/** * Process the payment and return the result **/ function process_payment($order_id) { $order = new fflcommerce_order($order_id); // Mark as on-hold (we're awaiting the cheque) $order->update_status('waiting-for-payment', __('Awaiting cheque payment', 'fflcommerce')); // Remove cart fflcommerce_cart::empty_cart(); // Return thankyou redirect $checkout_redirect = apply_filters('fflcommerce_get_checkout_redirect_page_id', fflcommerce_get_page_id('thanks')); return array('result' => 'success', 'redirect' => add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink($checkout_redirect)))); }
/** * Process the payment and return the result **/ function process_payment($order_id) { $order = new fflcommerce_order($order_id); $status = FFLCommerce_Base::get_options()->get('fflcommerce_cod_status', 'processing'); $order->update_status($status, __('Waiting for cash delivery.', 'fflcommerce')); // Remove cart fflcommerce_cart::empty_cart(); // Return thankyou redirect $checkout_redirect = apply_filters('fflcommerce_get_checkout_redirect_page_id', fflcommerce_get_page_id('thanks')); return array('result' => 'success', 'redirect' => add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink($checkout_redirect)))); }
function fflcommerce_complete_processing_orders() { if (self::get_options()->get('fflcommerce_complete_processing_orders') == 'yes') { add_filter('posts_where', array($this, 'orders_filter_when')); $orders = get_posts(array('post_status' => 'publish', 'post_type' => 'shop_order', 'shop_order_status' => 'processing', 'suppress_filters' => false, 'fields' => 'ids')); remove_filter('posts_where', array($this, 'orders_filter_when')); fflcommerce_emails::suppress_next_action(); foreach ($orders as $index => $order_id) { $order = new fflcommerce_order($order_id); $order->update_status('completed', __('Completed due to order being in processing state for a month or longer.', 'fflcommerce')); } } }
function fflcommerce_process_shop_order_meta($post_id) { $fflcommerce_options = FFLCommerce_Base::get_options(); $fflcommerce_errors = array(); $order = new fflcommerce_order($post_id); // Get old data + attributes $data = (array) maybe_unserialize(get_post_meta($post_id, 'order_data', true)); //Get old order items $old_order_items = (array) maybe_unserialize(get_post_meta($post_id, 'order_items', true)); // Add/Replace data to array $customerDetails = array('billing_first_name', 'billing_last_name', 'billing_company', 'billing_address_1', 'billing_address_2', 'billing_city', 'billing_postcode', 'billing_country', 'billing_state', 'billing_email', 'billing_phone', 'shipping_first_name', 'shipping_last_name', 'shipping_company', 'shipping_address_1', 'shipping_address_2', 'shipping_city', 'shipping_postcode', 'shipping_country', 'shipping_state'); $order_fields = array('shipping_method', 'shipping_service', 'payment_method', 'order_subtotal', 'order_discount_subtotal', 'order_shipping', 'order_discount', 'order_discount_coupons', 'order_tax_total', 'order_shipping_tax', 'order_total', 'order_total_prices_per_tax_class_ex_tax'); /* Pre-fill the customer addresses */ foreach ($customerDetails as $key) { $order_fields[] = $key; /* Checks if this is a new order from "Add Order" button */ if (!empty($_POST['auto_draft']) && !empty($_POST['customer_user']) && empty($_POST[$key])) { $data[$key] = get_user_meta($_POST['customer_user'], $key, true); } } //run stripslashes on all valid fields foreach ($order_fields as $field_name) { if (isset($_POST[$field_name])) { $data[$field_name] = stripslashes($_POST[$field_name]); } } // Sanitize numeric values $data['order_total'] = fflcommerce_sanitize_num($data['order_total']); $data['order_subtotal'] = fflcommerce_sanitize_num($data['order_subtotal']); // if a shipping or payment methods has changed, update the method title for pretty display if (isset($_POST['shipping_method'])) { $data['shipping_service'] = ''; $shipping_methods = fflcommerce_shipping::get_all_methods(); if (!empty($shipping_methods)) { foreach ($shipping_methods as $method) { if ($_POST['shipping_method'] == $method->id) { $data['shipping_service'] = $method->title; } } } } if (isset($_POST['payment_method'])) { $data['payment_method_title'] = ''; $payment_methods = fflcommerce_payment_gateways::get_available_payment_gateways(); if (!empty($payment_methods)) { foreach ($payment_methods as $method) { if ($_POST['payment_method'] == $method->id) { $data['payment_method_title'] = $method->title; } } } } // if total tax has been modified from order tax, then create a customized tax array // just for the order. At this point, we no longer know about multiple tax classes. // Even if we used the old tax array data, we still don't know how to break down // the amounts since they're customized. if (isset($data['order_tax_total']) && $order->get_total_tax() != $data['order_tax_total']) { $new_tax = $data['order_tax_total']; $data['order_tax'] = fflcommerce_tax::create_custom_tax($data['order_total'] - $data['order_tax_total'], $data['order_tax_total'], $data['order_shipping_tax'], isset($data['order_tax_divisor']) ? $data['order_tax_divisor'] : null); } // Customer update_post_meta($post_id, 'customer_user', (int) $_POST['customer_user']); // Order items $order_items = array(); if (isset($_POST['item_id'])) { $item_id = $_POST['item_id']; $item_variation = $_POST['item_variation_id']; $item_name = $_POST['item_name']; $item_quantity = $_POST['item_quantity']; $item_cost = $_POST['item_cost']; $item_tax_rate = $_POST['item_tax_rate']; for ($i = 0; $i < count($item_id); $i++) { if (!isset($item_id[$i]) || !isset($item_name[$i]) || !isset($item_quantity[$i]) || !isset($item_cost[$i]) || !isset($item_tax_rate[$i])) { continue; } $variation_id = ''; $variation = ''; if (!empty($item_variation[$i])) { $variation_id = (int) $item_variation[$i]; // if this is a variation, we should check if it is an old one // and copy the 'variation' field describing details of variation foreach ($old_order_items as $old_item_index => $old_item) { if ($old_item['variation_id'] == $variation_id) { $variation = $old_item['variation']; unset($old_order_items[$old_item_index]); break; } } // override variation with values from $_POST if (isset($_POST['order_attributes'][$i]) && is_array($_POST['order_attributes'][$i])) { foreach ($_POST['order_attributes'][$i] as $var_key => $var_value) { $variation[$var_key] = $var_value; } } } $cost_inc_tax = $fflcommerce_options->get('fflcommerce_prices_include_tax') == 'yes' ? number_format((double) fflcommerce_clean($item_cost[$i]), 2, '.', '') : -1; $order_items[] = apply_filters('update_order_item', array('id' => htmlspecialchars(stripslashes($item_id[$i])), 'variation_id' => $variation_id, 'variation' => $variation, 'name' => htmlspecialchars(stripslashes($item_name[$i])), 'qty' => (int) $item_quantity[$i], 'cost' => number_format((double) fflcommerce_clean($item_cost[$i]), 2, '.', ''), 'cost_inc_tax' => $cost_inc_tax, 'taxrate' => number_format((double) fflcommerce_clean($item_tax_rate[$i]), 4, '.', ''))); } } // Save update_post_meta($post_id, 'order_data', $data); update_post_meta($post_id, 'order_items', $order_items); // Order status $order->update_status($_POST['order_status']); // Handle button actions if (isset($_POST['reduce_stock']) && $_POST['reduce_stock'] && count($order_items) > 0) { $order->add_order_note(__('Manually reducing stock.', 'fflcommerce')); foreach ($order_items as $order_item) { $_product = $order->get_product_from_item($order_item); if ($_product->exists) { if ($_product->managing_stock()) { $old_stock = $_product->stock; $new_quantity = $_product->reduce_stock($order_item['qty']); $order->add_order_note(sprintf(__('Item #%s stock reduced from %s to %s.', 'fflcommerce'), $order_item['id'], $old_stock, $new_quantity)); if ($new_quantity < 0) { if ($old_stock < 0) { $backorder_qty = $order_item['qty']; } else { $backorder_qty = $old_stock - $order_item['qty']; } do_action('fflcommerce_product_on_backorder_notification', $post_id, $_product, $backorder_qty); } // stock status notifications if ($fflcommerce_options->get('fflcommerce_notify_no_stock') == 'yes' && $fflcommerce_options->get('fflcommerce_notify_no_stock_amount') >= 0 && $fflcommerce_options->get('fflcommerce_notify_no_stock_amount') >= $new_quantity) { do_action('fflcommerce_no_stock_notification', $_product); } else { if ($fflcommerce_options->get('fflcommerce_notify_low_stock') == 'yes' && $fflcommerce_options->get('fflcommerce_notify_low_stock_amount') >= $new_quantity) { do_action('fflcommerce_low_stock_notification', $_product); } } } } else { $order->add_order_note(sprintf(__('Item %s %s not found, skipping.', 'fflcommerce'), $order_item['id'], $order_item['name'])); } } $order->add_order_note(__('Manual stock reduction complete.', 'fflcommerce')); } else { if (isset($_POST['restore_stock']) && $_POST['restore_stock'] && sizeof($order_items) > 0) { $order->add_order_note(__('Manually restoring stock.', 'fflcommerce')); foreach ($order_items as $order_item) { $_product = $order->get_product_from_item($order_item); if ($_product->exists) { if ($_product->managing_stock()) { $old_stock = $_product->stock; $new_quantity = $_product->increase_stock($order_item['qty']); $order->add_order_note(sprintf(__('Item #%s stock increased from %s to %s.', 'fflcommerce'), $order_item['id'], $old_stock, $new_quantity)); } } else { $order->add_order_note(sprintf(__('Item %s %s not found, skipping.', 'fflcommerce'), $order_item['id'], $order_item['name'])); } } $order->add_order_note(__('Manual stock restore complete.', 'fflcommerce')); } else { if (isset($_POST['invoice']) && $_POST['invoice']) { // Mail link to customer fflcommerce_send_customer_invoice($order->id); } } } // Error Handling if (count($fflcommerce_errors) > 0) { $fflcommerce_options->set('fflcommerce_errors', $fflcommerce_errors); } }
/** * Successful Payment! **/ function successful_request($posted) { // Custom holds post ID if (!empty($posted['mb_transaction_id'])) { $order = new fflcommerce_order((int) $posted['transaction_id']); if ($order->status !== 'completed') { // We are here so lets check status and do actions switch ($posted['status']) { case '2': // Processed $order->add_order_note(__('Skrill payment completed', 'fflcommerce')); $order->payment_complete(); break; case '0': // Pending // Pending case '-2': // Failed $order->update_status('on-hold', sprintf(__('Skrill payment failed (%s)', 'fflcommerce'), strtolower($posted['status']))); break; case '-1': // Cancelled $order->update_status('cancelled', __('Skrill payment cancelled', 'fflcommerce')); break; default: $order->update_status('cancelled', __('Skrill exception', 'fflcommerce')); break; } } exit; } }
/** * Successful payment processing * * @param array $posted */ function successful_request($posted) { $posted = stripslashes_deep($posted); // 'custom' holds post ID (Order ID) if (!empty($posted['custom']) && !empty($posted['txn_type']) && !empty($posted['invoice'])) { $accepted_types = array('cart', 'instant', 'express_checkout', 'web_accept', 'masspay', 'send_money', 'subscr_payment'); $order = new fflcommerce_order((int) $posted['custom']); // Sandbox fix if (isset($posted['test_ipn']) && $posted['test_ipn'] == 1 && strtolower($posted['payment_status']) == 'pending') { $posted['payment_status'] = 'completed'; } $merchant = $this->testmode == 'no' ? $this->email : $this->testemail; if ($order->status !== 'completed') { // We are here so lets check status and do actions switch (strtolower($posted['payment_status'])) { case 'completed': if (!in_array(strtolower($posted['txn_type']), $accepted_types)) { // Put this order on-hold for manual checking $order->update_status('on-hold', sprintf(__('PayPal Validation Error: Unknown "txn_type" of "%s" for Order ID: %s.', 'fflcommerce'), $posted['txn_type'], $posted['custom'])); exit; } if ($order->get_order_number() !== $posted['invoice']) { // Put this order on-hold for manual checking $order->update_status('on-hold', sprintf(__('PayPal Validation Error: Order Invoice Number does NOT match PayPal posted invoice (%s) for Order ID: .', 'fflcommerce'), $posted['invoice'], $posted['custom'])); exit; } // Validate Amount if (number_format((double) $order->order_total, $this->decimals, '.', '') != $posted['mc_gross']) { // Put this order on-hold for manual checking $order->update_status('on-hold', sprintf(__('PayPal Validation Error: Payment amounts do not match initial order (gross %s).', 'fflcommerce'), $posted['mc_gross'])); exit; } if (strcasecmp(trim($posted['business']), trim($merchant)) != 0) { // Put this order on-hold for manual checking $order->update_status('on-hold', sprintf(__('PayPal Validation Error: Payment Merchant email received does not match PayPal Gateway settings. (%s)', 'fflcommerce'), $posted['business'])); exit; } if (!in_array($posted['mc_currency'], apply_filters('fflcommerce_multi_currencies_available', array(FFLCommerce_Base::get_options()->get('fflcommerce_currency'))))) { // Put this order on-hold for manual checking $order->update_status('on-hold', sprintf(__('PayPal Validation Error: Payment currency received (%s) does not match Shop currency.', 'fflcommerce'), $posted['mc_currency'])); exit; } $order->add_order_note(__('PayPal Standard payment completed', 'fflcommerce')); $order->payment_complete(); fflcommerce_log('PAYPAL: IPN payment completed for Order ID: ' . $posted['custom']); break; case 'denied': case 'expired': case 'failed': case 'voided': // Failed order $order->update_status('failed', sprintf(__('Payment %s via IPN.', 'fflcommerce'), strtolower($posted['payment_status']))); fflcommerce_log("PAYPAL: failed order with status = " . strtolower($posted['payment_status']) . "for Order ID: " . $posted['custom']); break; case 'refunded': case 'reversed': case 'chargeback': fflcommerce_log("PAYPAL: payment status type - '" . $posted['payment_status'] . "' - not supported for Order ID: " . $posted['custom']); break; } } exit; } else { fflcommerce_log("PAYPAL: function 'successful_request' -- empty initial required values -- EXITING!\n'posted' values = " . print_r($posted, true)); } }
function fflcommerce_custom_order_columns($column) { global $post; $fflcommerce_options = FFLCommerce_Base::get_options(); $order = new fflcommerce_order($post->ID); switch ($column) { case "order_status": echo sprintf('<mark class="%s">%s</mark>', sanitize_title($order->status), __($order->status, 'fflcommerce')); break; case "order_title": echo '<a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '">' . sprintf(__('Order %s', 'fflcommerce'), $order->get_order_number()) . '</a>'; echo '<time title="' . date_i18n(_x('c', 'date', 'fflcommerce'), strtotime($post->post_date)) . '">' . date_i18n(__('F j, Y, g:i a', 'fflcommerce'), strtotime($post->post_date)) . '</time>'; break; case "customer": if ($order->user_id) { $user_info = get_userdata($order->user_id); } ?> <dl> <dt><?php _e('User:'******'fflcommerce'); ?> </dt> <dd><?php if (isset($user_info) && $user_info) { echo '<a href="user-edit.php?user_id=' . $user_info->ID . '">#' . $user_info->ID . ' – <strong>'; if ($user_info->first_name || $user_info->last_name) { echo $user_info->first_name . ' ' . $user_info->last_name; } else { echo $user_info->display_name; } echo '</strong></a>'; } else { _e('Guest', 'fflcommerce'); } ?> </dd> <?php if ($order->billing_email) { ?> <dt><?php _e('Billing Email:', 'fflcommerce'); ?> </dt> <dd><a href="mailto:<?php echo $order->billing_email; ?> "><?php echo $order->billing_email; ?> </a></dd><?php } ?> <?php if ($order->billing_phone) { ?> <dt><?php _e('Billing Phone:', 'fflcommerce'); ?> </dt> <dd><?php echo $order->billing_phone; ?> </dd><?php } ?> </dl> <?php break; case "billing_address": echo '<strong>' . $order->billing_first_name . ' ' . $order->billing_last_name; if ($order->billing_company) { echo ', ' . $order->billing_company; } echo '</strong><br/>'; echo '<a target="_blank" href="http://maps.google.co.uk/maps?&q=' . urlencode($order->formatted_billing_address) . '&z=16">' . $order->formatted_billing_address . '</a>'; break; case "shipping_address": if ($order->formatted_shipping_address) { echo '<strong>' . $order->shipping_first_name . ' ' . $order->shipping_last_name; if ($order->shipping_company) { echo ', ' . $order->shipping_company; } echo '</strong><br/>'; echo '<a target="_blank" href="http://maps.google.co.uk/maps?&q=' . urlencode($order->formatted_shipping_address) . '&z=16">' . $order->formatted_shipping_address . '</a>'; } else { echo '–'; } break; case "billing_and_shipping": ?> <dl> <?php if ($order->payment_method_title) { ?> <dt><?php _e('Payment:', 'fflcommerce'); ?> </dt> <dd><?php echo $order->payment_method_title; ?> </dd> <?php } ?> <?php if ($order->shipping_service) { ?> <dt><?php _e('Shipping:', 'fflcommerce'); ?> </dt> <dd><?php echo sprintf(__('%s', 'fflcommerce'), $order->shipping_service); ?> </dd> <?php } ?> </dl> <?php break; case "total_cost": ?> <table cellpadding="0" cellspacing="0" class="cost"> <tr> <?php if ($fflcommerce_options->get('fflcommerce_calc_taxes') == 'yes' && $order->has_compound_tax() || $fflcommerce_options->get('fflcommerce_tax_after_coupon') == 'yes' && $order->order_discount > 0) { ?> <th><?php _e('Retail Price', 'fflcommerce'); ?> </th> <?php } else { ?> <th><?php _e('Subtotal', 'fflcommerce'); ?> </th> <?php } ?> <td><?php echo fflcommerce_price($order->order_subtotal); ?> </td> </tr> <?php if ($order->order_shipping > 0) { ?> <tr> <th><?php _e('Shipping', 'fflcommerce'); ?> </th> <td><?php echo fflcommerce_price($order->order_shipping); ?> </td> </tr> <?php } do_action('fflcommerce_processing_fee_after_shipping'); if ($fflcommerce_options->get('fflcommerce_tax_after_coupon') == 'yes' && $order->order_discount > 0) { ?> <tr> <th><?php _e('Discount', 'fflcommerce'); ?> </th> <td>-<?php echo fflcommerce_price($order->order_discount); ?> </td> </tr> <?php } if ($fflcommerce_options->get('fflcommerce_calc_taxes') == 'yes' && $order->has_compound_tax() || $fflcommerce_options->get('fflcommerce_tax_after_coupon') == 'yes' && $order->order_discount > 0) { ?> <tr> <th><?php _e('Subtotal', 'fflcommerce'); ?> </th> <td><?php echo fflcommerce_price($order->order_discount_subtotal); ?> </td> </tr> <?php } if ($fflcommerce_options->get('fflcommerce_calc_taxes') == 'yes') { foreach ($order->get_tax_classes() as $tax_class) { if ($order->show_tax_entry($tax_class)) { ?> <tr> <th><?php echo $order->get_tax_class_for_display($tax_class) . ' (' . (double) $order->get_tax_rate($tax_class) . '%):'; ?> </th> <td><?php echo $order->get_tax_amount($tax_class); ?> </td> </tr> <?php } } } if ($fflcommerce_options->get('fflcommerce_tax_after_coupon') == 'no' && $order->order_discount > 0) { ?> <tr> <th><?php _e('Discount', 'fflcommerce'); ?> </th> <td>-<?php echo fflcommerce_price($order->order_discount); ?> </td> </tr><?php } ?> <tr> <th><?php _e('Total', 'fflcommerce'); ?> </th> <td><?php echo fflcommerce_price($order->order_total); ?> </td> </tr> </table> <?php break; case 'order_coupons': if (!empty($order->order_discount_coupons)) { foreach ($order->order_discount_coupons as $used_coupon) { ?> <p class="order_coupon"><?php echo '#' . $used_coupon['id'] . ' - ' . $used_coupon['code']; ?> </p> <?php } } break; } }
/** * Process the checkout after the confirm order button is pressed */ public function process_checkout() { if (!defined('FFLCOMMERCE_CHECKOUT')) { define('FFLCOMMERCE_CHECKOUT', true); } // Initialize cart fflcommerce_cart::get_cart(); fflcommerce_cart::calculate_totals(); if (isset($_POST) && $_POST && !isset($_POST['login'])) { fflcommerce::verify_nonce('process_checkout'); // this will fill in our $posted array with validated data self::validate_checkout(); $gateway = fflcommerce_payment_gateways::get_gateway($this->posted['payment_method']); if (self::process_gateway($gateway)) { $gateway->validate_fields(); } do_action('fflcommerce_after_checkout_validation', $this->posted, $_POST, sizeof(fflcommerce::$errors)); if (fflcommerce::has_errors()) { return false; } if (!isset($_POST['update_totals'])) { $user_id = get_current_user_id(); // Create customer account and log them in if ($this->show_signup && !$user_id && $this->posted['create_account']) { $user_id = $this->create_user_account(); if ($user_id === 0) { return false; } } $billing = array('first_name' => $this->posted['billing_first_name'], 'last_name' => $this->posted['billing_last_name'], 'company' => $this->posted['billing_company'], 'address_1' => $this->posted['billing_address_1'], 'address_2' => $this->posted['billing_address_2'], 'city' => $this->posted['billing_city'], 'state' => $this->posted['billing_state'], 'postcode' => $this->posted['billing_postcode'], 'country' => $this->posted['billing_country'], 'phone' => $this->posted['billing_phone'], 'email' => $this->posted['billing_email']); fflcommerce_customer::set_country($billing['country']); fflcommerce_customer::set_state($billing['state']); fflcommerce_customer::set_postcode($billing['postcode']); if (isset($this->posted['billing_euvatno']) && $this->valid_euvatno) { $billing['euvatno'] = $this->posted['billing_euvatno']; $billing['euvatno'] = str_replace(' ', '', $billing['euvatno']); // If country code is not provided - add one. if (strpos($billing['euvatno'], $billing['country']) === false) { $billing['euvatno'] = $billing['country'] . $billing['euvatno']; } } // Get shipping/billing if (!empty($this->posted['shiptobilling'])) { $shipping = $billing; unset($shipping['phone'], $shipping['email']); } elseif (fflcommerce_shipping::is_enabled()) { $shipping = array('first_name' => $this->posted['shipping_first_name'], 'last_name' => $this->posted['shipping_last_name'], 'company' => $this->posted['shipping_company'], 'address_1' => $this->posted['shipping_address_1'], 'address_2' => $this->posted['shipping_address_2'], 'city' => $this->posted['shipping_city'], 'state' => $this->posted['shipping_state'], 'postcode' => $this->posted['shipping_postcode'], 'country' => $this->posted['shipping_country']); } fflcommerce_customer::set_shipping_country($shipping['country']); fflcommerce_customer::set_shipping_state($shipping['state']); fflcommerce_customer::set_shipping_postcode($shipping['postcode']); // Update totals based on processed customer address fflcommerce_cart::calculate_totals(); // Save billing/shipping to user meta fields if ($user_id > 0) { foreach ($billing as $field => $value) { update_user_meta($user_id, 'billing_' . $field, $value); } if (isset($shipping)) { foreach ($shipping as $field => $value) { update_user_meta($user_id, 'shipping_' . $field, $value); } } } if (!isset($_POST['submit_action']) || $_POST['submit_action'] != 'place_order') { $result = fflcommerce::redirect(fflcommerce_get_page_id(FFLCOMMERCE_CHECKOUT)); return array('result' => 'redirect', 'redirect' => $result); } // Order meta data $data = array(); $applied_coupons = array_map(function ($coupon) { return JS_Coupons::get_coupon($coupon); }, fflcommerce_cart::get_coupons()); do_action('fflcommerce_checkout_update_order_total', $this->posted); foreach ($billing as $field => $value) { $data['billing_' . $field] = $value; } if (isset($shipping)) { foreach ($shipping as $field => $value) { $data['shipping_' . $field] = $value; } } $data['order_discount_coupons'] = $applied_coupons; $data['shipping_method'] = $this->posted['shipping_method']; $data['shipping_service'] = $this->posted['shipping_service']; $data['payment_method'] = $this->posted['payment_method']; $data['payment_method_title'] = $gateway->title; $data['order_subtotal'] = fflcommerce_cart::get_subtotal(); $data['order_discount_subtotal'] = fflcommerce_cart::get_discount_subtotal(); $data['order_shipping'] = fflcommerce_cart::get_shipping_total(); $data['order_discount'] = fflcommerce_cart::get_total_discount(false); $data['order_tax'] = fflcommerce_cart::get_taxes_as_string(); $data['order_tax_no_shipping_tax'] = fflcommerce_cart::get_total_cart_tax_without_shipping_tax(); $data['order_tax_divisor'] = fflcommerce_cart::get_tax_divisor(); $data['order_shipping_tax'] = fflcommerce_cart::get_shipping_tax(); $data['order_total'] = fflcommerce_cart::get_total(false); $data['order_total_prices_per_tax_class_ex_tax'] = fflcommerce_cart::get_price_per_tax_class_ex_tax(); if ($this->valid_euvatno) { $data['order_tax'] = ''; $temp = fflcommerce_cart::get_total_cart_tax_without_shipping_tax(); $data['order_total'] -= $data['order_shipping_tax'] + $temp; $data['order_shipping_tax'] = 0; } // Cart items $order_items = array(); foreach (fflcommerce_cart::get_cart() as $values) { /** @var fflcommerce_product $product */ $product = $values['data']; // Check stock levels if (!$product->has_enough_stock($values['quantity'])) { fflcommerce::add_error(sprintf(__('Sorry, we do not have enough "%s" in stock to fulfill your order. Please edit your cart and try again. We apologize for any inconvenience caused.', 'fflcommerce'), $product->get_title())); if (self::get_options()->get('fflcommerce_show_stock') == 'yes') { fflcommerce::add_error(sprintf(__('We have only %d available at this time.', 'fflcommerce'), $product->get_stock())); } break; } // Calc item tax to store $rates = $product->get_tax_destination_rate(); $rates = current($rates); if (isset($rates['rate'])) { $rate = $rates['rate']; } else { $rate = 0.0; } if ($this->valid_euvatno) { $rate = 0.0; } $price_inc_tax = $product->get_price_with_tax(); if (!empty($values['variation_id'])) { $product_id = $values['variation_id']; } else { $product_id = $values['product_id']; } $custom_products = (array) fflcommerce_session::instance()->customized_products; $custom = isset($custom_products[$product_id]) ? $custom_products[$product_id] : ''; if (!empty($custom)) { unset($custom_products[$product_id]); fflcommerce_session::instance()->customized_products = $custom_products; } $order_items[] = apply_filters('new_order_item', array('id' => $values['product_id'], 'variation_id' => $values['variation_id'], 'variation' => $values['variation'], 'customization' => $custom, 'name' => $product->get_title(), 'qty' => (int) $values['quantity'], 'cost' => $product->get_price_excluding_tax(), 'cost_inc_tax' => $price_inc_tax, 'taxrate' => $rate), $values); } if (fflcommerce::has_errors()) { return false; } // Insert or update the post data $create_new_order = true; $order_data = array('post_type' => 'shop_order', 'post_title' => 'Order – ' . date('F j, Y @ h:i A'), 'post_status' => 'publish', 'post_excerpt' => $this->posted['order_comments'], 'post_author' => 1); $order_id = 0; if (isset(fflcommerce_session::instance()->order_awaiting_payment) && fflcommerce_session::instance()->order_awaiting_payment > 0) { $order_id = absint(fflcommerce_session::instance()->order_awaiting_payment); $terms = wp_get_object_terms($order_id, 'shop_order_status', array('fields' => 'slugs')); $order_status = isset($terms[0]) ? $terms[0] : 'pending'; // Resume the unpaid order if its pending if ($order_status == 'pending' || $order_status == 'failed') { $create_new_order = false; $order_data['ID'] = $order_id; wp_update_post($order_data); } } if ($create_new_order) { $order_id = wp_insert_post($order_data); } if (is_wp_error($order_id) || $order_id === 0) { fflcommerce::add_error(__('Error: Unable to create order. Please try again.', 'fflcommerce')); return false; } // Update post meta update_post_meta($order_id, 'order_data', $data); update_post_meta($order_id, 'order_key', uniqid('order_')); update_post_meta($order_id, 'customer_user', (int) $user_id); update_post_meta($order_id, 'order_items', $order_items); wp_set_object_terms($order_id, 'pending', 'shop_order_status'); $order = new fflcommerce_order($order_id); /* Coupon usage limit */ foreach ($data['order_discount_coupons'] as $coupon) { $coupon_id = JS_Coupons::get_coupon_post_id($coupon['code']); if ($coupon_id !== false) { $usage_count = get_post_meta($coupon_id, 'usage', true); $usage_count = empty($usage_count) ? 1 : $usage_count + 1; update_post_meta($coupon_id, 'usage', $usage_count); } } if ($create_new_order) { do_action('fflcommerce_new_order', $order_id); } else { do_action('fflcommerce_resume_order', $order_id); } do_action('fflcommerce_checkout_update_order_meta', $order_id, $this->posted); // can't just simply check needs_payment() here, as paypal may have force payment set to true if (self::process_gateway($gateway)) { // Store Order ID in session so it can be re-used after payment failure fflcommerce_session::instance()->order_awaiting_payment = $order_id; // Process Payment $result = $gateway->process_payment($order_id); // Redirect to success/confirmation/payment page if ($result['result'] == 'success') { return $result; } return false; } else { // No payment was required for order $order->payment_complete(); // Empty the Cart fflcommerce_cart::empty_cart(); // Redirect to success/confirmation/payment page $checkout_redirect = apply_filters('fflcommerce_get_checkout_redirect_page_id', fflcommerce_get_page_id('thanks')); return array('result' => 'redirect', 'redirect' => $checkout_redirect); } } } return true; }
/** * Recent Orders */ function fflcommerce_dash_recent_orders() { $args = array('numberposts' => 10, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'shop_order', 'post_status' => 'publish'); $orders = get_posts($args); if ($orders) { echo '<ul class="recent-orders">'; foreach ($orders as $order) { $this_order = new fflcommerce_order($order->ID); $user = get_userdata($this_order->user_id); if ($user) { $user = array('link' => get_edit_user_link($user->ID), 'name' => $user->display_name); } else { $user = array('link' => '', 'name' => __('guest', 'fflcommerce')); } $total_items = 0; foreach ($this_order->items as $index => $item) { $total_items += $item['qty']; } echo ' <li> <span class="order-status ' . sanitize_title($this_order->status) . '">' . ucwords(__($this_order->status, 'fflcommerce')) . '</span> <a href="' . admin_url('post.php?post=' . $order->ID) . '&action=edit">' . $this_order->get_order_number() . '</a> <span class="order-time">' . get_the_time(__('M d, Y', 'fflcommerce'), $order->ID) . '</span> <span class="order-customer"><a href="' . $user['link'] . '">' . $user['name'] . '</a></span> <small>' . sizeof($this_order->items) . ' ' . _n('Item', 'Items', sizeof($this_order->items), 'fflcommerce') . ', <span class="total-quantity">' . __('Total Quantity', 'fflcommerce') . ' ' . $total_items . '</span> <span class="order-cost">' . fflcommerce_price($this_order->order_total) . '</span></small> </li>'; } echo '</ul>'; } }
/** * Process the payment and return the result **/ function process_payment($order_id) { $order = new fflcommerce_order($order_id); $order->update_status('waiting-for-payment', __('Awaiting Bank Transfer', 'fflcommerce')); fflcommerce_cart::empty_cart(); $checkout_redirect = apply_filters('fflcommerce_get_checkout_redirect_page_id', fflcommerce_get_page_id('thanks')); return array('result' => 'success', 'redirect' => add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink($checkout_redirect)))); }
/** * Order totals meta box * * Displays the order totals meta box * * @since 1.0 */ function fflcommerce_order_totals_meta_box($post) { $_order = new fflcommerce_order($post->ID); $coupons = array(); $order_discount_coupons = (array) $_order->_fetch('order_discount_coupons'); if (!empty($order_discount_coupons)) { foreach ($order_discount_coupons as $coupon) { $coupons[] = isset($coupon['code']) ? $coupon['code'] : ''; } } ?> <ul class="totals"> <li class="left"> <label><?php _e('Subtotal:', 'fflcommerce'); ?> </label> <input type="text" id="order_subtotal" name="order_subtotal" placeholder="0.00 <?php _e('(ex. tax)', 'fflcommerce'); ?> " value="<?php echo esc_attr($_order->_fetch('order_subtotal')); ?> " class="first" /> </li> <li class="right"> <label><?php _e('Discount: ', 'fflcommerce'); ?> <span class="applied-coupons-values"><?php echo implode(',', $coupons); ?> </span></label> <input type="text" id="order_discount" name="order_discount" placeholder="0.00" value="<?php echo esc_attr($_order->_fetch('order_discount')); ?> " /> </li> <?php $shipping_methods = fflcommerce_shipping::get_all_methods(); $shipping_select = "<select id='shipping_method' name='shipping_method' class='last' data-placeholder=" . __('Choose', 'fflcommerce') . ">"; $shipping_select .= "<option></option>"; if (!empty($shipping_methods)) { foreach ($shipping_methods as $index => $method) { $mark = ''; if ($_order->_fetch('shipping_method') == $method->id) { $mark = 'selected="selected"'; } $shipping_select .= "<option value='{$method->id}' {$mark}>{$method->title}</option>"; } } $shipping_select .= "</select>"; ?> <li> <label><?php _e('Shipping:', 'fflcommerce'); ?> </label> <input type="text" id="order_shipping" name="order_shipping" placeholder="0.00 <?php _e('(ex. tax)', 'fflcommerce'); ?> " value="<?php echo esc_attr($_order->_fetch('order_shipping')); ?> " class="first" /> <?php echo $shipping_select; ?> <script type="text/javascript"> /*<![CDATA[*/ jQuery(function() { jQuery("#shipping_method").select2({ width: '120px' }); }); /*]]>*/ </script> </li> <li class="left"> <label><?php _e('Total Tax:', 'fflcommerce'); ?> </label> <input type="text" id="order_tax" name="order_tax_total" placeholder="0.00" value="<?php echo esc_attr($_order->get_total_tax()); ?> " class="first" /> </li> <li class="right"> <label><?php _e('Shipping Tax:', 'fflcommerce'); ?> </label> <input type="text" id="order_shipping_tax" name="order_shipping_tax" placeholder="0.00" value="<?php echo esc_attr($_order->_fetch('order_shipping_tax')); ?> " class="first" /> </li> <?php $payment_methods = fflcommerce_payment_gateways::get_available_payment_gateways(); $payment_select = "<select id='payment_method' name='payment_method' class='last' data-placeholder=" . __('Choose', 'fflcommerce') . ">"; $payment_select .= "<option></option>"; if (!empty($payment_methods)) { foreach ($payment_methods as $index => $method) { $mark = ''; if ($_order->_fetch('payment_method') == $method->id) { $mark = 'selected="selected"'; } $payment_select .= "<option value='{$method->id}' {$mark}>{$method->title}</option>"; } } $payment_select .= "</select>"; ?> <?php do_action('fflcommerce_admin_order_totals_after_shipping', $post->ID); ?> <li> <label><?php _e('Total:', 'fflcommerce'); ?> </label> <input type="text" id="order_total" name="order_total" placeholder="0.00" value="<?php echo esc_attr($_order->_fetch('order_total')); ?> " class="first" /> <?php echo $payment_select; ?> <script type="text/javascript"> /*<![CDATA[*/ jQuery(function() { jQuery("#payment_method").select2({ width: '120px' }); }); /*]]>*/ </script> </li> </ul> <div class="clear"></div> <?php }
function fflcommerce_ga_ecommerce_tracking($order_id) { $options = FFLCommerce_Base::get_options(); // Skip if disabled if ($options->get('fflcommerce_ga_ecommerce_tracking_enabled') != 'yes') { return; } // Don't track the shop owners roaming if (current_user_can('manage_fflcommerce')) { return; } $tracking_id = $options->get('fflcommerce_ga_id'); if (!$tracking_id) { return; } // Get the order and output tracking code $order = new fflcommerce_order($order_id); ?> <script type="text/javascript"> fflcommerceGA('require', 'ecommerce'); fflcommerceGA('ecommerce:addTransaction', { 'id': '<?php echo $order->get_order_number(); ?> ', // Transaction ID. Required. 'affiliation': '<?php bloginfo('name'); ?> ', // Affiliation or store name. 'revenue': '<?php echo $order->order_total; ?> ', // Grand Total. 'shipping': '<?php echo $order->order_shipping; ?> ', // Shipping. 'tax': '<?php echo $order->get_total_tax(); ?> ' // Tax. }); <?php foreach ($order->items as $item) { $_product = $order->get_product_from_item($item); ?> fflcommerceGA('ecommerce:addItem', { 'id': '<?php echo $order->get_order_number(); ?> ', // Transaction ID. Required. 'name': '<?php echo $item['name']; ?> ', // Product name. Required. 'sku': '<?php echo $_product->sku; ?> ', // SKU/code. 'category': '<?php if (isset($_product->variation_data)) { echo fflcommerce_get_formatted_variation($_product, $item['variation'], true); } ?> ', // Category or variation. 'price': '<?php echo $item['cost'] / $item['qty']; ?> ', // Unit price. 'quantity': '<?php echo $item['qty']; ?> ' // Quantity. }); <?php } ?> fflcommerceGA('ecommerce:send'); </script> <?php }
/** * Process Response from WorldPay */ private function process_response($posted) { $installation_id = $this->get_post('instId'); $cartId = $this->get_post('cartId'); $transId = $this->get_post('transId'); $processed_transID = get_post_meta($cartId, '_worldpay_processed_transID', true); $amount = $this->get_post('amount'); $authAmount = $this->get_post('authAmount'); $authCurrency = $this->get_post('authCurrency'); $currency = $this->get_post('currency'); $shop_currency = FFLCommerce_Base::get_options()->get('fflcommerce_currency'); $testMode = $this->get_post('testMode'); $error = array(); $order = new fflcommerce_order((int) $cartId); // Do all checks only if transaction was processed. switch ($this->get_post('transStatus')) { case 'Y': // If the currency is locked. if ($this->fixed_currency == 'yes') { // All currencies should be the same. if ($currency != $authCurrency || $authCurrency != $shop_currency || $currency != $shop_currency) { $error['Locked_Currency_Error'] = sprintf(__('The currency paid in was different than the one requested. Order #: %s. Currency paid in: %s, the amount paid: %s. You should investigate further.', 'fflcommerce'), $order->id, $authCurrency, $authAmount); } // All amounts should be the same if ($order->order_total != $amount || $authAmount != $order->order_total || $authAmount != $amount) { $error['Locked_Amount_Error'] = sprintf(__('There were differences in the amounts received. Order #: %s. Submitted: %s, Paid: %s, Order Total: %s. You should investigate further.', 'fflcommerce'), $order->id, $amount, $authAmount, $order->order_total); } } else { // If currency submitted to WorldPay is the same as your store one. // They should always be the same even if you accept multiple currency payments. if ($currency != $shop_currency) { $error['currency'] = sprintf(__('The currency submitted to WorldPay (%s) is different than the main currency of your shop (%s). You should investigate further.', 'fflcommerce'), $currency, $shop_currency); } // If multi-currency is supported, at least the amount submitted to WorldPay should be the same as the order total. if ($order->order_total != $amount) { $error['amount'] = sprintf(__('The order total (%s) is different than the amount submitted to WorldPay (%s). You should investigate further.', 'fflcommerce'), $order->order_total, $amount); } } // Check merchant. if ($installation_id != $this->installation_id) { $error['instId'] = sprintf(__('Order was paid to installation ID: %s, which is different than the Installation ID set in your shop: %s. You should investigate further.', 'fflcommerce'), $installation_id, $this->installation_id); } if ($transId == $processed_transID) { $error['already_processed'] = sprintf(__('Payment with the same transaction ID (%s) was already processed for this order. You should investigate further.', 'fflcommerce'), $transId); } if ($this->testmode == 'no' && $testMode > 0) { $error['testmode'] = sprintf(__('Your shop is in Live mode, but you received a Test mode transaction. You should investigate further.', 'fflcommerce')); } if (empty($error) && $testMode == 0) { // Payment completed as live response $order->add_order_note(__('WorldPay payment completed. Transaction ID: ' . $transId, 'fflcommerce')); update_post_meta($order->id, '_worldpay_processed_transID', $transId, $processed_transID); $order->payment_complete(); $args = array('key' => $order->order_key, 'order' => $order->id); $redirect_url = add_query_arg($args, get_permalink(fflcommerce_get_page_id('thanks'))); } elseif (empty($error) && $testMode > 0) { // Payment completed as test response $order->add_order_note(__('TESTMODE: WorldPay payment completed. Transaction ID: ' . $transId, 'fflcommerce')); update_post_meta($order->id, '_worldpay_processed_transID', $transId, $processed_transID); $order->payment_complete(); $args = array('key' => $order->order_key, 'order' => $order->id); $redirect_url = add_query_arg($args, get_permalink(fflcommerce_get_page_id('thanks'))); } if (!empty($error) && $this->receive_err_log == 'yes') { $info = sprintf(__('Order #%s ', 'fflcommerce'), $order->id); $this->email_worldpay_error_logs($error, $posted, $info); $redirect_url = get_permalink(fflcommerce_get_page_id('checkout')); } break; case 'C': if ($testMode == 0) { // Payment was canceled live. $order->cancel_order(__('Order was canceled by customer at WorldPay.', 'fflcommerce')); } if ($testMode > 0) { // Payment was canceled in test mode. $order->cancel_order(__('TESTMODE: Order was canceled by customer at WorldPay.', 'fflcommerce')); } $redirect_url = $this->get_post('MC_cancel_return'); break; default: // No action $redirect_url = $this->get_post('MC_cancel_return'); break; } echo '<html><head><meta http-equiv="refresh" content="2;url=' . $redirect_url . '"></head><body><WPDISPLAY ITEM=banner></body></html>'; exit; }
function fflcommerce_order_tracking($atts) { extract(shortcode_atts(array(), $atts)); global $post; $fflcommerce_options = FFLCommerce_Base::get_options(); if ($_POST) { $order = new fflcommerce_order(); $order->id = !empty($_POST['orderid']) ? $_POST['orderid'] : 0; if (isset($_POST['order_email']) && $_POST['order_email']) { $order_email = trim($_POST['order_email']); } else { $order_email = ''; } if (!fflcommerce::verify_nonce('order_tracking')) { echo '<p>' . __('You have taken too long. Please refresh the page and retry.', 'fflcommerce') . '</p>'; } elseif ($order->id && $order_email && $order->get_order(apply_filters('fflcommerce_shortcode_order_tracking_order_id', $order->id))) { if ($order->billing_email == $order_email) { echo '<p>' . sprintf(__('Order %s which was made %s ago and has the status "%s"', 'fflcommerce'), $order->get_order_number(), human_time_diff(strtotime($order->order_date), current_time('timestamp')), __($order->status, 'fflcommerce')); if ($order->status == 'completed') { $completed = (array) get_post_meta($order->id, '_js_completed_date', true); if (!empty($completed)) { $completed = $completed[0]; } else { $completed = ''; } // shouldn't happen, reset to be sure echo sprintf(__(' was completed %s ago', 'fflcommerce'), human_time_diff(strtotime($completed), current_time('timestamp'))); } echo '.</p>'; do_action('fflcommerce_tracking_details_info', $order); ?> <?php do_action('fflcommerce_before_track_order_details', $order->id); ?> <h2><?php _e('Order Details', 'fflcommerce'); ?> </h2> <table class="shop_table"> <thead> <tr> <th><?php _e('ID/SKU', 'fflcommerce'); ?> </th> <th><?php _e('Title', 'fflcommerce'); ?> </th> <th><?php _e('Price', 'fflcommerce'); ?> </th> <th><?php _e('Quantity', 'fflcommerce'); ?> </th> </tr> </thead> <tfoot> <tr> <?php if ($fflcommerce_options->get('fflcommerce_calc_taxes') == 'yes' && $order->has_compound_tax() || $fflcommerce_options->get('fflcommerce_tax_after_coupon') == 'yes' && $order->order_discount > 0) { ?> <td colspan="3"><?php _e('Retail Price', 'fflcommerce'); ?> </td> <?php } else { ?> <td colspan="3"><?php _e('Subtotal', 'fflcommerce'); ?> </td> <?php } ?> <td><?php echo $order->get_subtotal_to_display(); ?> </td> </tr> <?php if ($order->order_shipping > 0) { ?> <tr> <td colspan="3"><?php _e('Shipping', 'fflcommerce'); ?> </td> <td><?php echo $order->get_shipping_to_display(); ?> </td> </tr> <?php } do_action('fflcommerce_processing_fee_after_shipping'); if ($fflcommerce_options->get('fflcommerce_tax_after_coupon') == 'yes' && $order->order_discount > 0) { ?> <tr class="discount"> <td colspan="3"><?php _e('Discount', 'fflcommerce'); ?> </td> <td>-<?php echo fflcommerce_price($order->order_discount); ?> </td> </tr> <?php } if ($fflcommerce_options->get('fflcommerce_calc_taxes') == 'yes' && $order->has_compound_tax() || $fflcommerce_options->get('fflcommerce_tax_after_coupon') == 'yes' && $order->order_discount > 0) { ?> <tr> <td colspan="3"><?php _e('Subtotal', 'fflcommerce'); ?> </td> <td><?php echo fflcommerce_price($order->order_discount_subtotal); ?> </td> </tr> <?php } if ($fflcommerce_options->get('fflcommerce_calc_taxes') == 'yes') { foreach ($order->get_tax_classes() as $tax_class) { if ($order->show_tax_entry($tax_class)) { ?> <tr> <td colspan="3"><?php echo $order->get_tax_class_for_display($tax_class) . ' (' . (double) $order->get_tax_rate($tax_class) . '%):'; ?> </td> <td><?php echo $order->get_tax_amount($tax_class); ?> </td> </tr> <?php } } } ?> <?php if ($fflcommerce_options->get('fflcommerce_tax_after_coupon') == 'no' && $order->order_discount > 0) { ?> <tr class="discount"> <td colspan="3"><?php _e('Discount', 'fflcommerce'); ?> </td> <td>-<?php echo fflcommerce_price($order->order_discount); ?> </td> </tr><?php } ?> <tr> <td colspan="3"><strong><?php _e('Grand Total', 'fflcommerce'); ?> </strong></td> <td><strong><?php echo fflcommerce_price($order->order_total); ?> </strong></td> </tr> </tfoot> <tbody> <?php foreach ($order->items as $order_item) { if (isset($order_item['variation_id']) && $order_item['variation_id'] > 0) { $_product = new fflcommerce_product_variation($order_item['variation_id']); } else { $_product = new fflcommerce_product($order_item['id']); } echo '<tr>'; echo '<td>' . $_product->sku . '</td>'; echo '<td class="product-name">' . $_product->get_title(); if ($_product instanceof fflcommerce_product_variation) { echo fflcommerce_get_formatted_variation($_product, $order_item['variation']); } do_action('fflcommerce_display_item_meta_data', $order_item); echo '</td>'; echo '<td>' . fflcommerce_price($order_item['cost']) . '</td>'; echo '<td>' . $order_item['qty'] . '</td>'; echo '</tr>'; } ?> </tbody> </table> <?php do_action('fflcommerce_after_track_order_details', $order->id); ?> <div style="width: 49%; float:left;"> <h2><?php _e('Billing Address', 'fflcommerce'); ?> </h2> <p><?php $address = $order->billing_first_name . ' ' . $order->billing_last_name . '<br/>'; if ($order->billing_company) { $address .= $order->billing_company . '<br/>'; } $address .= $order->formatted_billing_address; echo $address; ?> </p> </div> <div style="width: 49%; float:right;"> <h2><?php _e('Shipping Address', 'fflcommerce'); ?> </h2> <p><?php $address = $order->shipping_first_name . ' ' . $order->shipping_last_name . '<br/>'; if ($order->shipping_company) { $address .= $order->shipping_company . '<br/>'; } $address .= $order->formatted_shipping_address; echo $address; ?> </p> </div> <div class="clear"></div> <?php } else { echo '<p>' . __('Sorry, we could not find that order id in our database. <a href="' . get_permalink($post->ID) . '">Want to retry?</a>', 'fflcommerce') . '</p>'; } } else { echo '<p>' . sprintf(__('Sorry, we could not find that order id in our database. <a href="%s">Want to retry?</a></p>', 'fflcommerce'), get_permalink($post->ID)); } } else { ?> <form action="<?php echo esc_url(get_permalink($post->ID)); ?> " method="post" class="track_order"> <p><?php _e('To track your order please enter your Order ID and email address in the boxes below and press return. This was given to you on your receipt and in the confirmation email you should have received.', 'fflcommerce'); ?> </p> <p class="form-row form-row-first"><label for="orderid"><?php _e('Order ID', 'fflcommerce'); ?> </label> <input class="input-text" type="text" name="orderid" id="orderid" placeholder="<?php _e('Found in your order confirmation email.', 'fflcommerce'); ?> " /></p> <p class="form-row form-row-last"><label for="order_email"><?php _e('Billing Email', 'fflcommerce'); ?> </label> <input class="input-text" type="text" name="order_email" id="order_email" placeholder="<?php _e('Email you used during checkout.', 'fflcommerce'); ?> " /></p> <div class="clear"></div> <p class="form-row"><input type="submit" class="button" name="track" value="<?php _e('Track"', 'fflcommerce'); ?> " /></p> <?php fflcommerce::nonce_field('order_tracking'); ?> </form> <?php } }
/** * Outputs the thankyou page **/ function fflcommerce_thankyou() { $thankyou_message = __('<p>Thank you. Your order has been processed successfully.</p>', 'fflcommerce'); echo apply_filters('fflcommerce_thankyou_message', $thankyou_message); // Pay for order after checkout step if (isset($_GET['order'])) { $order_id = $_GET['order']; } else { $order_id = 0; } if (isset($_GET['key'])) { $order_key = $_GET['key']; } else { $order_key = ''; } if ($order_id > 0) { $order = new fflcommerce_order($order_id); if ($order->order_key == $order_key) { ?> <?php do_action('fflcommerce_thankyou_before_order_details', $order->id); ?> <ul class="order_details"> <li class="order"> <?php _e('Order:', 'fflcommerce'); ?> <strong><?php echo $order->get_order_number(); ?> </strong> </li> <li class="date"> <?php _e('Date:', 'fflcommerce'); ?> <strong><?php echo date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($order->order_date)); ?> </strong> </li> <li class="total"> <?php _e('Total:', 'fflcommerce'); ?> <strong><?php echo fflcommerce_price($order->order_total); ?> </strong> </li> <li class="method"> <?php _e('Payment method:', 'fflcommerce'); ?> <strong><?php $gateways = fflcommerce_payment_gateways::payment_gateways(); if (isset($gateways[$order->payment_method])) { echo $gateways[$order->payment_method]->title; } else { echo $order->payment_method; } ?> </strong> </li> </ul> <div class="clear"></div> <?php do_action('thankyou_' . $order->payment_method, $order_id); do_action('fflcommerce_thankyou', $order->id); } } echo '<p><a class="button" href="' . esc_url(fflcommerce_cart::get_shop_url()) . '">' . __('← Continue Shopping', 'fflcommerce') . '</a></p>'; }
/** * @param fflcommerce_order $order * @return string */ function fflcommerce_get_order_taxes_list($order) { $taxes = ''; foreach ($order->get_tax_classes() as $tax_class) { $taxes .= sprintf(_x('%s (%s%%): %.4f', 'emails', 'fflcommerce'), $order->get_tax_class_for_display($tax_class), $order->get_tax_rate($tax_class), $order->get_tax_amount($tax_class)) . PHP_EOL; } return $taxes; }
function column_default($user, $column_name) { switch ($column_name) { case 'customer_name': if ($user->last_name && $user->first_name) { return $user->last_name . ', ' . $user->first_name; } else { return '-'; } case 'username': return $user->user_login; case 'location': $state_code = get_user_meta($user->ID, 'billing_state', true); $country_code = get_user_meta($user->ID, 'billing_country', true); $state = fflcommerce_countries::has_state($country_code, $state_code) ? fflcommerce_countries::get_state($country_code, $state_code) : $state_code; $country = fflcommerce_countries::has_country($country_code) ? fflcommerce_countries::get_country($country_code) : $country_code; $value = ''; if ($state) { $value .= $state . ', '; } $value .= $country; if ($value) { return $value; } else { return '-'; } case 'email': return '<a href="mailto:' . $user->user_email . '">' . $user->user_email . '</a>'; case 'spent': return fflcommerce_price(fflcommerce_get_customer_total_spent($user->ID)); case 'orders': return fflcommerce_get_customer_order_count($user->ID); case 'last_order': $order_ids = get_posts(array('posts_per_page' => 1, 'post_type' => 'shop_order', 'post_status' => array('publish'), 'orderby' => 'date', 'order' => 'desc', 'meta_query' => array(array('key' => 'customer_user', 'value' => $user->ID)), 'fields' => 'ids')); if ($order_ids) { $order = new fflcommerce_order($order_ids[0]); return '<a href="' . admin_url('post.php?post=' . $order->id . '&action=edit') . '">' . $order->get_order_number() . '</a> – ' . date_i18n(get_option('date_format'), strtotime($order->order_date)); } else { return '-'; } break; case 'user_actions': ob_start(); ?> <p> <?php do_action('fflcommerce_admin_user_actions_start', $user); $actions = array(); $actions['refresh'] = array('url' => wp_nonce_url(add_query_arg('refresh', $user->ID), 'refresh'), 'name' => __('Refresh stats', 'fflcommerce'), 'action' => 'refresh'); $actions['edit'] = array('url' => admin_url('user-edit.php?user_id=' . $user->ID), 'name' => __('Edit', 'fflcommerce'), 'action' => 'edit'); $order_ids = $this->get_guest_orders(); $order_ids = array_map(function ($order) { return $order->ID; }, array_filter($order_ids, function ($order) use($user) { return $order->data['billing_email'] == $user->user_email; })); if ($order_ids) { $actions['link'] = array('url' => wp_nonce_url(add_query_arg('link_orders', $user->ID), 'link_orders'), 'name' => __('Link previous orders', 'fflcommerce'), 'action' => 'link'); } $actions = apply_filters('fflcommerce_admin_user_actions', $actions, $user); foreach ($actions as $action) { printf('<a class="button tips %s" href="%s" data-tip="%s">%s</a>', esc_attr($action['action']), esc_url($action['url']), esc_attr($action['name']), esc_attr($action['name'])); } do_action('fflcommerce_admin_user_actions_end', $user); ?> </p><?php $user_actions = ob_get_contents(); ob_end_clean(); return $user_actions; } return ''; }
function fflcommerce_pay_action() { if (!is_fflcommerce_single_page(FFLCOMMERCE_PAY)) { return; } if (isset($_GET['pay_for_order']) && isset($_GET['order']) && isset($_GET['order_id'])) { // Pay for existing order $order_key = urldecode($_GET['order']); $order_id = (int) $_GET['order_id']; $order = new fflcommerce_order($order_id); if ($order->id == $order_id && $order->order_key == $order_key && $order->status == 'pending') { // Set customer location to order location if ($order->billing_country) { fflcommerce_customer::set_country($order->billing_country); } if ($order->billing_state) { fflcommerce_customer::set_state($order->billing_state); } if ($order->billing_postcode) { fflcommerce_customer::set_postcode($order->billing_postcode); } // Pay form was posted - process payment if (isset($_POST['pay']) && fflcommerce::verify_nonce('pay')) { // Update payment method if ($order->order_total > 0) { $payment_method = fflcommerce_clean($_POST['payment_method']); $data = (array) maybe_unserialize(get_post_meta($order_id, 'order_data', true)); $data['payment_method'] = $payment_method; update_post_meta($order_id, 'order_data', $data); $available_gateways = fflcommerce_payment_gateways::get_available_payment_gateways(); $result = $available_gateways[$payment_method]->process_payment($order_id); // Redirect to success/confirmation/payment page if ($result['result'] == 'success') { wp_safe_redirect($result['redirect']); exit; } } else { // No payment was required for order $order->payment_complete(); // filter redirect page $checkout_redirect = apply_filters('fflcommerce_get_checkout_redirect_page_id', fflcommerce_get_page_id('thanks')); wp_safe_redirect(get_permalink($checkout_redirect)); exit; } } } elseif ($order->status != 'pending') { fflcommerce::add_error(__('Your order has already been paid for. Please contact us if you need assistance.', 'fflcommerce')); } else { fflcommerce::add_error(__('Invalid order.', 'fflcommerce')); } } else { // Pay for order after checkout step if (isset($_GET['order'])) { $order_id = $_GET['order']; } else { $order_id = 0; } if (isset($_GET['key'])) { $order_key = $_GET['key']; } else { $order_key = ''; } if ($order_id > 0) { $order = new fflcommerce_order($order_id); if ($order->order_key != $order_key || $order->status != 'pending') { wp_safe_redirect(apply_filters('fflcommerce_get_myaccount_page_id', get_permalink(fflcommerce_get_page_id('myaccount')))); exit; } } else { wp_safe_redirect(apply_filters('fflcommerce_get_myaccount_page_id', get_permalink(fflcommerce_get_page_id('myaccount')))); exit; } } }
/** * Generate the futurepay payment iframe */ protected function call_futurepay($order_id) { // Get the order $order = new fflcommerce_order($order_id); $data = array('gmid' => $this->gmid, 'reference' => $order_id . '-' . uniqid(), 'email' => $order->billing_email, 'first_name' => $order->billing_first_name, 'last_name' => $order->billing_last_name, 'company' => $order->billing_company, 'address_line_1' => $order->billing_address_1, 'address_line_2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'country' => $order->billing_country, 'zip' => $order->billing_postcode, 'phone' => $order->billing_phone, 'shipping_address_line_1' => $order->shipping_address_1, 'shipping_address_line_2' => $order->shipping_address_2, 'shipping_city' => $order->shipping_city, 'shipping_state' => $order->shipping_state, 'shipping_country' => $order->shipping_country, 'shipping_zip' => $order->shipping_postcode, 'shipping_date' => date('Y/m/d g:i:s')); // for FFL Commerce 1.0, FuturePay doesn't allow negative prices (or 0.00 ) which affects discounts // with FuturePay doing the calcs, so we will bundle all products into ONE line item with // a quantity of ONE and send it that way using the final order total after shipping // and discounts are applied // all product titles will be comma delimited with their quantities $item_names = array(); if (sizeof($order->items) > 0) { foreach ($order->items as $item) { $_product = $order->get_product_from_item($item); $title = $_product->get_title(); // if variation, insert variation details into product title if ($_product instanceof fflcommerce_product_variation) { $title .= ' (' . fflcommerce_get_formatted_variation($_product, $item['variation'], true) . ')'; } $item_names[] = $item['qty'] . ' x ' . $title; } } // now add the one line item to the necessary product field arrays $data['sku'][] = "Products"; $data['price'][] = $order->order_total; // futurepay only needs final order amount $data['tax_amount'][] = 0; $data['description'][] = sprintf(__('Order %s', 'fflcommerce'), $order->get_order_number()) . ' = ' . implode(', ', $item_names); $data['quantity'][] = 1; try { $response = wp_remote_post(self::$request_url . 'merchant-request-order-token', array('body' => http_build_query($data), 'sslverify' => false)); // Convert error to exception if (is_wp_error($response)) { if (class_exists('WP_Exception') && $response instanceof WP_Exception) { throw $response; } else { fflcommerce_log($response->get_error_message()); throw new Exception($response->get_error_message()); } } // Fetch the body from the result, any errors should be caught before proceeding $response = trim(wp_remote_retrieve_body($response)); // we need something to validate the response. Valid transactions begin with 'FPTK' if (!strstr($response, 'FPTK')) { $error_message = isset(self::$futurepay_errorcodes[$response]) ? self::$futurepay_errorcodes[$response] : __('An unknown error has occured with code = ', 'fflcommerce') . $response; $order->add_order_note(sprintf(__('FUTUREPAY: %s', 'fflcommerce'), $error_message)); fflcommerce::add_error(sprintf(__('FUTUREPAY: %s. Please try again or select another gateway for your Order.', 'fflcommerce'), $error_message)); wp_safe_redirect(get_permalink(fflcommerce_get_page_id('checkout'))); exit; } /** * If we're good to go, haul in FuturePay's javascript and display the payment form * so that the customer can enter his ID and password */ echo '<div id="futurepay"></div>'; echo '<script src="' . self::$request_url . 'cart-integration/' . $response . '"></script>'; echo '<script type="text/javascript"> /*<![CDATA[*/ jQuery(window).load( function() { FP.CartIntegration(); // Need to replace form html jQuery("#futurepay").html(FP.CartIntegration.getFormContent()); FP.CartIntegration.displayFuturePay(); }); function FuturePayResponseHandler(response) { if (response.error) { // TODO: we need something better than this alert(response.code + " " + response.message); } else { window.location.replace("./?futurepay="+response.transaction_id); } } /*]]>*/ </script>'; echo '<input type="button" class="button alt" name="place_order" id="place_order" value="Place Order" onclick="FP.CartIntegration.placeOrder();" />'; } catch (Exception $e) { echo '<div class="fflcommerce_error">' . $e->getMessage() . '</div>'; fflcommerce_log('FUTUREPAY ERROR: ' . $e->getMessage()); } }