function paymill_marketpress_errorHandling($errors)
 {
     global $mp;
     foreach ($errors as $error) {
         $mp->cart_checkout_error('<div class="paymill_error">' . $error . '. ' . sprintf(__('Please <a href="%s">go back and try again</a>.', 'paymill'), mp_checkout_step_url('checkout')) . '</div>');
     }
 }
示例#2
0
文件: ideal.php 项目: hscale/webento
 /**
  * Runs when your class is instantiated. Use to setup your plugin instead of __construct()
  */
 function on_creation()
 {
     global $mp;
     //set names here to be able to translate
     $this->admin_name = __('iDEAL (beta)', 'mp');
     $this->public_name = __('iDEAL', 'mp');
     $this->method_img_url = $mp->plugin_url . 'images/ideal.png';
     $this->method_button_img_url = $mp->plugin_url . 'images/ideal.png';
     $this->merchant_id = $mp->get_setting('gateways->ideal->merchant_id');
     $this->ideal_hash = $mp->get_setting('gateways->ideal->ideal_hash');
     $this->returnURL = mp_checkout_step_url('confirm-checkout');
     $this->cancelURL = mp_checkout_step_url('checkout') . "?cancel=1";
     $this->errorURL = mp_checkout_step_url('checkout') . "?err=1";
 }
示例#3
0
 /**
  * Runs when your class is instantiated. Use to setup your plugin instead of __construct()
  */
 function on_creation()
 {
     global $mp;
     $settings = get_option('mp_settings');
     //set names here to be able to translate
     $this->admin_name = __('PayWay', 'mp');
     $this->public_name = __('PayWay', 'mp');
     $this->method_img_url = $mp->plugin_url . 'images/ideal.png';
     $this->method_button_img_url = $mp->plugin_url . 'images/ideal.png';
     $this->merchant_id = $settings['gateways']['payway']['merchant_id'];
     $this->ideal_hash = $settings['gateways']['payway']['ideal_hash'];
     $this->returnURL = mp_checkout_step_url('confirm-checkout');
     $this->cancelURL = mp_checkout_step_url('checkout') . "?cancel=1";
     $this->errorURL = mp_checkout_step_url('checkout') . "?err=1";
 }
示例#4
0
 /**
  * Use this to do the final payment. Create the order then process the payment. If
  *  you know the payment is successful right away go ahead and change the order status
  *  as well.
  *  Call $mp->cart_checkout_error($msg, $context); to handle errors. If no errors
  *  it will redirect to the next step.
  *
  * @param array $cart. Contains the cart contents for the current blog, global cart if $mp->global_cart is true
  * @param array $shipping_info. Contains shipping info and email in case you need it
  */
 function process_payment($cart, $shipping_info)
 {
     global $mp;
     $timestamp = time();
     $settings = get_option('mp_settings');
     $billing_info = $_SESSION['mp_billing_info'];
     $payment = new MP_Gateway_Worker_AuthorizeNet_AIM($this->API_Endpoint, $settings['gateways']['authorizenet-aim']['delim_data'], $settings['gateways']['authorizenet-aim']['delim_char'], $settings['gateways']['authorizenet-aim']['encap_char'], $settings['gateways']['authorizenet-aim']['api_user'], $settings['gateways']['authorizenet-aim']['api_key'], $settings['gateways']['authorizenet-aim']['mode'] == 'sandbox');
     $payment->transaction($_SESSION['card_num']);
     $totals = array();
     $coupon_code = $mp->get_coupon_code();
     foreach ($cart as $product_id => $variations) {
         foreach ($variations as $variation => $data) {
             $sku = empty($data['SKU']) ? "{$product_id}_{$variation}" : $data['SKU'];
             //total on tax excluded
             $price = $mp->coupon_value_product($coupon_code, $data['price'] * $data['quantity'], $product_id);
             $totals[] = $price;
             //display as tax inclusive
             $payment->addLineItem($sku, substr($data['name'], 0, 31), substr($data['name'] . ' - ' . $data['url'], 0, 254), $data['quantity'], $data['price'], 1);
             $i++;
         }
     }
     $total = array_sum($totals);
     //shipping line
     $shipping_tax = 0;
     if (($shipping_price = $mp->shipping_price(false)) !== false) {
         $total += $shipping_price;
         $shipping_tax = $mp->shipping_tax_price($shipping_price) - $shipping_price;
     }
     //tax line if tax inclusive pricing is off. It it's on it would screw up the totals
     if (!$mp->get_setting('tax->tax_inclusive')) {
         $tax_price = $mp->tax_price(false) + $shipping_tax;
         $total += $tax_price;
     }
     // Billing Info
     $payment->setParameter("x_card_code", $_SESSION['card_code']);
     $payment->setParameter("x_exp_date ", $_SESSION['exp_month'] . $_SESSION['exp_year']);
     $payment->setParameter("x_amount", $total);
     $payment->setParameter("x_currency_code", $this->currencyCode);
     // Order Info
     $payment->setParameter("x_description", "Order ID: " . $_SESSION['mp_order']);
     $payment->setParameter("x_invoice_num", $_SESSION['mp_order']);
     $payment->setParameter("x_test_request", false);
     // this should NEVER be true, even in sandbox mode
     $payment->setParameter("x_duplicate_window", 30);
     // E-mail
     $payment->setParameter("x_header_email_receipt", $settings['gateways']['authorizenet-aim']['header_email_receipt']);
     $payment->setParameter("x_footer_email_receipt", $settings['gateways']['authorizenet-aim']['footer_email_receipt']);
     $payment->setParameter("x_email_customer", strtoupper($settings['gateways']['authorizenet-aim']['email_customer']));
     $_names = explode(" ", $billing_info['name']);
     if (isset($_names[0])) {
         $first_name = array_shift($_names);
     } else {
         $first_name = "";
     }
     if (isset($_names[0])) {
         $last_name = join(" ", $_names);
     } else {
         $last_name = "";
     }
     $address = $billing_info['address1'];
     if (!empty($billing_info['address2'])) {
         $address .= "\n" . $billing_info['address2'];
     }
     //Customer Info
     $payment->setParameter("x_first_name", $first_name);
     $payment->setParameter("x_last_name", $last_name);
     $payment->setParameter("x_address", $address);
     $payment->setParameter("x_city", $billing_info['city']);
     $payment->setParameter("x_state", $billing_info['state']);
     $payment->setParameter("x_country", $billing_info['country']);
     $payment->setParameter("x_zip", $billing_info['zip']);
     $payment->setParameter("x_phone", $billing_info['phone']);
     $payment->setParameter("x_email", $billing_info['email']);
     //only add shipping info if set
     if (!$mp->download_only_cart($cart) && isset($shipping_info['name'])) {
         $_names = explode(" ", $shipping_info['name']);
         if (isset($_names[0])) {
             $shipping_first_name = array_shift($_names);
         } else {
             $shipping_first_name = "";
         }
         if (isset($_names[0])) {
             $shipping_last_name = join(" ", $_names);
         } else {
             $shipping_last_name = "";
         }
         $shipping_address = $shipping_info['address1'];
         if (!empty($billing_info['address2'])) {
             $shipping_address .= "\n" . $shipping_info['address2'];
         }
         $payment->setParameter("x_ship_to_first_name", $shipping_first_name);
         $payment->setParameter("x_ship_to_last_name", $shipping_last_name);
         $payment->setParameter("x_ship_to_address", $shipping_address);
         $payment->setParameter("x_ship_to_city", $shipping_info['city']);
         $payment->setParameter("x_ship_to_state", $shipping_info['state']);
         $payment->setParameter("x_ship_to_country", $shipping_info['country']);
         $payment->setParameter("x_ship_to_zip", $shipping_info['zip']);
     }
     $payment->setParameter("x_customer_ip", $_SERVER['REMOTE_ADDR']);
     $payment->process();
     if ($payment->isApproved()) {
         $paid = $payment->isHeldForReview() ? false : true;
         $payment_info['gateway_public_name'] = $this->public_name;
         $payment_info['gateway_private_name'] = $this->admin_name;
         $payment_info['method'] = $payment->getMethod();
         $payment_info['status'][$timestamp] = $payment->isHeldForReview() ? __('held for review', 'mp') : __('paid', 'mp');
         $payment_info['total'] = $total;
         $payment_info['currency'] = $this->currencyCode;
         $payment_info['transaction_id'] = $payment->getTransactionID();
         //succesful payment, create our order now
         $result = $mp->create_order($_SESSION['mp_order'], $cart, $shipping_info, $payment_info, $paid);
     } else {
         $error = $payment->getResponseText();
         $mp->cart_checkout_error(sprintf(__('There was a problem finalizing your purchase. %s Please <a href="%s">go back and try again</a>.', 'mp'), $error, mp_checkout_step_url('checkout')));
     }
 }
示例#5
0
 /**
  * Use this to do the final payment. Create the order then process the payment. If
  * you know the payment is successful right away go ahead and change the order status
  * as well.
  * Call $mp->cart_checkout_error($msg, $context); to handle errors. If no errors
  * it will redirect to the next step.
  *
  * @param array $cart. Contains the cart contents for the current blog, global cart if $mp->global_cart is true
  * @param array $shipping_info. Contains shipping info and email in case you need it
  */
 function process_payment($cart, $shipping_info)
 {
     global $mp;
     $settings = get_option('mp_settings');
     // Token MUST be set at this point
     if (!isset($_SESSION['simplifyToken'])) {
         $mp->cart_checkout_error(__('The Simplify Token was not generated correctly. Please go back and try again.', 'mp'));
         return false;
     }
     // Setup the Simplify API
     if (!class_exists('Simplify')) {
         require_once $mp->plugin_dir . "plugins-gateway/simplify-files/lib/Simplify.php";
     }
     Simplify::$publicKey = $this->publishable_key;
     Simplify::$privateKey = $this->private_key;
     $totals = array();
     $coupon_code = $mp->get_coupon_code();
     foreach ($cart as $product_id => $variations) {
         foreach ($variations as $variation => $data) {
             $price = $mp->coupon_value_product($coupon_code, $data['price'] * $data['quantity'], $product_id);
             $totals[] = $price;
         }
     }
     $total = array_sum($totals);
     //shipping line
     $shipping_tax = 0;
     if (($shipping_price = $mp->shipping_price(false)) !== false) {
         $total += $shipping_price;
         $shipping_tax = $mp->shipping_tax_price($shipping_price) - $shipping_price;
     }
     //tax line if tax inclusive pricing is off. It it's on it would screw up the totals
     if (!$mp->get_setting('tax->tax_inclusive')) {
         $tax_price = $mp->tax_price(false) + $shipping_tax;
         $total += $tax_price;
     }
     $order_id = $mp->generate_order_id();
     try {
         $token = $SESSION['simplifyToken'];
         $charge = Simplify_Payment::createPayment(array('amount' => $total * 100, 'token' => $_SESSION['simplifyToken'], 'description' => sprintf(__('%s Store Purchase - Order ID: %s, Email: %s', 'mp'), get_bloginfo('name'), $order_id, $_SESSION['mp_shipping_info']['email']), 'currency' => $this->currency));
         if ($charge->paymentStatus == 'APPROVED') {
             $payment_info = array();
             $payment_info['gateway_public_name'] = $this->public_name;
             $payment_info['gateway_private_name'] = $this->admin_name;
             $payment_info['method'] = sprintf(__('%1$s Card ending in %2$s - Expires %3$s', 'mp'), $charge->card->type, $charge->card->last4, $charge->card->expMonth . '/' . $charge->card->expYear);
             $payment_info['transaction_id'] = $charge->id;
             $timestamp = time();
             $payment_info['status'][$timestamp] = __('Paid', 'mp');
             $payment_info['total'] = $total;
             $payment_info['currency'] = $this->currency;
             $order = $mp->create_order($order_id, $cart, $_SESSION['mp_shipping_info'], $payment_info, true);
             unset($_SESSION['simplifyToken']);
             $mp->set_cart_cookie(array());
         }
     } catch (Exception $e) {
         unset($_SESSION['simplifyToken']);
         $mp->cart_checkout_error(sprintf(__('There was an error processing your card: "%s". Please <a href="%s">go back and try again</a>.', 'mp'), $e->getMessage(), mp_checkout_step_url('checkout')));
         return false;
     }
 }
示例#6
0
 /**
  * Use this to do the final payment. Create the order then process the payment. If
  *    you know the payment is successful right away go ahead and change the order status
  *    as well.
  *    Call $mp->cart_checkout_error($msg, $context); to handle errors. If no errors
  *    it will redirect to the next step.
  *
  * @param array $cart          . Contains the cart contents for the current blog, global cart if $mp->global_cart is true
  * @param array $shipping_info . Contains shipping info and email in case you need it
  */
 function process_payment($cart, $shipping_info)
 {
     //if iframe is disabled, redirect user to bitpay site
     global $mp;
     $iframe_enabled = $mp->get_setting('gateways->bitpay->iframe');
     $private_key = $mp->get_setting('gateways->bitpay->private_key');
     // If iframe is enabled, return
     if ($iframe_enabled == 'yes') {
         return;
     }
     //Bitpay Invoice id
     $bitpayInvoiceId = isset($_SESSION['bitpayInvoiceId']) ? $_SESSION['bitpayInvoiceId'] : '';
     if (!$bitpayInvoiceId) {
         return;
     }
     //get Invoice status
     $invoice = $this->bitpay_get_invoice($bitpayInvoiceId, $private_key);
     //Check order Id for obtained Invoice
     if ($_SESSION['mp_order'] != $invoice->posData) {
         $mp->cart_checkout_error(__('Incorrect order invoice, please contact site administrator', 'mp'));
         wp_redirect(mp_checkout_step_url('confirm-checkout'));
         exit;
     }
     //If order status new, redirect user to bitpay
     if ($invoice->status == 'new') {
         wp_redirect($invoice->url);
         exit;
     }
 }
示例#7
0
 /**
  * Use this to do the final payment. Create the order then process the payment. If
  *  you know the payment is successful right away go ahead and change the order status
  *  as well.
  *  Call $mp->cart_checkout_error($msg, $context); to handle errors. If no errors
  *  it will redirect to the next step.
  *
  * @param array $cart. Contains the cart contents for the current blog, global cart if $mp->global_cart is true
  * @param array $shipping_info. Contains shipping info and email in case you need it
  */
 function process_payment($cart, $shipping_info)
 {
     global $mp, $current_user;
     $timestamp = time();
     $settings = get_option('mp_settings');
     $url = $this->API_URL . "api/checkout/v2/merchantCheckoutForm/Merchant/" . $this->API_Merchant_id;
     $order_id = $mp->generate_order_id();
     $params = array();
     $params['_type'] = 'checkout-shopping-cart';
     $params['shopping-cart.merchant-private-data'] = $order_id;
     $params['checkout-flow-support.merchant-checkout-flow-support.edit-cart-url'] = mp_cart_link(false, true);
     $params["checkout-flow-support.merchant-checkout-flow-support.continue-shopping-url"] = mp_store_link(false, true);
     $params["checkout-flow-support.merchant-checkout-flow-support.tax-tables.default-tax-table.tax-rules.default-tax-rule-1.shipping-taxed"] = $settings['tax']['tax_shipping'] ? 'true' : 'false';
     $params["checkout-flow-support.merchant-checkout-flow-support.tax-tables.default-tax-table.tax-rules.default-tax-rule-1.tax-areas.world-area-1"] = '';
     $totals = array();
     $item_params = array();
     $i = 1;
     $items = 0;
     $coupon_code = $mp->get_coupon_code();
     foreach ($cart as $product_id => $variations) {
         foreach ($variations as $data) {
             $price = $mp->coupon_value_product($coupon_code, $data['price'] * $data['quantity'], $product_id);
             $totals[] = $price;
             $item_params["shopping-cart.items.item-{$i}.item-name"] = $data['name'];
             $item_params["shopping-cart.items.item-{$i}.item-description"] = $data['url'];
             $item_params["shopping-cart.items.item-{$i}.unit-price"] = $price;
             $item_params["shopping-cart.items.item-{$i}.unit-price.currency"] = $this->currencyCode;
             $item_params["shopping-cart.items.item-{$i}.quantity"] = $data['quantity'];
             $item_params["shopping-cart.items.item-{$i}.merchant-item-id"] = $data['SKU'];
             $i++;
             $items++;
         }
     }
     $total = array_sum($totals);
     $params = array_merge($params, $item_params);
     //shipping line
     $shipping_tax = 0;
     if (($shipping_price = $mp->shipping_price(false)) !== false) {
         $total += $shipping_price;
         $shipping_tax = $mp->shipping_tax_price($shipping_price) - $shipping_price;
         $params["checkout-flow-support.merchant-checkout-flow-support.shipping-methods.flat-rate-shipping-1.price"] = $shipping_price;
         $params["checkout-flow-support.merchant-checkout-flow-support.shipping-methods.flat-rate-shipping-1.price.currency"] = $this->currencyCode;
         $params["checkout-flow-support.merchant-checkout-flow-support.shipping-methods.flat-rate-shipping-1.name"] = __('Standard Shipping', 'mp');
     }
     //tax line if tax inclusive pricing is off. It it's on it would screw up the totals
     if (!$mp->get_setting('tax->tax_inclusive')) {
         $tax_price = $mp->tax_price(false) + $shipping_tax;
         $total += $tax_price;
         $params["checkout-flow-support.merchant-checkout-flow-support.tax-tables.default-tax-table.tax-rules.default-tax-rule-1.rate"] = $tax_price;
     } else {
         $params["checkout-flow-support.merchant-checkout-flow-support.tax-tables.default-tax-table.tax-rules.default-tax-rule-1.rate"] = '0.00';
     }
     $param_list = array();
     foreach ($params as $k => $v) {
         $param_list[] = "{$k}=" . rawurlencode($v);
     }
     $param_str = implode('&', $param_list);
     //setup transients for ipn in case checkout doesn't redirect (ipn should come within 12 hrs!)
     set_transient('mp_order_' . $order_id . '_cart', $cart, 60 * 60 * 12);
     set_transient('mp_order_' . $order_id . '_shipping', $shipping_info, 60 * 60 * 12);
     set_transient('mp_order_' . $order_id . '_userid', $current_user->ID, 60 * 60 * 12);
     $response = $this->google_api_request($param_str, $url);
     if ($response['_type'] == 'checkout-redirect') {
         wp_redirect($response['redirect-url']);
         exit;
     } else {
         $mp->cart_checkout_error(sprintf(__('There was a problem setting up your purchase with Google Checkout. Please try again or <a href="%s">select a different payment method</a>.<br/>%s', 'mp'), mp_checkout_step_url('checkout'), @$response['error-message']));
     }
 }
示例#8
0
 /**
  * Use this to do the final payment. Create the order then process the payment. If
  *  you know the payment is successful right away go ahead and change the order status
  *  as well.
  *  Call $mp->cart_checkout_error($msg, $context); to handle errors. If no errors
  *  it will redirect to the next step.
  *
  * @param array $cart. Contains the cart contents for the current blog, global cart if $mp->global_cart is true
  * @param array $shipping_info. Contains shipping info and email in case you need it
  */
 function process_payment($cart, $shipping_info)
 {
     global $mp, $current_user;
     $timestamp = time();
     $settings = get_option('mp_settings');
     $url = "https://www.moneybookers.com/app/payment.pl";
     $order_id = $mp->generate_order_id();
     $params = array();
     $params['transaction_id'] = $order_id;
     $params['pay_to_email'] = $this->API_Email;
     $params['currency'] = $this->currencyCode;
     $params['language'] = $this->API_Language;
     $params['return_url'] = mp_checkout_step_url('confirmation');
     $params['return_url_text'] = __('Complete Checkout', 'mp');
     $params['cancel_url'] = mp_checkout_step_url('checkout');
     $params['status_url'] = $this->ipn_url;
     $params['confirmation_note'] = $this->confirmationNote;
     if (isset($settings['gateways']['moneybookers']['logourl']) && !empty($settings['gateways']['moneybookers']['logourl'])) {
         $params['logo_url'] = $settings['gateways']['moneybookers']['logourl'];
     }
     if (isset($settings['gateways']['moneybookers']['business-name']) && !empty($settings['gateways']['moneybookers']['business-name'])) {
         $params['recipient_description'] = $settings['gateways']['moneybookers']['business-name'];
     }
     $params['pay_from_email'] = $shipping_info['email'];
     if (!$mp->download_only_cart($cart) && $mp->get_setting('shipping->method') != 'none' && isset($shipping_info['name'])) {
         $names = explode(' ', $shipping_info['name']);
         $params['firstname'] = $names[0];
         $params['lastname'] = $names[count($names) - 1];
         //grab last name
         $params['address'] = $shipping_info['address1'];
         $params['phone_number'] = $shipping_info['phone'];
         $params['postal_code'] = $shipping_info['zip'];
         $params['city'] = $shipping_info['city'];
         $params['state'] = $shipping_info['state'];
     }
     $totals = array();
     $product_count = 0;
     $coupon_code = $mp->get_coupon_code();
     foreach ($cart as $product_id => $variations) {
         foreach ($variations as $data) {
             $price = $mp->coupon_value_product($coupon_code, $data['price'] * $data['quantity'], $product_id);
             //we're sending tax included prices here if tax included is on
             $totals[] = $price;
             $product_count++;
         }
     }
     $params["detail1_text"] = $order_id;
     $params["detail1_description"] = __('Order ID:', 'mp');
     $total = array_sum($totals);
     $i = 2;
     $params["amount{$i}"] = $mp->display_currency($total);
     $params["amount{$i}_description"] = sprintf(__('Cart Subtotal for %d Items:', 'mp'), $product_count);
     $i++;
     //shipping line
     $shipping_tax = 0;
     if (($shipping_price = $mp->shipping_price(false)) !== false) {
         $total += $shipping_price;
         $shipping_tax = $mp->shipping_tax_price($shipping_price) - $shipping_price;
         $params["amount{$i}"] = $mp->display_currency($shipping_price);
         $params["amount{$i}_description"] = __('Shipping & Handling:', 'mp');
         $i++;
     }
     //tax line if tax inclusive pricing is off. It it's on it would screw up the totals
     $tax_price = $mp->tax_price(false) + $shipping_tax;
     if (!$mp->get_setting('tax->tax_inclusive')) {
         $total += $tax_price;
         $params["amount{$i}"] = $mp->display_currency($tax_price);
         $params["amount{$i}_description"] = __('Taxes:', 'mp');
         $i++;
     } else {
         $params["detail3_text"] = $mp->display_currency($tax_price);
         $params["detail3_description"] = __('Taxes:', 'mp');
         $i++;
     }
     $params['amount'] = $total;
     $param_list = array();
     foreach ($params as $k => $v) {
         $param_list[] = "{$k}=" . rawurlencode($v);
     }
     $param_str = implode('&', $param_list);
     //setup transients for ipn in case checkout doesn't redirect (ipn should come within 12 hrs!)
     set_transient('mp_order_' . $order_id . '_cart', $cart, 60 * 60 * 12);
     set_transient('mp_order_' . $order_id . '_shipping', $shipping_info, 60 * 60 * 12);
     set_transient('mp_order_' . $order_id . '_userid', $current_user->ID, 60 * 60 * 12);
     wp_redirect("{$url}?{$param_str}");
     exit(0);
 }
示例#9
0
function _mp_cart_payment($type, $echo = false)
{
    global $mp, $blog_id, $mp_gateway_active_plugins;
    $blog_id = is_multisite() ? $blog_id : 1;
    $cart = $mp->get_cart_contents($mp->global_cart);
    $content = '';
    if ($type == 'form') {
        $content = '<form id="mp_payment_form" method="post" action="' . mp_checkout_step_url('checkout') . '">';
        if (count((array) $mp_gateway_active_plugins) == 1) {
            $content .= '<input type="hidden" name="mp_choose_gateway" value="' . $mp_gateway_active_plugins[0]->plugin_name . '" />';
        } else {
            if (count((array) $mp_gateway_active_plugins) > 1) {
                $content .= '<table class="mp_cart_payment_methods">';
                $content .= '<thead><tr>';
                $content .= '<th>' . __('Choose a Payment Method:', 'mp') . '</th>';
                $content .= '</tr></thead>';
                $content .= '<tbody><tr><td>';
                foreach ((array) $mp_gateway_active_plugins as $plugin) {
                    $content .= '<label>';
                    $content .= '<input type="radio" class="mp_choose_gateway" name="mp_choose_gateway" value="' . $plugin->plugin_name . '" ' . checked($_SESSION['mp_payment_method'], $plugin->plugin_name, false) . '/>';
                    if ($plugin->method_img_url) {
                        $content .= '<img src="' . $plugin->method_img_url . '" alt="' . $plugin->public_name . '" />';
                    } else {
                        $content .= $plugin->public_name;
                    }
                    $content .= '</label>';
                }
                $content .= '</td>';
                $content .= '</tr>';
                $content .= '</tbody>';
                $content .= '</table>';
            }
        }
        $content .= apply_filters('mp_checkout_payment_form', '', $cart, $_SESSION['mp_shipping_info']);
        $content .= '</form>';
    } else {
        if ($type == 'confirm') {
            //if skipping a step
            if (empty($_SESSION['mp_payment_method'])) {
                $content .= '<div class="mp_checkout_error">' . sprintf(__('Whoops, looks like you skipped a step! Please <a href="%s">go back and try again</a>.', 'mp'), mp_checkout_step_url('checkout')) . '</div>';
                return $content;
            }
            $content .= '<form id="mp_payment_form" method="post" action="' . mp_checkout_step_url('confirm-checkout') . '">';
            $content .= apply_filters('mp_checkout_confirm_payment_' . $_SESSION['mp_payment_method'], $cart, $_SESSION['mp_shipping_info']);
            $content .= '<p class="mp_cart_direct_checkout">';
            $content .= '<input type="submit" name="mp_payment_confirm" id="mp_payment_confirm" value="' . __('Confirm Payment &raquo;', 'mp') . '" />';
            $content .= '</p>';
            $content .= '</form>';
        } else {
            if ($type == 'confirmation') {
                //if skipping a step
                if (empty($_SESSION['mp_payment_method'])) {
                    //$content .= '<div class="mp_checkout_error">' . sprintf(__('Whoops, looks like you skipped a step! Please <a href="%s">go back and try again</a>.', 'mp'), mp_checkout_step_url('checkout')) . '</div>';
                }
                //gateway plugin message hook
                $content .= apply_filters('mp_checkout_payment_confirmation_' . $_SESSION['mp_payment_method'], '', $mp->get_order($_SESSION['mp_order']));
                //tracking information
                $track_link = '<a href="' . mp_orderstatus_link(false, true) . $_SESSION['mp_order'] . '/' . '">' . mp_orderstatus_link(false, true) . $_SESSION['mp_order'] . '/' . '</a>';
                $content .= '<p>' . sprintf(__('You may track the latest status of your order(s) here:<br />%s', 'mp'), $track_link) . '</p>';
                //add ecommerce JS
                $mp->create_ga_ecommerce($mp->get_order($_SESSION['mp_order']));
                //clear cart session vars
                unset($_SESSION['mp_payment_method']);
                unset($_SESSION['mp_order']);
            }
        }
    }
    if ($echo) {
        echo $content;
    } else {
        return $content;
    }
}
示例#10
0
 /**
  * Use this to do the final payment. Create the order then process the payment. If
  *  you know the payment is successful right away go ahead and change the order status
  *  as well.
  *  Call $mp->cart_checkout_error($msg, $context); to handle errors. If no errors
  *  it will redirect to the next step.
  *
  * @param array $cart. Contains the cart contents for the current blog, global cart if $mp->global_cart is true
  * @param array $shipping_info. Contains shipping info and email in case you need it
  */
 function process_payment($cart, $shipping_info)
 {
     global $mp;
     $timestamp = time();
     $settings = get_option('mp_settings');
     $url = "https://www.2checkout.com/checkout/purchase";
     $params = array();
     $params['sid'] = $this->API_Username;
     $params['cart_order_id'] = $_SESSION['mp_order'];
     $params['x_receipt_link_url'] = mp_checkout_step_url('confirmation');
     $params['skip_landing'] = '1';
     $params['fixed'] = 'Y';
     $params['currency_code'] = $this->currencyCode;
     if ($this->SandboxFlag == 'sandbox') {
         $params['demo'] = 'Y';
     }
     $totals = array();
     $counter = 1;
     $params["id_type"] = 1;
     foreach ($cart as $product_id => $variations) {
         foreach ($variations as $variation => $data) {
             $totals[] = $mp->before_tax_price($data['price'], $product_id) * $data['quantity'];
             $suffix = "_{$counter}";
             $sku = empty($data['SKU']) ? $product_id : $data['SKU'];
             $params["c_prod{$suffix}"] = "{$sku},{$data['quantity']}";
             $params["c_name{$suffix}"] = $data['name'];
             $params["c_description{$suffix}"] = $data['url'];
             $params["c_price{$suffix}"] = $mp->before_tax_price($data['price'], $product_id);
             if ($data['download']) {
                 $params["c_tangible{$suffix}"] = 'N';
             } else {
                 $params["c_tangible{$suffix}"] = 'Y';
             }
             $counter++;
         }
     }
     $total = array_sum($totals);
     if ($coupon = $mp->coupon_value($mp->get_coupon_code(), $total)) {
         $total = $coupon['new_total'];
     }
     //shipping line
     if (($shipping_price = $mp->shipping_price()) !== false) {
         $total = $total + $shipping_price;
         $params['sh_cost'] = $shipping_price;
     }
     //tax line
     if (($tax_price = $mp->tax_price()) !== false) {
         $total = $total + $tax_price;
     }
     $params['total'] = $total;
     $param_list = array();
     foreach ($params as $k => $v) {
         $param_list[] = "{$k}=" . rawurlencode($v);
     }
     $param_str = implode('&', $param_list);
     wp_redirect("{$url}?{$param_str}");
     exit(0);
 }
示例#11
0
 /**
  * Use this to do the final payment. Create the order then process the payment. If
  *  you know the payment is successful right away go ahead and change the order status
  *  as well.
  *  Call $mp->cart_checkout_error($msg, $context); to handle errors. If no errors
  *  it will redirect to the next step.
  *
  * @param array $cart. Contains the cart contents for the current blog, global cart if $mp->global_cart is true
  * @param array $shipping_info. Contains shipping info and email in case you need it
  */
 function process_payment($cart, $shipping_info)
 {
     global $mp;
     $timestamp = time();
     $settings = get_option('mp_settings');
     $params = array();
     if ($this->SandboxFlag == 'sandbox') {
         $url = "https://sandbox.2checkout.com/checkout/purchase";
         $params['demo'] = 'Y';
     } else {
         $url = "https://www.2checkout.com/checkout/purchase";
     }
     $params['sid'] = $this->API_Username;
     $params['cart_order_id'] = $params['merchant_order_id'] = $_SESSION['mp_order'];
     $params['x_receipt_link_url'] = mp_checkout_step_url('confirmation');
     $params['skip_landing'] = '1';
     $params['fixed'] = 'Y';
     $params['currency_code'] = $this->currencyCode;
     $params['mode'] = '2CO';
     // set shipping address
     foreach ($shipping_info as $k => $v) {
         switch ($k) {
             case 'address1':
             case 'address2':
                 $k = 'ship_street_' . $k;
                 break;
             default:
                 $k = 'ship_' . $k;
                 break;
         }
         $params[$k] = $v;
     }
     $totals = array();
     $counter = 1;
     $params["id_type"] = 1;
     $coupon_code = $mp->get_coupon_code();
     foreach ($cart as $product_id => $variations) {
         foreach ($variations as $variation => $data) {
             $price = (double) $mp->coupon_value_product($coupon_code, $data['price'], $product_id);
             $totals[] = $price * $data['quantity'];
             $prefix = 'li_' . $counter;
             $sku = empty($data['SKU']) ? $product_id : $data['SKU'];
             $params["{$prefix}_product_id"] = $sku;
             $params["{$prefix}_name"] = $data['name'];
             $params["{$prefix}_quantity"] = $data['quantity'];
             $params["{$prefix}_description"] = $data['url'];
             $params["{$prefix}_price"] = $price;
             $params["{$prefix}_type"] = 'product';
             if ($data['download']) {
                 $params["{$prefix}_tangible"] = 'N';
             } else {
                 $params["{$prefix}_tangible"] = 'Y';
             }
             $counter++;
         }
     }
     $shipping_tax = 0;
     if (($shipping_price = $mp->shipping_price(false)) !== false) {
         $prefix = 'li_' . $counter;
         $params["{$prefix}_product_id"] = 'shipping';
         $params["{$prefix}_name"] = 'Shipping';
         $params["{$prefix}_type"] = 'shipping';
         $params["{$prefix}_price"] = $shipping_price;
         $shipping_tax = $mp->shipping_tax_price($shipping_price) - $shipping_price;
         $counter += 1;
         $totals[] = $shipping_price;
     }
     //tax line
     if (!$mp->get_setting('tax->tax_inclusive')) {
         $tax_price = round($mp->tax_price(false) + $shipping_tax, 2);
         $prefix = 'li_' . $counter;
         $params["{$prefix}_product_id"] = 'taxes';
         $params["{$prefix}_name"] = 'Taxes';
         $params["{$prefix}_type"] = 'tax';
         $params["{$prefix}_price"] = $tax_price;
         $counter += 1;
         $totals[] = $tax_price;
     }
     $params['total'] = array_sum($totals);
     $url .= '?' . http_build_query($params);
     wp_redirect($url);
     die;
 }
示例#12
0
 /**
  * Use this to do the final payment. Create the order then process the payment. If
  *  you know the payment is successful right away go ahead and change the order status
  *  as well.
  *  Call $mp->cart_checkout_error($msg, $context); to handle errors. If no errors
  *  it will redirect to the next step.
  *
  * @param array $cart. Contains the cart contents for the current blog, global cart if $mp->global_cart is true
  * @param array $shipping_info. Contains shipping info and email in case you need it
  */
 function process_payment($cart, $shipping_info)
 {
     global $mp;
     $settings = get_option('mp_settings');
     //make sure token is set at this point
     if (!isset($_SESSION['paymillToken'])) {
         $mp->cart_checkout_error(__('The Paymill Token was not generated correctly. Please go back and try again.', 'mp'));
         return false;
     }
     define('PAYMILL_API_HOST', 'https://api.paymill.com/v2/');
     define('PAYMILL_API_KEY', $settings['gateways']['paymill']['private_key']);
     $token = $_SESSION['paymillToken'];
     if ($token) {
         require "paymill-files/lib/Services/Paymill/Transactions.php";
         $transactionsObject = new Services_Paymill_Transactions(PAYMILL_API_KEY, PAYMILL_API_HOST);
         $totals = array();
         $coupon_code = $mp->get_coupon_code();
         foreach ($cart as $product_id => $variations) {
             foreach ($variations as $variation => $data) {
                 $price = $mp->coupon_value_product($coupon_code, $data['price'] * $data['quantity'], $product_id);
                 $totals[] = $price;
             }
         }
         $total = array_sum($totals);
         //shipping line
         if ($shipping_price = $mp->shipping_price()) {
             $total += $shipping_price;
         }
         //tax line
         if ($tax_price = $mp->tax_price()) {
             $total += $tax_price;
         }
         $order_id = $mp->generate_order_id();
         try {
             $params = array('amount' => $total * 100, 'currency' => strtolower($this->currency), 'token' => $token, 'description' => sprintf(__('%s Store Purchase - Order ID: %s, Email: %s', 'mp'), get_bloginfo('name'), $order_id, $_SESSION['mp_shipping_info']['email']));
             $charge = $transactionsObject->create($params);
             if ($charge['status'] == 'closed') {
                 //setup our payment details
                 $payment_info = array();
                 $payment_info['gateway_public_name'] = $this->public_name;
                 $payment_info['gateway_private_name'] = $this->admin_name;
                 $payment_info['method'] = sprintf(__('%1$s Card ending in %2$s - Expires %3$s', 'mp'), ucfirst($charge['payment']['card_type']), $charge['payment']['last4'], $charge['payment']['expire_month'] . '/' . $charge['payment']['expire_year']);
                 $payment_info['transaction_id'] = $charge['id'];
                 $timestamp = time();
                 $payment_info['status'][$timestamp] = __('Paid', 'mp');
                 $payment_info['total'] = $total;
                 $payment_info['currency'] = $this->currency;
                 $order = $mp->create_order($order_id, $cart, $_SESSION['mp_shipping_info'], $payment_info, true);
                 unset($_SESSION['paymillToken']);
                 $mp->set_cart_cookie(array());
             }
         } catch (Exception $e) {
             unset($_SESSION['paymillToken']);
             $mp->cart_checkout_error(sprintf(__('There was an error processing your card: "%s". Please <a href="%s">go back and try again</a>.', 'mp'), $e->getMessage(), mp_checkout_step_url('checkout')));
             return false;
         }
     }
 }
示例#13
0
 /**
  * Use this to do the final payment. Create the order then process the payment. If
  *  you know the payment is successful right away go ahead and change the order status
  *  as well.
  *  Call $mp->cart_checkout_error($msg, $context); to handle errors. If no errors
  *  it will redirect to the next step.
  *
  * @param array $cart. Contains the cart contents for the current blog, global cart if $mp->global_cart is true
  * @param array $shipping_info. Contains shipping info and email in case you need it
  */
 function process_payment($cart, $shipping_info)
 {
     global $mp;
     $settings = get_option('mp_settings');
     $timestamp = time();
     $totals = array();
     foreach ($cart as $product_id => $variations) {
         foreach ($variations as $data) {
             $totals[] = $mp->before_tax_price($data['price'], $product_id) * $data['quantity'];
         }
     }
     $total = array_sum($totals);
     if ($coupon = $mp->coupon_value($mp->get_coupon_code(), $total)) {
         $total = $coupon['new_total'];
     }
     //shipping line
     if (($shipping_price = $mp->shipping_price()) !== false) {
         $total = $total + $shipping_price;
     }
     //tax line
     if (($tax_price = $mp->tax_price()) !== false) {
         $total = $total + $tax_price;
     }
     //get CubePoints user
     $uid = cp_currentUser();
     //test for CubePoints amount
     if (cp_getPoints(cp_currentUser()) >= $total) {
         //subtract $total from user's CubePoints
         cp_points('custom', $uid, -$total, sprintf(__('%s Store Purchase', 'mp'), get_bloginfo('name')));
         //create MarketPress order
         $order_id = $mp->generate_order_id();
         $payment_info['gateway_public_name'] = $this->public_name;
         $payment_info['gateway_private_name'] = $this->admin_name;
         $payment_info['status'][$timestamp] = __("Paid", 'mp');
         $payment_info['total'] = $total;
         $payment_info['currency'] = $settings['currency'];
         $payment_info['method'] = __('CubePoints', 'mp');
         $payment_info['transaction_id'] = $order_id;
         $paid = true;
         //create our order now
         $result = $mp->create_order($order_id, $cart, $shipping_info, $payment_info, $paid);
     } else {
         //insuffient CubePoints
         $mp->cart_checkout_error(sprintf(__('Sorry, but you do not appear to have enough points to complete this purchase!', 'mp'), mp_checkout_step_url('checkout')));
     }
 }
示例#14
0
function _flexmarket_cart_shipping($editable = false, $echo = false, $btnclass = '')
{
    global $mp, $current_user;
    $meta = get_user_meta($current_user->ID, 'mp_shipping_info', true);
    //get address
    $email = !empty($_SESSION['mp_shipping_info']['email']) ? $_SESSION['mp_shipping_info']['email'] : (isset($meta['email']) ? $meta['email'] : $current_user->user_email);
    $name = !empty($_SESSION['mp_shipping_info']['name']) ? $_SESSION['mp_shipping_info']['name'] : (isset($meta['name']) ? $meta['name'] : $current_user->user_firstname . ' ' . $current_user->user_lastname);
    $address1 = !empty($_SESSION['mp_shipping_info']['address1']) ? $_SESSION['mp_shipping_info']['address1'] : $meta['address1'];
    $address2 = !empty($_SESSION['mp_shipping_info']['address2']) ? $_SESSION['mp_shipping_info']['address2'] : $meta['address2'];
    $city = !empty($_SESSION['mp_shipping_info']['city']) ? $_SESSION['mp_shipping_info']['city'] : $meta['city'];
    $state = !empty($_SESSION['mp_shipping_info']['state']) ? $_SESSION['mp_shipping_info']['state'] : $meta['state'];
    $zip = !empty($_SESSION['mp_shipping_info']['zip']) ? $_SESSION['mp_shipping_info']['zip'] : $meta['zip'];
    $country = !empty($_SESSION['mp_shipping_info']['country']) ? $_SESSION['mp_shipping_info']['country'] : $meta['country'];
    if (!$country) {
        $country = $mp->get_setting('base_country', 'US');
    }
    $phone = !empty($_SESSION['mp_shipping_info']['phone']) ? $_SESSION['mp_shipping_info']['phone'] : $meta['phone'];
    $special_instructions = !empty($_SESSION['mp_shipping_info']['special_instructions']) ? $_SESSION['mp_shipping_info']['special_instructions'] : '';
    $content = '';
    //don't show if logged in
    if (!is_user_logged_in() && !defined('MP_HIDE_LOGIN_OPTION') && $editable) {
        $content .= '<p class="mp_cart_login_msg alert alert-info">';
        $content .= '<strong>' . __('Made a purchase here before?', 'mp') . '</strong>  <a class="mp_cart_login_link btn btn-mini' . $btnclass . '" href="' . wp_login_url(mp_checkout_step_url('shipping')) . '">' . __('Login now', 'mp') . '</a> ' . __('to retrieve your saved info!', 'mp');
        $content .= '</p>';
    }
    if ($editable) {
        $content .= '<form id="mp_shipping_form" method="post" action="">';
        $content .= apply_filters('mp_checkout_before_shipping', '');
        $content .= '<table class="mp_cart_shipping table table-striped table-bordered table-hover">';
        $content .= '<thead><tr>';
        $content .= '<th colspan="2">' . ($mp->download_only_cart($mp->get_cart_contents() && !$mp->global_cart) ? __('Enter Your Checkout Information:', 'mp') : __('Enter Your Shipping Information:', 'mp')) . '</th>';
        $content .= '</tr></thead>';
        $content .= '<tbody>';
        $content .= '<tr>';
        $content .= '<td class="span4 align-right" align="right">' . __('Email:', 'mp') . '*</td><td>';
        $content .= apply_filters('mp_checkout_error_email', '');
        $content .= '<input size="35" name="email" type="text" value="' . esc_attr($email) . '" /></td>';
        $content .= '</tr>';
        if ((!$mp->download_only_cart($mp->get_cart_contents()) || $mp->global_cart) && $mp->get_setting('shipping->method') != 'none') {
            $content .= '<tr>';
            $content .= '<td class="span4 align-right" align="right">' . __('Full Name:', 'mp') . '*</td><td>';
            $content .= apply_filters('mp_checkout_error_name', '');
            $content .= '<input size="35" name="name" type="text" value="' . esc_attr($name) . '" /> </td>';
            $content .= '</tr>';
            $content .= '<tr>';
            $content .= '<td class="span4 align-right" align="right">' . __('Country:', 'mp') . '*</td><td>';
            $content .= apply_filters('mp_checkout_error_country', '');
            $content .= '<select id="mp_country" name="country" class="mp_shipping_field">';
            foreach ($mp->get_setting('shipping->allowed_countries', array()) as $code) {
                $content .= '<option value="' . $code . '"' . selected($country, $code, false) . '>' . esc_attr($mp->countries[$code]) . '</option>';
            }
            $content .= '</select>';
            $content .= '</td>';
            $content .= '</tr>';
            $content .= '<tr>';
            $content .= '<td class="span4 align-right" align="right">' . __('Address:', 'mp') . '*</td><td>';
            $content .= apply_filters('mp_checkout_error_address1', '');
            $content .= '<input class="input-xlarge" name="address1" type="text" value="' . esc_attr($address1) . '" /><br />';
            $content .= '<small><em>' . __('Street address, P.O. box, company name, c/o', 'mp') . '</em></small>';
            $content .= '</td>';
            $content .= '</tr>';
            $content .= '<tr>';
            $content .= '<td class="span4 align-right" align="right">' . __('Address 2:', 'mp') . '&nbsp;</td><td>';
            $content .= '<input class="input-xlarge" name="address2" type="text" value="' . esc_attr($address2) . '" /><br />';
            $content .= '<small><em>' . __('Apartment, suite, unit, building, floor, etc.', 'mp') . '</em></small>';
            $content .= '</td>';
            $content .= '</tr>';
            $content .= '<tr>';
            $content .= '<td class="span4 align-right" align="right">' . __('City:', 'mp') . '*</td><td>';
            $content .= apply_filters('mp_checkout_error_city', '');
            $content .= '<input class="input-xlarge mp_shipping_field" id="mp_city" name="city" type="text" value="' . esc_attr($city) . '" /></td>';
            $content .= '</tr>';
            $content .= '<tr>';
            $content .= '<td class="span4 align-right" align="right">' . __('State/Province/Region:', 'mp') . ($country == 'US' || $country == 'CA' ? '*' : '') . '</td><td id="mp_province_field">';
            $content .= apply_filters('mp_checkout_error_state', '');
            $content .= mp_province_field($country, $state) . '</td>';
            $content .= '</tr>';
            $content .= '<tr>';
            $content .= '<td class="span4 align-right" align="right">' . __('Postal/Zip Code:', 'mp') . '*</td><td>';
            $content .= apply_filters('mp_checkout_error_zip', '');
            $content .= '<input size="10" class="mp_shipping_field" id="mp_zip" name="zip" type="text" value="' . esc_attr($zip) . '" /></td>';
            $content .= '</tr>';
            $content .= '<tr>';
            $content .= '<td class="span4 align-right" align="right">' . __('Phone Number:', 'mp') . '</td><td>';
            $content .= '<input size="20" name="phone" type="text" value="' . esc_attr($phone) . '" /></td>';
            $content .= '</tr>';
        }
        if ($mp->get_setting('special_instructions')) {
            $content .= '<tr>';
            $content .= '<td class="span4 align-right" align="right">' . __('Special Instructions:', 'mp') . '</td><td>';
            $content .= '<textarea name="special_instructions" rows="3" style="width: 98%;">' . esc_textarea($special_instructions) . '</textarea></td>';
            $content .= '</tr>';
        }
        $content .= apply_filters('mp_checkout_shipping_field', '');
        $content .= '</tbody>';
        $content .= '</table>';
        $content .= apply_filters('mp_checkout_after_shipping', '');
        $content .= '<div class="clear padding10"></div>';
        $content .= '<p class="mp_cart_direct_checkout align-right">';
        $content .= '<input type="submit" class="btn btn-large' . $btnclass . '" name="mp_shipping_submit" id="mp_shipping_submit" value="' . __('Continue Checkout &raquo;', 'mp') . '" />';
        $content .= '</p>';
        $content .= '</form>';
    } else {
        if (!$mp->download_only_cart($mp->get_cart_contents())) {
            //is not editable and not download only
            $content .= '<table class="mp_cart_shipping table table-striped table-bordered table-hover">';
            $content .= '<thead><tr>';
            $content .= '<th>' . __('Shipping Information:', 'mp') . '</th>';
            $content .= '<th class="align-right" align="right"><a href="' . mp_checkout_step_url('shipping') . '">' . __('Edit', 'mp') . '</a></th>';
            $content .= '</tr></thead>';
            $content .= '<tbody>';
            $content .= '<tr>';
            $content .= '<td class="span4 align-right" align="right">' . __('Email:', 'mp') . '</td><td>';
            $content .= esc_attr($email) . ' </td>';
            $content .= '</tr>';
            $content .= '<tr>';
            $content .= '<td class="span4 align-right" align="right">' . __('Full Name:', 'mp') . '</td><td>';
            $content .= esc_attr($name) . '</td>';
            $content .= '</tr>';
            $content .= '<tr>';
            $content .= '<td class="span4 align-right" align="right">' . __('Address:', 'mp') . '</td>';
            $content .= '<td>' . esc_attr($address1) . '</td>';
            $content .= '</tr>';
            if ($address2) {
                $content .= '<tr>';
                $content .= '<td class="span4 align-right" align="right">' . __('Address 2:', 'mp') . '</td>';
                $content .= '<td>' . esc_attr($address2) . '</td>';
                $content .= '</tr>';
            }
            $content .= '<tr>';
            $content .= '<td class="span4 align-right" align="right">' . __('City:', 'mp') . '</td>';
            $content .= '<td>' . esc_attr($city) . '</td>';
            $content .= '</tr>';
            if ($state) {
                $content .= '<tr>';
                $content .= '<td class="span4 align-right" align="right">' . __('State/Province/Region:', 'mp') . '</td>';
                $content .= '<td>' . esc_attr($state) . '</td>';
                $content .= '</tr>';
            }
            $content .= '<tr>';
            $content .= '<td class="span4 align-right" align="right">' . __('Postal/Zip Code:', 'mp') . '</td>';
            $content .= '<td>' . esc_attr($zip) . '</td>';
            $content .= '</tr>';
            $content .= '<tr>';
            $content .= '<td class="span4 align-right" align="right">' . __('Country:', 'mp') . '</td>';
            $content .= '<td>' . $mp->countries[$country] . '</td>';
            $content .= '</tr>';
            if ($phone) {
                $content .= '<tr>';
                $content .= '<td class="span4 align-right" align="right">' . __('Phone Number:', 'mp') . '</td>';
                $content .= '<td>' . esc_attr($phone) . '</td>';
                $content .= '</tr>';
            }
            $content .= apply_filters('mp_checkout_shipping_field_readonly', '');
            $content .= '</tbody>';
            $content .= '</table>';
        }
    }
    if ($echo) {
        echo $content;
    } else {
        return $content;
    }
}
示例#15
0
 /**
  * Return any html you want to show on the confirmation screen after checkout. This
  *	should be a payment details box and message.
  *
  * Don't forget to return!
  */
 function order_confirmation_msg($content, $order)
 {
     global $mp;
     $content = '';
     if (!$order) {
         return '<p><a href="' . mp_checkout_step_url('confirm-checkout') . '">' . __('Please go back and try again.', 'mp') . '</a></p>';
     }
     if ($order->post_status == 'order_received') {
         $content .= '<p>' . sprintf(__('Your payment via eWay for this order totaling %s is in progress. Here is the latest status:', 'mp'), $mp->format_currency($order->mp_payment_info['currency'], $order->mp_payment_info['total'])) . '</p>';
         $statuses = $order->mp_payment_info['status'];
         krsort($statuses);
         //sort with latest status at the top
         $status = reset($statuses);
         $timestamp = key($statuses);
         $content .= '<p><strong>' . $mp->format_date($timestamp) . ':</strong> ' . esc_html($status) . '</p>';
     } else {
         $content .= '<p>' . sprintf(__('Your payment for this order totaling %s is complete. The transaction number is <strong>%s</strong>.', 'mp'), $mp->format_currency($order->mp_payment_info['currency'], $order->mp_payment_info['total']), $order->mp_payment_info['transaction_id']) . '</p>';
     }
     return $content;
 }
示例#16
0
 /**
  * Use this to do the final payment. Create the order then process the payment. If
  *  you know the payment is successful right away go ahead and change the order status
  *  as well.
  *  Call $mp->cart_checkout_error($msg, $context); to handle errors. If no errors
  *  it will redirect to the next step.
  *
  * @param array $cart. Contains the cart contents for the current blog, global cart if $mp->global_cart is true
  * @param array $shipping_info. Contains shipping info and email in case you need it
  */
 function process_payment($cart, $shipping_info)
 {
     global $mp;
     $settings = get_option('mp_settings');
     //make sure token is set at this point
     if (!isset($_SESSION['payment_method_id'])) {
         $mp->cart_checkout_error(__('The WePay Card Token was not generated correctly. Please go back and try again.', 'mp'));
         return false;
     }
     $order_id = $mp->generate_order_id();
     //Get the WePay SDK
     require $mp->plugin_dir . 'plugins-gateway/wepay-files/wepay-sdk.php';
     $totals = array();
     $coupon_code = $mp->get_coupon_code();
     foreach ($cart as $product_id => $variations) {
         foreach ($variations as $variation => $data) {
             $price = $mp->coupon_value_product($coupon_code, $data['price'] * $data['quantity'], $product_id);
             $totals[] = $price;
         }
     }
     $total = array_sum($totals);
     //shipping line
     if ($shipping_price = $mp->shipping_price()) {
         $total += $shipping_price;
     }
     //tax line
     if ($tax_price = $mp->tax_price()) {
         $total += $tax_price;
     }
     try {
         // Application settings
         $account_id = $this->account_id;
         $client_id = $this->client_id;
         $client_secret = $this->client_secret;
         $access_token = $this->access_token;
         // Credit card id to charge
         $credit_card_id = $_SESSION['payment_method_id'];
         if ($this->mode == 'staging') {
             WePay::useStaging($this->client_id, $this->client_secret);
         } else {
             WePay::useProduction($this->client_id, $this->client_secret);
         }
         $wepay = new WePay($access_token);
         // charge the credit card
         $response = $wepay->request('checkout/create', array('account_id' => $account_id, 'amount' => number_format($total, 2, '.', ''), 'currency' => 'USD', 'short_description' => $order_id, 'type' => $this->checkout_type, 'payment_method_id' => $credit_card_id, 'payment_method_type' => 'credit_card'));
         if (isset($response->state) && $response->state == 'authorized') {
             $credit_card_response = $wepay->request('/credit_card', array('client_id' => $this->client_id, 'client_secret' => $this->client_secret, 'credit_card_id' => $_SESSION['payment_method_id']));
             //setup our payment details
             $payment_info = array();
             $payment_info['gateway_public_name'] = $this->public_name;
             $payment_info['gateway_private_name'] = $this->admin_name;
             $payment_info['method'] = sprintf(__('%1$s', 'mp'), $credit_card_response->credit_card_name);
             $payment_info['transaction_id'] = $order_id;
             $timestamp = time();
             $payment_info['status'][$timestamp] = __('Paid', 'mp');
             $payment_info['total'] = $total;
             $payment_info['currency'] = $this->currency;
             $order = $mp->create_order($order_id, $cart, $_SESSION['mp_shipping_info'], $payment_info, true);
             unset($_SESSION['payment_method_id']);
             $mp->set_cart_cookie(array());
         }
     } catch (Exception $e) {
         unset($_SESSION['payment_method_id']);
         $mp->cart_checkout_error(sprintf(__('There was an error processing your card: "%s". Please <a href="%s">go back and try again</a>.', 'mp'), $e->getMessage(), mp_checkout_step_url('checkout')));
         return false;
     }
 }
示例#17
0
 /**
  * Use this to do the final payment. Create the order then process the payment. If
  * you know the payment is successful right away go ahead and change the order status
  * as well.
  * Call $mp->cart_checkout_error($msg, $context); to handle errors. If no errors
  * it will redirect to the next step.
  *
  * @param array $cart. Contains the cart contents for the current blog, global cart if $mp->global_cart is true
  * @param array $shipping_info. Contains shipping info and email in case you need it
  * @since 1.1
  * @version 1.2.1
  */
 function process_payment($cart, $shipping_info)
 {
     global $mp;
     $settings = get_option('mp_settings');
     $user_id = get_current_user_id();
     $insolvent = $this->mycred->template_tags_user($settings['gateways']['mycred']['lowfunds'], false, wp_get_current_user());
     $timestamp = time();
     // This gateway requires buyer to be logged in
     if (!is_user_logged_in()) {
         $message = str_replace('%login_url_here%', wp_login_url(mp_checkout_step_url('checkout')), $settings['gateways']['mycred']['visitors']);
         $mp->cart_checkout_error($this->mycred->template_tags_general($message));
     }
     // Make sure current user is not excluded from using myCRED
     if ($this->mycred->exclude_user($user_id)) {
         $mp->cart_checkout_error(sprintf(__('Sorry, but you can not use this gateway as your account is excluded. Please <a href="%s">select a different payment method</a>.', 'mycred'), mp_checkout_step_url('checkout')));
     }
     // Get users balance
     $balance = $this->mycred->get_users_cred($user_id, $this->mycred_type);
     $total = $this->get_cart_total($cart);
     // Low balance or Insolvent
     if ($balance <= $this->mycred->zero() || $balance - $total < $this->mycred->zero()) {
         $mp->cart_checkout_error($insolvent . ' <a href="' . mp_checkout_step_url('checkout') . '">' . __('Go Back', 'mycred') . '</a>');
         return;
     }
     // Let others decline a store order
     $decline = apply_filters('mycred_decline_store_purchase', false, $cart, $this);
     if ($decline !== false) {
         $mp->cart_checkout_error($decline);
         return;
     }
     // Create MarketPress order
     $order_id = $mp->generate_order_id();
     $payment_info['gateway_public_name'] = $this->public_name;
     $payment_info['gateway_private_name'] = $this->admin_name;
     $payment_info['status'][$timestamp] = __('Paid', 'mycred');
     $payment_info['total'] = $total;
     $payment_info['currency'] = $settings['currency'];
     $payment_info['method'] = __('myCRED', 'mycred');
     $payment_info['transaction_id'] = $order_id;
     $paid = true;
     $result = $mp->create_order($order_id, $cart, $shipping_info, $payment_info, $paid);
     $order = get_page_by_title($result, 'OBJECT', 'mp_order');
     // Deduct cost
     $this->mycred->add_creds('marketpress_payment', $user_id, 0 - $total, $settings['gateways']['mycred']['log_template'], $order->ID, array('ref_type' => 'post'), $this->mycred_type);
     // Profit Sharing
     if ($settings['gateways']['mycred']['profit_share_percent'] > 0) {
         foreach ($cart as $product_id => $variations) {
             // Get Product
             $product = get_post((int) $product_id);
             // Continue if product has just been deleted or owner is buyer
             if ($product === NULL || $product->post_author == $cui) {
                 continue;
             }
             foreach ($variations as $data) {
                 $price = $data['price'];
                 $quantity = $data['quantity'];
                 $cost = $price * $quantity;
                 // Calculate Share
                 $share = $settings['gateways']['mycred']['profit_share_percent'] / 100 * $cost;
                 // Payout
                 $this->mycred->add_creds('store_sale', $product->post_author, $share, $settings['gateways']['mycred']['profit_share_log'], $product->ID, array('ref_type' => 'post'), $this->mycred_type);
             }
         }
     }
 }
示例#18
0
 /**
  * Use this to do the final payment. Create the order then process the payment. If
  *	you know the payment is successful right away go ahead and change the order status
  *	as well.
  *	Call $mp->cart_checkout_error($msg, $context); to handle errors. If no errors
  *	it will redirect to the next step.
  *
  * @param array $cart. Contains the cart contents for the current blog, global cart if $mp->global_cart is true
  * @param array $shipping_info. Contains shipping info and email in case you need it
  */
 function process_payment($cart, $shipping_info)
 {
     global $mp;
     $settings = get_option('mp_settings');
     //make sure token is set at this point
     if (!isset($_SESSION['stripeToken'])) {
         $mp->cart_checkout_error(__('The Stripe Token was not generated correctly. Please go back and try again.', 'mp'));
         return false;
     }
     //setup the Stripe API
     if (!class_exists('Stripe')) {
         require_once $mp->plugin_dir . "plugins-gateway/stripe-files/lib/Stripe.php";
     }
     Stripe::setApiKey($this->private_key);
     $totals = array();
     $coupon_code = $mp->get_coupon_code();
     foreach ($cart as $product_id => $variations) {
         foreach ($variations as $variation => $data) {
             $price = $mp->coupon_value_product($coupon_code, $data['price'] * $data['quantity'], $product_id);
             $totals[] = $price;
         }
     }
     $total = array_sum($totals);
     //shipping line
     $shipping_tax = 0;
     if (($shipping_price = $mp->shipping_price(false)) !== false) {
         $total += $shipping_price;
         $shipping_tax = $mp->shipping_tax_price($shipping_price) - $shipping_price;
     }
     //tax line if tax inclusive pricing is off. It it's on it would screw up the totals
     if (!$mp->get_setting('tax->tax_inclusive')) {
         $tax_price = $mp->tax_price(false) + $shipping_tax;
         $total += $tax_price;
     }
     $order_id = $mp->generate_order_id();
     try {
         // create the charge on Stripe's servers - this will charge the user's card
         $charge = Stripe_Charge::create(array("amount" => round($total * 100), "currency" => strtolower($this->currency), "card" => $_SESSION['stripeToken'], "description" => sprintf(__('%s Store Purchase - Order ID: %s, Email: %s', 'mp'), get_bloginfo('name'), $order_id, $_SESSION['mp_shipping_info']['email'])));
         if ($charge->paid == 'true') {
             //setup our payment details
             $payment_info = array();
             $payment_info['gateway_public_name'] = $this->public_name;
             $payment_info['gateway_private_name'] = $this->admin_name;
             $payment_info['method'] = sprintf(__('%1$s Card ending in %2$s - Expires %3$s', 'mp'), $charge->card->type, $charge->card->last4, $charge->card->exp_month . '/' . $charge->card->exp_year);
             $payment_info['transaction_id'] = $charge->id;
             $timestamp = time();
             $payment_info['status'][$timestamp] = __('Paid', 'mp');
             $payment_info['total'] = $total;
             $payment_info['currency'] = $this->currency;
             $order = $mp->create_order($order_id, $cart, $_SESSION['mp_shipping_info'], $payment_info, true);
             unset($_SESSION['stripeToken']);
             $mp->set_cart_cookie(array());
         }
     } catch (Exception $e) {
         unset($_SESSION['stripeToken']);
         $mp->cart_checkout_error(sprintf(__('There was an error processing your card: "%s". Please <a href="%s">go back and try again</a>.', 'mp'), $e->getMessage(), mp_checkout_step_url('checkout')));
         return false;
     }
 }
 /**
  * Runs before page load incase you need to run any scripts before loading the success message page
  */
 function order_confirmation($order)
 {
     global $mp;
     //check if created already by IPN
     if (!$order) {
         $result = $this->PaymentDetails($_SESSION['PAYKEY']);
         if ($result["responseEnvelope_ack"] == "Success" || $result["responseEnvelope_ack"] == "SuccessWithWarning") {
             //setup our payment details
             $payment_info['gateway_public_name'] = $this->public_name;
             $payment_info['gateway_private_name'] = $this->admin_name;
             $payment_info['method'] = __('PayPal balance, Credit Card, or Instant Transfer', 'mp');
             $payment_info['transaction_id'] = $result["paymentInfoList_paymentInfo(0)_transactionId"];
             $timestamp = time();
             $order_id = $result["trackingId"];
             //setup status
             switch ($result["paymentInfoList_paymentInfo(0)_transactionStatus"]) {
                 case 'PARTIALLY_REFUNDED':
                     $status = __('The payment has been partially refunded.', 'mp');
                     $create_order = true;
                     $paid = true;
                     break;
                 case 'COMPLETED':
                     $status = __('The payment has been completed, and the funds have been added successfully to your account balance.', 'mp');
                     $create_order = true;
                     $paid = true;
                     break;
                 case 'PROCESSING':
                     $status = __('The transaction is in progress.', 'mp');
                     $create_order = true;
                     $paid = true;
                     break;
                 case 'REVERSED':
                     $status = __('You refunded the payment.', 'mp');
                     $create_order = false;
                     $paid = false;
                     break;
                 case 'DENIED':
                     $status = __('The transaction was rejected by the receiver (you).', 'mp');
                     $create_order = false;
                     $paid = false;
                     break;
                 case 'PENDING':
                     $pending_str = array('ADDRESS_CONFIRMATION' => __('The payment is pending because your customer did not include a confirmed shipping address and your Payment Receiving Preferences is set such that you want to manually accept or deny each of these payments. To change your preference, go to the Preferences section of your Profile.', 'mp'), 'ECHECK' => __('The payment is pending because it was made by an eCheck that has not yet cleared.', 'mp'), 'INTERNATIONAL' => __('The payment is pending because you hold a non-U.S. account and do not have a withdrawal mechanism. You must manually accept or deny this payment from your Account Overview.', 'mp'), 'MULTI_CURRENCY' => __('You do not have a balance in the currency sent, and you do not have your Payment Receiving Preferences set to automatically convert and accept this payment. You must manually accept or deny this payment.', 'mp'), 'RISK' => __('The payment is pending while it is being reviewed by PayPal for risk.', 'mp'), 'UNILATERAL' => __('The payment is pending because it was made to an email address that is not yet registered or confirmed.', 'mp'), 'UPGRADE' => __('The payment is pending because it was made via credit card and you must upgrade your account to Business or Premier status in order to receive the funds. It can also mean that you have reached the monthly limit for transactions on your account.', 'mp'), 'VERIFY' => __('The payment is pending because you are not yet verified. You must verify your account before you can accept this payment.', 'mp'), 'OTHER' => __('The payment is pending for an unknown reason. For more information, contact PayPal customer service.', 'mp'));
                     $status = __('The payment is pending.', 'mp');
                     $status .= '<br />' . $pending_str[$result["paymentInfoList_paymentInfo(0)_pendingReason"]];
                     $create_order = true;
                     $paid = false;
                     break;
                 default:
                     // case: various error cases
                     $create_order = false;
                     $paid = false;
             }
             $status = $result["paymentInfoList_paymentInfo(0)_transactionStatus"] . ': ' . $status;
             //status's are stored as an array with unix timestamp as key
             $payment_info['status'][$timestamp] = $status;
             $payment_info['total'] = $result["paymentInfoList_paymentInfo(0)_receiver_amount"];
             $payment_info['currency'] = $result["currencyCode"];
             //succesful payment, create our order now
             if ($create_order) {
                 $cart = get_transient('mp_order_' . $order_id . '_cart');
                 $shipping_info = get_transient('mp_order_' . $order_id . '_shipping');
                 $order_id = $mp->create_order($result["trackingId"], $cart, $shipping_info, $payment_info, $paid);
                 delete_transient('mp_order_' . $order_id . '_cart');
                 delete_transient('mp_order_' . $order_id . '_shipping');
                 delete_transient('mp_order_' . $order_id . '_shipping_total');
                 delete_transient('mp_order_' . $order_id . '_tax_total');
                 delete_transient('mp_order_' . $order_id . '_userid');
                 delete_transient('mp_order_' . $order_id . '_coupon');
             } else {
                 $mp->cart_checkout_error(sprintf(__('Sorry, your order was not completed. Please <a href="%s">go back and try again</a>.', 'mp'), mp_checkout_step_url('checkout')));
                 return;
             }
         } else {
             //whoops, error
             for ($i = 0; $i <= 5; $i++) {
                 //print the first 5 errors
                 if (isset($result["error({$i})_message"])) {
                     $error .= "<li>{$result["error({$i})_errorId"]} - {$result["error({$i})_message"]}</li>";
                 }
             }
             $error = '<br /><ul>' . $error . '</ul>';
             $mp->cart_checkout_error(sprintf(__('There was a problem connecting to PayPal to check the status of your purchase. Please <a href="%s">check the status of your order here &raquo;</a>', 'mp') . $error, mp_orderstatus_link(false, true)));
             return;
         }
     } else {
         $mp->set_cart_cookie(array());
     }
 }
示例#20
0
 /**
  * Use this to do the final payment. Create the order then process the payment. If
  *  you know the payment is successful right away go ahead and change the order status
  *  as well.
  *  Call $mp->cart_checkout_error($msg, $context); to handle errors. If no errors
  *  it will redirect to the next step.
  *
  * @param array $cart. Contains the cart contents for the current blog, global cart if $mp->global_cart is true
  * @param array $shipping_info. Contains shipping info and email in case you need it
  */
 function process_payment($cart, $shipping_info)
 {
     global $mp;
     $timestamp = time();
     $settings = get_option('mp_settings');
     $billing_info = $_SESSION['mp_billing_info'];
     $payment = new MP_Gateway_Worker_Payflow($this->API_Endpoint, $settings['gateways']['payflow']['delim_data'], $settings['gateways']['payflow']['delim_char'], $settings['gateways']['payflow']['encap_char'], $settings['gateways']['payflow']['api_user'], $settings['gateways']['payflow']['api_key'], $settings['gateways']['payflow']['mode'] == 'sandbox');
     $payment->transaction($_SESSION['card_num']);
     $payment->setParameter("EXPDATE", $_SESSION['exp_month'] . substr($_SESSION['exp_year'], 2, 2));
     $payment->setParameter("CVV2", $_SESSION['card_code']);
     $payment->setParameter("USER", $settings['gateways']['payflow']['api_user']);
     $payment->setParameter("VENDOR", $settings['gateways']['payflow']['api_vendor']);
     $payment->setParameter("PWD", $settings['gateways']['payflow']['api_pwd']);
     $payment->setParameter("PARTNER", $settings['gateways']['payflow']['api_partner']);
     $totals = array();
     foreach ($cart as $product_id => $variations) {
         foreach ($variations as $variation => $data) {
             $totals[] = $mp->before_tax_price($data['price'], $product_id) * $data['quantity'];
             $i++;
         }
     }
     $total = array_sum($totals);
     //coupon line
     if ($coupon = $mp->coupon_value($mp->get_coupon_code(), $total)) {
         $total = $coupon['new_total'];
     }
     //shipping line
     if (($shipping_price = $mp->shipping_price()) !== false) {
         $total = $total + $shipping_price;
     }
     //tax line
     if (($tax_price = $mp->tax_price()) !== false) {
         $total = $total + $tax_price;
     }
     // Billing Info
     $payment->setParameter("TENDER", 'C');
     $payment->setParameter("TRXTYPE", 'S');
     $payment->setParameter("AMT", number_format($total, 2, '.', ''));
     $payment->setParameter("CURRENCY", $this->currencyCode);
     // Order Info
     $payment->setParameter("COMMENT1", "Order ID: " . $_SESSION['mp_order']);
     $payment->setParameter("INVNUM", $_SESSION['mp_order']);
     // E-mail
     $_names = split(" ", $billing_info['name']);
     if (isset($_names[0])) {
         $first_name = array_shift($_names);
     } else {
         $first_name = "";
     }
     if (isset($_names[0])) {
         $last_name = join(" ", $_names);
     } else {
         $last_name = "";
     }
     $address = $billing_info['address1'];
     if (!empty($billing_info['address2'])) {
         $address .= "\n" . $billing_info['address2'];
     }
     //Customer Info
     $payment->setParameter("FIRSTNAME", $first_name);
     $payment->setParameter("LASTNAME", $last_name);
     $payment->setParameter("STREET", $address);
     $payment->setParameter("CITY", $billing_info['city']);
     $payment->setParameter("STATE", $billing_info['state']);
     $payment->setParameter("COUNTRY", $billing_info['country']);
     $payment->setParameter("ZIP", $billing_info['zip']);
     $payment->setParameter("EMAIL", $billing_info['email']);
     $_ship_names = split(" ", $shipping_info['name']);
     if (isset($_ship_names[0])) {
         $first_name_shipping = array_shift($_ship_names);
     } else {
         $first_name_shipping = "";
     }
     if (isset($_ship_names[0])) {
         $last_name_shipping = join(" ", $_ship_names);
     } else {
         $last_name_shipping = "";
     }
     $ship_address = $shipping_info['address1'];
     if (!empty($shipping_info['address2'])) {
         $ship_address .= "\n" . $shipping_info['address2'];
     }
     $payment->setParameter("SHIPTOFIRSTNAME", $first_name_shipping);
     $payment->setParameter("SHIPTOLASTNAME", $last_name_shipping);
     $payment->setParameter("SHIPTOCITY", $shipping_info["city"]);
     $payment->setParameter("SHIPTOSTATE", $shipping_info["state"]);
     $payment->setParameter("SHIPTOCOUNTRY", $shipping_info["country"]);
     $payment->setParameter("SHIPTOZIP", $shipping_info["zip"]);
     $payment->setParameter("SHIPTOSTREET", $ship_address);
     $payment->setParameter("CLIENTIP", $_SERVER['REMOTE_ADDR']);
     $payment->process();
     //file_put_contents("pp.txt",serialize($payment));
     if ($payment->isApproved()) {
         $status = __('The payment has been completed, and the funds have been added successfully to your account balance.', 'mp');
         $paid = true;
         $payment_info['gateway_public_name'] = $this->public_name;
         $payment_info['gateway_private_name'] = $this->admin_name;
         $payment_info['method'] = $payment->getMethod();
         $payment_info['status'][$timestamp] = "paid";
         $payment_info['total'] = $total;
         $payment_info['currency'] = "USD";
         // Authorize.net only supports USD transactions
         $payment_info['transaction_id'] = $payment->getTransactionID();
         //succesful payment, create our order now
         $result = $mp->create_order($_SESSION['mp_order'], $cart, $shipping_info, $payment_info, $paid);
     } else {
         $error = $payment->getResponseText();
         $mp->cart_checkout_error(sprintf(__('There was a problem finalizing your purchase. %s Please <a href="%s">go back and try again</a>.', 'mp'), $error, mp_checkout_step_url('checkout')));
     }
 }
示例#21
0
 /**
  * Use this to do the final payment. Create the order then process the payment. If
  *  you know the payment is successful right away go ahead and change the order status
  *  as well.
  *  Call $mp->cart_checkout_error($msg, $context); to handle errors. If no errors
  *  it will redirect to the next step.
  *
  * @param array $cart. Contains the cart contents for the current blog, global cart if $mp->global_cart is true
  * @param array $shipping_info. Contains shipping info and email in case you need it
  */
 function process_payment($cart, $shipping_info)
 {
     global $mp;
     $timestamp = time();
     $settings = get_option('mp_settings');
     $billing_info = $_SESSION['mp_billing_info'];
     $payment = new MP_Gateway_Worker_AuthorizeNet_AIM($this->API_Endpoint, $settings['gateways']['authorizenet-aim']['delim_data'], $settings['gateways']['authorizenet-aim']['delim_char'], $settings['gateways']['authorizenet-aim']['encap_char'], $settings['gateways']['authorizenet-aim']['api_user'], $settings['gateways']['authorizenet-aim']['api_key'], $settings['gateways']['authorizenet-aim']['mode'] == 'sandbox');
     $payment->transaction($_SESSION['card_num']);
     $totals = array();
     foreach ($cart as $product_id => $variations) {
         foreach ($variations as $variation => $data) {
             $sku = empty($data['SKU']) ? "{$product_id}_{$variation}" : $data['SKU'];
             $totals[] = $mp->before_tax_price($data['price'], $product_id) * $data['quantity'];
             $payment->addLineItem($sku, substr($data['name'], 0, 31), substr($data['name'] . ' - ' . $data['url'], 0, 254), $data['quantity'], $mp->before_tax_price($data['price'], $product_id), 1);
             $i++;
         }
     }
     $total = array_sum($totals);
     //coupon line
     if ($coupon = $mp->coupon_value($mp->get_coupon_code(), $total)) {
         $total = $coupon['new_total'];
     }
     //shipping line
     if (($shipping_price = $mp->shipping_price()) !== false) {
         $total = $total + $shipping_price;
     }
     //tax line
     if (($tax_price = $mp->tax_price()) !== false) {
         $total = $total + $tax_price;
     }
     // Billing Info
     $payment->setParameter("x_card_code", $_SESSION['card_code']);
     $payment->setParameter("x_exp_date ", $_SESSION['exp_month'] . $_SESSION['exp_year']);
     $payment->setParameter("x_amount", $total);
     // Order Info
     $payment->setParameter("x_description", "Order ID: " . $_SESSION['mp_order']);
     $payment->setParameter("x_invoice_num", $_SESSION['mp_order']);
     if ($settings['gateways']['authorizenet-aim']['mode'] == 'sandbox') {
         $payment->setParameter("x_test_request", true);
     } else {
         $payment->setParameter("x_test_request", false);
     }
     $payment->setParameter("x_duplicate_window", 30);
     // E-mail
     $payment->setParameter("x_header_email_receipt", $settings['gateways']['authorizenet-aim']['header_email_receipt']);
     $payment->setParameter("x_footer_email_receipt", $settings['gateways']['authorizenet-aim']['footer_email_receipt']);
     $payment->setParameter("x_email_customer", strtoupper($settings['gateways']['authorizenet-aim']['email_customer']));
     $_names = split(" ", $billing_info['name']);
     if (isset($_names[0])) {
         $first_name = array_shift($_names);
     } else {
         $first_name = "";
     }
     if (isset($_names[0])) {
         $last_name = join(" ", $_names);
     } else {
         $last_name = "";
     }
     $address = $billing_info['address1'];
     if (!empty($billing_info['address2'])) {
         $address .= "\n" . $billing_info['address2'];
     }
     //Customer Info
     $payment->setParameter("x_first_name", $first_name);
     $payment->setParameter("x_last_name", $last_name);
     $payment->setParameter("x_address", $address);
     $payment->setParameter("x_city", $billing_info['city']);
     $payment->setParameter("x_state", $billing_info['state']);
     $payment->setParameter("x_country", $billing_info['country']);
     $payment->setParameter("x_zip", $billing_info['zip']);
     $payment->setParameter("x_phone", $billing_info['phone']);
     $payment->setParameter("x_email", $billing_info['email']);
     //only add shipping info if set
     if (!$mp->download_only_cart($cart) && isset($shipping_info['name'])) {
         $_names = split(" ", $shipping_info['name']);
         if (isset($_names[0])) {
             $shipping_first_name = array_shift($_names);
         } else {
             $shipping_first_name = "";
         }
         if (isset($_names[0])) {
             $shipping_last_name = join(" ", $_names);
         } else {
             $shipping_last_name = "";
         }
         $shipping_address = $shipping_info['address1'];
         if (!empty($billing_info['address2'])) {
             $shipping_address .= "\n" . $shipping_info['address2'];
         }
         $payment->setParameter("x_ship_to_first_name", $shipping_first_name);
         $payment->setParameter("x_ship_to_last_name", $shipping_last_name);
         $payment->setParameter("x_ship_to_address", $shipping_address);
         $payment->setParameter("x_ship_to_city", $shipping_info['city']);
         $payment->setParameter("x_ship_to_state", $shipping_info['state']);
         $payment->setParameter("x_ship_to_country", $shipping_info['country']);
         $payment->setParameter("x_ship_to_zip", $shipping_info['zip']);
     }
     $payment->setParameter("x_customer_ip", $_SERVER['REMOTE_ADDR']);
     $payment->process();
     if ($payment->isApproved()) {
         $status = __('The payment has been completed, and the funds have been added successfully to your account balance.', 'mp');
         $paid = true;
         $payment_info['gateway_public_name'] = $this->public_name;
         $payment_info['gateway_private_name'] = $this->admin_name;
         $payment_info['method'] = $payment->getMethod();
         $payment_info['status'][$timestamp] = "paid";
         $payment_info['total'] = $total;
         $payment_info['currency'] = "USD";
         // Authorize.net only supports USD transactions
         $payment_info['transaction_id'] = $payment->getTransactionID();
         //succesful payment, create our order now
         $result = $mp->create_order($_SESSION['mp_order'], $cart, $shipping_info, $payment_info, $paid);
     } else {
         $error = $payment->getResponseText();
         $mp->cart_checkout_error(sprintf(__('There was a problem finalizing your purchase. %s Please <a href="%s">go back and try again</a>.', 'mp'), $error, mp_checkout_step_url('checkout')));
     }
 }
示例#22
0
    function update_cart()
    {
        global $blog_id, $mp_gateway_active_plugins;
        $blog_id = is_multisite() ? $blog_id : 1;
        $current_blog_id = $blog_id;
        $cart = $this->get_cart_cookie();
        if (isset($_POST['empty_cart'])) {
            //empty cart contents
            //clear all blog products only if global checkout enabled
            if ($this->global_cart) {
                $this->set_global_cart_cookie(array());
            } else {
                $this->set_cart_cookie(array());
            }
            if (defined('DOING_AJAX') && DOING_AJAX) {
                ?>
				<div class="mp_cart_empty">
					<?php 
                _e('There are no items in your cart.', 'mp');
                ?>
				</div>
				<div id="mp_cart_actions_widget">
					<a class="mp_store_link" href="<?php 
                mp_products_link(true, true);
                ?>
"><?php 
                _e('Browse Products &raquo;', 'mp');
                ?>
</a>
				</div>
        <?php 
                exit;
            }
        } else {
            if (isset($_POST['product_id'])) {
                //add a product to cart
                //if not valid product_id return
                $product_id = apply_filters('mp_product_id_add_to_cart', intval($_POST['product_id']));
                $product = get_post($product_id);
                if (!$product || $product->post_type != 'product' || $product->post_status != 'publish') {
                    return false;
                }
                //get quantity
                $quantity = isset($_POST['quantity']) ? intval(abs($_POST['quantity'])) : 1;
                //get variation
                $variation = isset($_POST['variation']) ? intval(abs($_POST['variation'])) : 0;
                //check max stores
                if ($this->global_cart && count($global_cart = $this->get_cart_cookie(true)) >= $mp_gateway_active_plugins[0]->max_stores && !isset($global_cart[$blog_id])) {
                    if (defined('DOING_AJAX') && DOING_AJAX) {
                        echo 'error||' . sprintf(__("Sorry, currently it's not possible to checkout with items from more than %s stores.", 'mp'), $mp_gateway_active_plugins[0]->max_stores);
                        exit;
                    } else {
                        $this->cart_checkout_error(sprintf(__("Sorry, currently it's not possible to checkout with items from more than %s stores.", 'mp'), $mp_gateway_active_plugins[0]->max_stores));
                        return false;
                    }
                }
                //calculate new quantity
                $new_quantity = $cart[$product_id][$variation] + $quantity;
                //check stock
                if (get_post_meta($product_id, 'mp_track_inventory', true)) {
                    $stock = maybe_unserialize(get_post_meta($product_id, 'mp_inventory', true));
                    if (!is_array($stock)) {
                        $stock[0] = $stock;
                    }
                    if ($stock[$variation] < $new_quantity) {
                        if (defined('DOING_AJAX') && DOING_AJAX) {
                            echo 'error||' . sprintf(__("Sorry, we don't have enough of this item in stock. (%s remaining)", 'mp'), number_format_i18n($stock[$variation] - $cart[$product_id][$variation]));
                            exit;
                        } else {
                            $this->cart_checkout_error(sprintf(__("Sorry, we don't have enough of this item in stock. (%s remaining)", 'mp'), number_format_i18n($stock[$variation] - $cart[$product_id][$variation])));
                            return false;
                        }
                    }
                    //send ajax leftover stock
                    if (defined('DOING_AJAX') && DOING_AJAX) {
                        $return = array_sum($stock) - $new_quantity . '||';
                    }
                } else {
                    //send ajax always stock if stock checking turned off
                    if (defined('DOING_AJAX') && DOING_AJAX) {
                        $return = 1 . '||';
                    }
                }
                //check limit if tracking on or downloadable
                if (get_post_meta($product_id, 'mp_track_limit', true) || ($file = get_post_meta($product_id, 'mp_file', true))) {
                    $limit = empty($file) ? maybe_unserialize(get_post_meta($product_id, 'mp_limit', true)) : array($variation => 1);
                    if ($limit[$variation] && $limit[$variation] < $new_quantity) {
                        if (defined('DOING_AJAX') && DOING_AJAX) {
                            echo 'error||' . sprintf(__('Sorry, there is a per order limit of %1$s for "%2$s".', 'mp'), number_format_i18n($limit[$variation]), $product->post_title);
                            exit;
                        } else {
                            $this->cart_checkout_error(sprintf(__('Sorry, there is a per order limit of %1$s for "%2$s".', 'mp'), number_format_i18n($limit[$variation]), $product->post_title));
                            return false;
                        }
                    }
                }
                $cart[$product_id][$variation] = $new_quantity;
                //save items to cookie
                $this->set_cart_cookie($cart);
                //if running via ajax return updated cart and die
                if (defined('DOING_AJAX') && DOING_AJAX) {
                    $return .= mp_show_cart('widget', false, false);
                    echo $return;
                    exit;
                }
            } else {
                if (isset($_POST['update_cart_submit'])) {
                    //update cart contents
                    $global_cart = $this->get_cart_cookie(true);
                    //process quantity updates
                    if (is_array($_POST['quant'])) {
                        foreach ($_POST['quant'] as $pbid => $quant) {
                            list($bid, $product_id, $variation) = split(':', $pbid);
                            if (is_multisite()) {
                                switch_to_blog($bid);
                            }
                            $quant = intval(abs($quant));
                            if ($quant) {
                                //check stock
                                if (get_post_meta($product_id, 'mp_track_inventory', true)) {
                                    $stock = maybe_unserialize(get_post_meta($product_id, 'mp_inventory', true));
                                    if (!is_array($stock)) {
                                        $stock[0] = $stock;
                                    }
                                    if ($stock[$variation] < $quant) {
                                        $left = $stock[$variation] - intval($global_cart[$bid][$product_id][$variation]) < 0 ? 0 : $stock[$variation] - intval($global_cart[$bid][$product_id][$variation]);
                                        $this->cart_checkout_error(sprintf(__('Sorry, there is not enough stock for "%s". (%s remaining)', 'mp'), get_the_title($product_id), number_format_i18n($left)));
                                        continue;
                                    }
                                }
                                //check limit if tracking on or downloadable
                                if (get_post_meta($product_id, 'mp_track_limit', true) || ($file = get_post_meta($product_id, 'mp_file', true))) {
                                    $limit = empty($file) ? maybe_unserialize(get_post_meta($product_id, 'mp_limit', true)) : array($variation => 1);
                                    if ($limit[$variation] && $limit[$variation] < $quant) {
                                        $this->cart_checkout_error(sprintf(__('Sorry, there is a per order limit of %1$s for "%2$s".', 'mp'), number_format_i18n($limit[$variation]), get_the_title($product_id)));
                                        continue;
                                    }
                                }
                                $global_cart[$bid][$product_id][$variation] = $quant;
                            } else {
                                unset($global_cart[$bid][$product_id][$variation]);
                            }
                        }
                        if (is_multisite()) {
                            switch_to_blog($current_blog_id);
                        }
                    }
                    //remove items
                    if (isset($_POST['remove']) && is_array($_POST['remove'])) {
                        foreach ($_POST['remove'] as $pbid) {
                            list($bid, $product_id, $variation) = split(':', $pbid);
                            unset($global_cart[$bid][$product_id][$variation]);
                        }
                        $this->cart_update_message(__('Item(s) Removed', 'mp'));
                    }
                    //save items to cookie
                    $this->set_global_cart_cookie($global_cart);
                    //add coupon code
                    if (!empty($_POST['coupon_code'])) {
                        if ($this->check_coupon($_POST['coupon_code'])) {
                            //get coupon code
                            if (is_multisite()) {
                                global $blog_id;
                                $_SESSION['mp_cart_coupon_' . $blog_id] = $_POST['coupon_code'];
                            } else {
                                $_SESSION['mp_cart_coupon'] = $_POST['coupon_code'];
                            }
                            $this->cart_update_message(__('Coupon Successfully Applied', 'mp'));
                        } else {
                            $this->cart_checkout_error(__('Invalid Coupon Code', 'mp'));
                        }
                    }
                } else {
                    if (isset($_GET['remove_coupon'])) {
                        //remove coupon code
                        if (is_multisite()) {
                            global $blog_id;
                            unset($_SESSION['mp_cart_coupon_' . $blog_id]);
                        } else {
                            unset($_SESSION['mp_cart_coupon']);
                        }
                        $this->cart_update_message(__('Coupon Removed', 'mp'));
                    } else {
                        if (isset($_POST['mp_shipping_submit'])) {
                            //save shipping info
                            //check checkout info
                            if (!is_email($_POST['email'])) {
                                $this->cart_checkout_error(__('Please enter a valid Email Address.', 'mp'), 'email');
                            }
                            //only require these fields if not a download only cart
                            if (!$this->download_only_cart($this->get_cart_contents()) && $this->get_setting('shipping->method') != 'none') {
                                if (empty($_POST['name'])) {
                                    $this->cart_checkout_error(__('Please enter your Full Name.', 'mp'), 'name');
                                }
                                if (empty($_POST['address1'])) {
                                    $this->cart_checkout_error(__('Please enter your Street Address.', 'mp'), 'address1');
                                }
                                if (empty($_POST['city'])) {
                                    $this->cart_checkout_error(__('Please enter your City.', 'mp'), 'city');
                                }
                                if (($_POST['country'] == 'US' || $_POST['country'] == 'CA') && empty($_POST['state'])) {
                                    $this->cart_checkout_error(__('Please enter your State/Province/Region.', 'mp'), 'state');
                                }
                                if ($_POST['country'] == 'US' && !array_key_exists(strtoupper($_POST['state']), $this->usa_states)) {
                                    $this->cart_checkout_error(__('Please enter a valid two-letter State abbreviation.', 'mp'), 'state');
                                } else {
                                    if ($_POST['country'] == 'CA' && !array_key_exists(strtoupper($_POST['state']), $this->canadian_provinces)) {
                                        $this->cart_checkout_error(__('Please enter a valid two-letter Canadian Province abbreviation.', 'mp'), 'state');
                                    } else {
                                        $_POST['state'] = strtoupper($_POST['state']);
                                    }
                                }
                                if (empty($_POST['zip'])) {
                                    $this->cart_checkout_error(__('Please enter your Zip/Postal Code.', 'mp'), 'zip');
                                }
                                if (empty($_POST['country']) || strlen($_POST['country']) != 2) {
                                    $this->cart_checkout_error(__('Please enter your Country.', 'mp'), 'country');
                                }
                                if ($_POST['no_shipping_options'] == '1') {
                                    $this->cart_checkout_error(__('No valid shipping options found. Please check your address carefully.', 'mp'), 'no_shipping_options');
                                }
                            }
                            // Process Personalization
                            if (isset($_POST['mp_custom_fields']) && count($_POST['mp_custom_fields'])) {
                                foreach ($_POST['mp_custom_fields'] as $cf_key => $cf_items) {
                                    list($bid, $product_id, $variation) = split(':', $cf_key);
                                    if (!isset($product_id)) {
                                        continue;
                                    }
                                    if (!isset($variation)) {
                                        continue;
                                    }
                                    $mp_has_custom_field = get_post_meta(intval($product_id), 'mp_has_custom_field', true);
                                    if (isset($mp_has_custom_field) && isset($mp_has_custom_field[intval($variation)]) && $mp_has_custom_field[intval($variation)]) {
                                        $mp_custom_field_required = get_post_meta(intval($product_id), 'mp_custom_field_required', true);
                                        if (isset($mp_custom_field_required) && isset($mp_custom_field_required[intval($variation)]) && $mp_custom_field_required[intval($variation)]) {
                                            foreach ($cf_items as $idx => $cf_item) {
                                                if (empty($cf_item)) {
                                                    $this->cart_checkout_error(__('Required product extra information.', 'mp'), 'custom_fields_' . $product_id . '_' . $variation);
                                                    break;
                                                } else {
                                                    $cf_items[$idx] = trim(strip_tags(stripslashes($cf_item)));
                                                }
                                            }
                                            $_POST['mp_custom_fields'][$cf_key] = $cf_items;
                                        }
                                    }
                                }
                            }
                            //save to session
                            global $current_user;
                            $meta = get_user_meta($current_user->ID, 'mp_shipping_info', true);
                            $_SESSION['mp_shipping_info']['email'] = $_POST['email'] ? trim(stripslashes($_POST['email'])) : (isset($meta['email']) ? $meta['email'] : $current_user->user_email);
                            $_SESSION['mp_shipping_info']['name'] = $_POST['name'] ? trim(stripslashes($_POST['name'])) : (isset($meta['name']) ? $meta['name'] : $current_user->user_firstname . ' ' . $current_user->user_lastname);
                            $_SESSION['mp_shipping_info']['address1'] = $_POST['address1'] ? trim(stripslashes($_POST['address1'])) : $meta['address1'];
                            $_SESSION['mp_shipping_info']['address2'] = $_POST['address2'] ? trim(stripslashes($_POST['address2'])) : $meta['address2'];
                            $_SESSION['mp_shipping_info']['city'] = $_POST['city'] ? trim(stripslashes($_POST['city'])) : $meta['city'];
                            $_SESSION['mp_shipping_info']['state'] = $_POST['state'] ? trim(stripslashes($_POST['state'])) : $meta['state'];
                            $_SESSION['mp_shipping_info']['zip'] = $_POST['zip'] ? trim(stripslashes($_POST['zip'])) : $meta['zip'];
                            $_SESSION['mp_shipping_info']['country'] = $_POST['country'] ? trim($_POST['country']) : $meta['country'];
                            $_SESSION['mp_shipping_info']['phone'] = $_POST['phone'] ? preg_replace('/[^0-9-\\(\\) ]/', '', trim($_POST['phone'])) : $meta['phone'];
                            if (isset($_POST['special_instructions'])) {
                                $_SESSION['mp_shipping_info']['special_instructions'] = trim(stripslashes($_POST['special_instructions']));
                            }
                            //Handle and store Product Custom field data
                            if (isset($_POST['mp_custom_fields'])) {
                                $_SESSION['mp_shipping_info']['mp_custom_fields'] = $_POST['mp_custom_fields'];
                            }
                            //for checkout plugins
                            do_action('mp_shipping_process');
                            //save to user meta
                            if ($current_user->ID) {
                                update_user_meta($current_user->ID, 'mp_shipping_info', $_SESSION['mp_shipping_info']);
                            }
                            //if no errors send to next checkout step
                            if ($this->checkout_error == false) {
                                //check for $0 checkout to skip gateways
                                //loop through cart items
                                $global_cart = $this->get_cart_contents(true);
                                if (!$this->global_cart) {
                                    //get subset if needed
                                    $selected_cart[$blog_id] = $global_cart[$blog_id];
                                } else {
                                    $selected_cart = $global_cart;
                                }
                                $totals = array();
                                $shipping_prices = array();
                                $tax_prices = array();
                                foreach ($selected_cart as $bid => $cart) {
                                    if (is_multisite()) {
                                        switch_to_blog($bid);
                                    }
                                    foreach ($cart as $product_id => $variations) {
                                        foreach ($variations as $data) {
                                            $totals[] = $data['price'] * $data['quantity'];
                                        }
                                    }
                                    if (($shipping_price = $this->shipping_price()) !== false) {
                                        $shipping_prices[] = $shipping_price;
                                    }
                                    if (($tax_price = $this->tax_price()) !== false) {
                                        $tax_prices[] = $tax_price;
                                    }
                                }
                                //go back to original blog
                                if (is_multisite()) {
                                    switch_to_blog($current_blog_id);
                                }
                                $total = array_sum($totals);
                                //coupon line
                                if ($coupon = $this->coupon_value($this->get_coupon_code(), $total)) {
                                    $total = $coupon['new_total'];
                                }
                                //shipping
                                if ($shipping_price = array_sum($shipping_prices)) {
                                    $total = $total + $shipping_price;
                                }
                                //tax line
                                if ($tax_price = array_sum($tax_prices)) {
                                    $total = $total + $tax_price;
                                }
                                if ($total > 0) {
                                    $network_settings = get_site_option('mp_network_settings');
                                    //can we skip the payment form page?
                                    if ($this->global_cart) {
                                        $skip = apply_filters('mp_payment_form_skip_' . $network_settings['global_gateway'], false);
                                    } else {
                                        $skip = apply_filters('mp_payment_form_skip_' . $this->get_setting('gateways->allowed->0'), false);
                                    }
                                    if (!$this->global_cart && count($this->get_setting('gateways->allowed', array())) > 1 || !$skip) {
                                        wp_safe_redirect(mp_checkout_step_url('checkout'));
                                        exit;
                                    } else {
                                        if ($this->global_cart) {
                                            $_SESSION['mp_payment_method'] = $network_settings['global_gateway'];
                                        } else {
                                            $_SESSION['mp_payment_method'] = $this->get_setting('gateways->allowed->0');
                                        }
                                        do_action('mp_payment_submit_' . $_SESSION['mp_payment_method'], $this->get_cart_contents($this->global_cart), $_SESSION['mp_shipping_info']);
                                        //if no errors send to next checkout step
                                        if ($this->checkout_error == false) {
                                            wp_safe_redirect(mp_checkout_step_url('confirm-checkout'));
                                            exit;
                                        } else {
                                            wp_safe_redirect(mp_checkout_step_url('checkout'));
                                            exit;
                                        }
                                    }
                                } else {
                                    //empty price, create order already
                                    //loop through and create orders
                                    foreach ($selected_cart as $bid => $cart) {
                                        $totals = array();
                                        if (is_multisite()) {
                                            switch_to_blog($bid);
                                        }
                                        foreach ($cart as $product_id => $variations) {
                                            foreach ($variations as $data) {
                                                $totals[] = $data['price'] * $data['quantity'];
                                            }
                                        }
                                        $total = array_sum($totals);
                                        //coupon line
                                        if ($coupon = $this->coupon_value($this->get_coupon_code(), $total)) {
                                            $total = $coupon['new_total'];
                                        }
                                        //shipping
                                        if (($shipping_price = $this->shipping_price()) !== false) {
                                            $total = $total + $shipping_price;
                                        }
                                        //tax line
                                        if (($tax_price = $this->tax_price()) !== false) {
                                            $total = $total + $tax_price;
                                        }
                                        //setup our payment details
                                        $timestamp = time();
                                        $payment_info['gateway_public_name'] = __('Manual Checkout', 'mp');
                                        $payment_info['gateway_private_name'] = __('Manual Checkout', 'mp');
                                        $payment_info['method'][] = __('N/A - Free order', 'mp');
                                        $payment_info['transaction_id'][] = __('N/A', 'mp');
                                        $payment_info['status'][$timestamp] = __('Completed', 'mp');
                                        $payment_info['total'] = $total;
                                        $payment_info['currency'] = $this->get_setting('currency');
                                        $this->create_order(false, $cart, $_SESSION['mp_shipping_info'], $payment_info, true);
                                    }
                                    //go back to original blog
                                    if (is_multisite()) {
                                        switch_to_blog($current_blog_id);
                                    }
                                    $_SESSION['mp_payment_method'] = 'manual';
                                    //so we don't get an error message on confirmation page
                                    //redirect to final page
                                    wp_safe_redirect(mp_checkout_step_url('confirmation'));
                                    exit;
                                }
                            }
                        } else {
                            if (isset($_POST['mp_choose_gateway'])) {
                                //check and save payment info
                                $_SESSION['mp_payment_method'] = $_POST['mp_choose_gateway'];
                                //processing script is only for selected gateway plugin
                                do_action('mp_payment_submit_' . $_SESSION['mp_payment_method'], $this->get_cart_contents($this->global_cart), $_SESSION['mp_shipping_info']);
                                //if no errors send to next checkout step
                                if ($this->checkout_error == false) {
                                    wp_safe_redirect(mp_checkout_step_url('confirm-checkout'));
                                    exit;
                                }
                            } else {
                                if (isset($_POST['mp_payment_confirm'])) {
                                    //create order and process payment
                                    do_action('mp_payment_confirm_' . $_SESSION['mp_payment_method'], $this->get_cart_contents($this->global_cart), $_SESSION['mp_shipping_info']);
                                    //if no errors send to next checkout step
                                    if ($this->checkout_error == false) {
                                        wp_safe_redirect(mp_checkout_step_url('confirmation'));
                                        exit;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
示例#23
0
 /**
  * Use this to do the final payment. Create the order then process the payment. If
  *  you know the payment is successful right away go ahead and change the order status
  *  as well.
  *  Call $mp->cart_checkout_error($msg, $context); to handle errors. If no errors
  *  it will redirect to the next step.
  *
  * @param array $cart. Contains the cart contents for the current blog, global cart if $mp->global_cart is true
  * @param array $shipping_info. Contains shipping info and email in case you need it
  */
 function process_payment($global_cart, $shipping_info)
 {
     global $mp, $blog_id, $site_id, $switched_stack, $switched;
     $blog_id = is_multisite() ? $blog_id : 1;
     $current_blog_id = $blog_id;
     if (!$mp->global_cart) {
         $selected_cart[$blog_id] = $global_cart;
     } else {
         $selected_cart = $global_cart;
     }
     if (isset($_SESSION['token']) && isset($_SESSION['PayerID']) && isset($_SESSION['final_amt'])) {
         //attempt the final payment
         $result = $this->DoExpressCheckoutPayment($_SESSION['token'], $_SESSION['PayerID']);
         //check response
         if ($result["ACK"] == "Success" || $result["ACK"] == "SuccessWithWarning") {
             //setup our payment details
             $payment_info['gateway_public_name'] = $this->public_name;
             $payment_info['gateway_private_name'] = $this->admin_name;
             for ($i = 0; $i < 10; $i++) {
                 if (!isset($result['PAYMENTINFO_' . $i . '_PAYMENTTYPE'])) {
                     continue;
                 }
                 $payment_info['method'] = $result["PAYMENTINFO_{$i}_PAYMENTTYPE"] == 'echeck' ? __('eCheck', 'mp') : __('PayPal balance, Credit Card, or Instant Transfer', 'mp');
                 $payment_info['transaction_id'] = $result["PAYMENTINFO_{$i}_TRANSACTIONID"];
                 $timestamp = strtotime($result["PAYMENTINFO_{$i}_ORDERTIME"]);
                 //setup status
                 switch ($result["PAYMENTINFO_{$i}_PAYMENTSTATUS"]) {
                     case 'Canceled-Reversal':
                         $status = __('A reversal has been canceled; for example, when you win a dispute and the funds for the reversal have been returned to you.', 'mp');
                         $paid = true;
                         break;
                     case 'Expired':
                         $status = __('The authorization period for this payment has been reached.', 'mp');
                         $paid = false;
                         break;
                     case 'Voided':
                         $status = __('An authorization for this transaction has been voided.', 'mp');
                         $paid = false;
                         break;
                     case 'Failed':
                         $status = __('The payment has failed. This happens only if the payment was made from your customer\'s bank account.', 'mp');
                         $paid = false;
                         break;
                     case 'Partially-Refunded':
                         $status = __('The payment has been partially refunded.', 'mp');
                         $paid = true;
                         break;
                     case 'In-Progress':
                         $status = __('The transaction has not terminated, e.g. an authorization may be awaiting completion.', 'mp');
                         $paid = false;
                         break;
                     case 'Completed':
                         $status = __('The payment has been completed, and the funds have been added successfully to your account balance.', 'mp');
                         $paid = true;
                         break;
                     case 'Processed':
                         $status = __('A payment has been accepted.', 'mp');
                         $paid = true;
                         break;
                     case 'Reversed':
                         $status = __('A payment was reversed due to a chargeback or other type of reversal. The funds have been removed from your account balance and returned to the buyer:', 'mp');
                         $reverse_reasons = array('none' => '', 'chargeback' => __('A reversal has occurred on this transaction due to a chargeback by your customer.', 'mp'), 'guarantee' => __('A reversal has occurred on this transaction due to your customer triggering a money-back guarantee.', 'mp'), 'buyer-complaint' => __('A reversal has occurred on this transaction due to a complaint about the transaction from your customer.', 'mp'), 'refund' => __('A reversal has occurred on this transaction because you have given the customer a refund.', 'mp'), 'other' => __('A reversal has occurred on this transaction due to an unknown reason.', 'mp'));
                         $status .= '<br />' . $reverse_reasons[$result["PAYMENTINFO_{$i}_REASONCODE"]];
                         $paid = false;
                         break;
                     case 'Refunded':
                         $status = __('You refunded the payment.', 'mp');
                         $paid = false;
                         break;
                     case 'Denied':
                         $status = __('You denied the payment when it was marked as pending.', 'mp');
                         $paid = false;
                         break;
                     case 'Pending':
                         $pending_str = array('address' => __('The payment is pending because your customer did not include a confirmed shipping address and your Payment Receiving Preferences is set such that you want to manually accept or deny each of these payments. To change your preference, go to the Preferences  section of your Profile.', 'mp'), 'authorization' => __('The payment is pending because it has been authorized but not settled. You must capture the funds first.', 'mp'), 'echeck' => __('The payment is pending because it was made by an eCheck that has not yet cleared.', 'mp'), 'intl' => __('The payment is pending because you hold a non-U.S. account and do not have a withdrawal mechanism. You must manually accept or deny this payment from your Account Overview.', 'mp'), 'multi-currency' => __('You do not have a balance in the currency sent, and you do not have your Payment Receiving Preferences set to automatically convert and accept this payment. You must manually accept or deny this payment.', 'mp'), 'order' => __('The payment is pending because it is part of an order that has been authorized but not settled.', 'mp'), 'paymentreview' => __('The payment is pending while it is being reviewed by PayPal for risk.', 'mp'), 'unilateral' => __('The payment is pending because it was made to an email address that is not yet registered or confirmed.', 'mp'), 'upgrade' => __('The payment is pending because it was made via credit card and you must upgrade your account to Business or Premier status in order to receive the funds. It can also mean that you have reached the monthly limit for transactions on your account.', 'mp'), 'verify' => __('The payment is pending because you are not yet verified. You must verify your account before you can accept this payment.', 'mp'), 'other' => __('The payment is pending for an unknown reason. For more information, contact PayPal customer service.', 'mp'), '*' => '');
                         $status = __('The payment is pending.', 'mp');
                         $status .= '<br />' . $pending_str[$result["PAYMENTINFO_{$i}_PENDINGREASON"]];
                         $paid = false;
                         break;
                     default:
                         // case: various error cases
                         $paid = false;
                 }
                 $status = $result["PAYMENTINFO_{$i}_PAYMENTSTATUS"] . ': ' . $status;
                 //status's are stored as an array with unix timestamp as key
                 $payment_info['status'] = array();
                 $payment_info['status'][$timestamp] = $status;
                 $payment_info['currency'] = $result["PAYMENTINFO_{$i}_CURRENCYCODE"];
                 $payment_info['total'] = $result["PAYMENTINFO_{$i}_AMT"];
                 $payment_info['note'] = $result["NOTE"];
                 //optional, only shown if gateway supports it
                 //figure out blog_id of this payment to put the order into it
                 $unique_id = $result["PAYMENTINFO_{$i}_PAYMENTREQUESTID"] ? $result["PAYMENTINFO_{$i}_PAYMENTREQUESTID"] : $result["PAYMENTREQUEST_{$i}_PAYMENTREQUESTID"];
                 //paypal docs messed up, not sure which is valid return
                 @(list($bid, $order_id) = explode(':', $unique_id));
                 if (is_multisite()) {
                     switch_to_blog($bid, true);
                 }
                 //succesful payment, create our order now
                 $mp->create_order($_SESSION['mp_order'], $selected_cart[$bid], $shipping_info, $payment_info, $paid);
             }
             if (is_multisite()) {
                 switch_to_blog($current_blog_id, true);
             }
             //success. Do nothing, it will take us to the confirmation page
         } else {
             //whoops, error
             for ($i = 0; $i <= 5; $i++) {
                 //print the first 5 errors
                 if (isset($result["L_ERRORCODE{$i}"])) {
                     $error .= "<li>{$result["L_ERRORCODE{$i}"]} - {$result["L_SHORTMESSAGE{$i}"]} - " . stripslashes($result["L_LONGMESSAGE{$i}"]) . "</li>";
                 }
             }
             $error = '<br /><ul>' . $error . '</ul>';
             $mp->cart_checkout_error(sprintf(__('There was a problem finalizing your purchase with PayPal. Please <a href="%s">go back and try again</a>.', 'mp'), mp_checkout_step_url('checkout')) . $error);
         }
     } else {
         $mp->cart_checkout_error(sprintf(__('There was a problem finalizing your purchase with PayPal. Please <a href="%s">go back and try again</a>.', 'mp'), mp_checkout_step_url('checkout')));
     }
 }
示例#24
0
    /**
     * @return string HTML that shows the user their current position in the purchase process.
     */
    function mp_cart_breadcrumbs($current_step)
    {
        $steps = array('checkout-edit' => __('Review Cart', 'mp'), 'shipping' => __('Shipping', 'mp'), 'checkout' => __('Checkout', 'mp'), 'confirm-checkout' => __('Confirm', 'mp'), 'confirmation' => __('Order Complete', 'mp'));
        $order = array_keys($steps);
        $current = array_search($current_step, $order);
        $all = array();
        foreach ($steps as $str => $human) {
            $i = array_search($str, $order);
            if ($i >= $current) {
                // incomplete
                $all[] = '<span class="incomplete ' . ($i == $current ? 'current' : '') . '">' . $human . '</span>';
            } else {
                // done
                $all[] = '<a class="done" href="' . mp_checkout_step_url($str) . '">' . $human . '</a>';
            }
        }
        $return = '<div class="mp_cart_breadcrumbs">
				' . implode('<span class="sep">' . apply_filters('mp_cart_breadcrumbs_seperator', '&raquo;') . '</span>', $all) . '
			</div>';
        return apply_filters('mp_cart_breadcrumbs', $return, $current_step);
    }
示例#25
0
 /**
  * Use this to do the final payment. Create the order then process the payment. If
  *  you know the payment is successful right away go ahead and change the order status
  *  as well.
  *  Call $mp->cart_checkout_error($msg, $context); to handle errors. If no errors
  *  it will redirect to the next step.
  *
  * @param array $cart. Contains the cart contents for the current blog, global cart if $mp->global_cart is true
  * @param array $shipping_info. Contains shipping info and email in case you need it
  */
 function process_payment($cart, $shipping_info)
 {
     global $mp;
     $settings = get_option('mp_settings');
     //make sure token is set at this point
     if (!isset($_SESSION['card_token'])) {
         $mp->cart_checkout_error(__('The PIN Token was not generated correctly. Please go back and try again.', 'mp'));
         return false;
     }
     if ($this->force_ssl) {
         define('PIN_API_CHARGE_URL', 'https://api.pin.net.au/1/charges');
     } else {
         define('PIN_API_CHARGE_URL', 'https://test-api.pin.net.au/1/charges');
     }
     define('PIN_API_KEY', $this->private_key);
     $token = $_SESSION['card_token'];
     if ($token) {
         $totals = array();
         $coupon_code = $mp->get_coupon_code();
         foreach ($cart as $product_id => $variations) {
             foreach ($variations as $variation => $data) {
                 $price = $mp->coupon_value_product($coupon_code, $data['price'] * $data['quantity'], $product_id);
                 $totals[] = $price;
             }
         }
         $total = array_sum($totals);
         //shipping line
         $shipping_tax = 0;
         if (($shipping_price = $mp->shipping_price(false)) !== false) {
             $total += $shipping_price;
             $shipping_tax = $mp->shipping_tax_price($shipping_price) - $shipping_price;
         }
         //tax line if tax inclusive pricing is off. It it's on it would screw up the totals
         if (!$mp->get_setting('tax->tax_inclusive')) {
             $tax_price = $mp->tax_price(false) + $shipping_tax;
             $total += $tax_price;
         }
         $order_id = $mp->generate_order_id();
         try {
             $args = array('method' => 'POST', 'httpversion' => '1.1', 'timeout' => apply_filters('http_request_timeout', 30), 'blocking' => true, 'compress' => true, 'headers' => array('Authorization' => 'Basic ' . base64_encode(PIN_API_KEY . ':' . '')), 'body' => array('amount' => (int) $total * 100, 'currency' => strtolower($this->currency), 'description' => sprintf(__('%s Store Purchase - Order ID: %s, Email: %s', 'mp'), get_bloginfo('name'), $order_id, $_SESSION['mp_shipping_info']['email']), 'email' => $_SESSION['mp_shipping_info']['email'], 'ip_address' => $_SESSION['ip_address'], 'card_token' => $_SESSION['card_token']), 'cookies' => array());
             $charge = wp_remote_post(PIN_API_CHARGE_URL, $args);
             $charge = json_decode($charge['body'], true);
             $charge = $charge['response'];
             if ($charge['success'] == true) {
                 //setup our payment details
                 $payment_info = array();
                 $payment_info['gateway_public_name'] = $this->public_name;
                 $payment_info['gateway_private_name'] = $this->admin_name;
                 $payment_info['method'] = sprintf(__('%1$s Card %2$s', 'mp'), ucfirst($charge['card']['scheme']), $charge['card']['display_number']);
                 $payment_info['transaction_id'] = $charge['token'];
                 $timestamp = time();
                 $payment_info['status'][$timestamp] = __('Paid', 'mp');
                 $payment_info['total'] = $total;
                 $payment_info['currency'] = $this->currency;
                 $order = $mp->create_order($order_id, $cart, $_SESSION['mp_shipping_info'], $payment_info, true);
                 unset($_SESSION['card_token']);
                 $mp->set_cart_cookie(array());
             } else {
                 unset($_SESSION['card_token']);
                 $mp->cart_checkout_error(sprintf(__('There was an error processing your card. Please <a href="%s">go back and try again</a>.', 'mp'), mp_checkout_step_url('checkout')));
                 return false;
             }
         } catch (Exception $e) {
             unset($_SESSION['card_token']);
             $mp->cart_checkout_error(sprintf(__('There was an error processing your card: "%s". Please <a href="%s">go back and try again</a>.', 'mp'), $e->getMessage(), mp_checkout_step_url('checkout')));
             return false;
         }
     }
 }