/** * CallSetExpressCheckout * * Makes a request to PayPal's SetExpressCheckout API * to setup the checkout and obtain a token. * * @paymentAmount (double) Total payment amount of the order. * @returnURL (string) URL for PayPal to send the buyer to after review and continue from PayPal. * @cancelURL (string) URL for PayPal to send the buyer to if they cancel the payment. */ function CallSetExpressCheckout($paymentAmount, $returnURL, $cancelURL, $usePayPalCredit = false, $posted) { /* * Display message to user if session has expired. */ if (sizeof(WC()->cart->get_cart()) == 0) { $ms = sprintf(__('Sorry, your session has expired. <a href=%s>Return to homepage →</a>', 'paypal-for-woocommerce'), '"' . home_url() . '"'); $set_ec_message = apply_filters('angelleye_set_ec_message', $ms); wc_add_notice($set_ec_message, "error"); } /* * Check if the PayPal class has already been established. */ if (!class_exists('Angelleye_PayPal')) { require_once PAYPAL_FOR_WOOCOMMERCE_PLUGIN_DIR . '/classes/lib/angelleye/paypal-php-library/includes/paypal.class.php'; } /* * Create PayPal object. */ $PayPalConfig = array('Sandbox' => $this->testmode == 'yes' ? TRUE : FALSE, 'APIUsername' => $this->api_username, 'APIPassword' => $this->api_password, 'APISignature' => $this->api_signature); $PayPal = new Angelleye_PayPal($PayPalConfig); /** * Prepare PayPal request data. */ /** * If Gift Wrap options are enabled, then MAXAMT is required * in SetExpressCheckout. * * https://github.com/angelleye/paypal-woocommerce/issues/142 */ if ($this->gift_wrap_enabled == 'yes') { $maxAmount = $paymentAmount * 2; $maxAmount = $maxAmount + $this->gift_wrap_amount; $maxAmount = AngellEYE_Gateway_Paypal::number_format($maxAmount); } else { $maxAmount = ''; } //prefill email if (isset($posted['billing_email'])) { $customer_email = $posted['billing_email']; } elseif (is_user_logged_in()) { global $current_user; get_currentuserinfo(); $customer_email = $current_user->user_email; } else { $customer_email = ''; } $SECFields = array('token' => '', 'maxamt' => $maxAmount, 'returnurl' => urldecode($returnURL), 'cancelurl' => urldecode($cancelURL), 'callback' => '', 'callbacktimeout' => '', 'callbackversion' => '', 'reqconfirmshipping' => '', 'noshipping' => '', 'allownote' => 1, 'addroverride' => '', 'localecode' => $this->use_wp_locale_code == 'yes' && get_locale() != '' ? get_locale() : '', 'pagestyle' => '', 'hdrimg' => $this->checkout_logo_hdrimg, 'logoimg' => $this->checkout_logo, 'hdrbordercolor' => '', 'hdrbackcolor' => '', 'payflowcolor' => '', 'skipdetails' => $this->skip_final_review == 'yes' ? '1' : '0', 'email' => $customer_email, 'channeltype' => '', 'giropaysuccessurl' => '', 'giropaycancelurl' => '', 'banktxnpendingurl' => '', 'brandname' => $this->brand_name, 'customerservicenumber' => $this->customer_service_number, 'buyeremailoptionenable' => '', 'surveyquestion' => '', 'surveyenable' => '', 'totaltype' => '', 'notetobuyer' => '', 'buyerid' => '', 'buyerusername' => '', 'buyerregistrationdate' => '', 'allowpushfunding' => '', 'taxidtype' => '', 'taxid' => ''); /** * If Gift Wrap options are enabled, add them to SEC */ if (strtolower($this->gift_wrap_enabled) == 'yes') { $SECFields['giftwrapenable'] = '1'; // Enable gift wrap widget on the PayPal Review page. Allowable values are 0 and 1. $SECFields['giftmessageenable'] = $this->gift_message_enabled ? '1' : ''; // Enable gift message widget on the PayPal Review page. Allowable values are 0 and 1 $SECFields['giftreceiptenable'] = $this->gift_receipt_enabled ? '1' : ''; // Enable gift receipt widget on the PayPal Review page. Allowable values are 0 and 1 $SECFields['giftwrapname'] = $this->gift_wrap_name; // Label for the gift wrap option such as "Box with ribbon". 25 char max. $SECFields['giftwrapamount'] = $this->gift_wrap_amount; // Amount charged for gift-wrap service. } /** * If PayPal Credit is being used, override the necessary parameters */ if ($usePayPalCredit) { $SECFields['solutiontype'] = 'Sole'; $SECFields['landingpage'] = 'Billing'; $SECFields['userselectedfundingsource'] = 'BML'; } elseif (strtolower($this->paypal_account_optional) == 'yes' && strtolower($this->landing_page) == 'billing') { $SECFields['solutiontype'] = 'Sole'; $SECFields['landingpage'] = 'Billing'; $SECFields['userselectedfundingsource'] = 'CreditCard'; } elseif (strtolower($this->paypal_account_optional) == 'yes' && strtolower($this->landing_page) == 'login') { $SECFields['solutiontype'] = 'Sole'; $SECFields['landingpage'] = 'Login'; } // Basic array of survey choices. Nothing but the values should go in here. $SurveyChoices = array('Choice 1', 'Choice2', 'Choice3', 'etc'); $Payments = array(); $Payment = array('amt' => AngellEYE_Gateway_Paypal::number_format(WC()->cart->total), 'currencycode' => get_woocommerce_currency(), 'shippingamt' => '', 'shippingdiscamt' => '', 'insuranceamt' => '', 'insuranceoptionoffered' => '', 'handlingamt' => '', 'taxamt' => '', 'desc' => '', 'custom' => '', 'invnum' => '', 'notifyurl' => '', 'shiptoname' => '', 'shiptostreet' => '', 'shiptostreet2' => '', 'shiptocity' => '', 'shiptostate' => '', 'shiptozip' => '', 'shiptocountrycode' => '', 'shiptophonenum' => '', 'notetext' => isset($posted['order_comments']) ? $posted['order_comments'] : '', 'allowedpaymentmethod' => '', 'paymentaction' => $this->payment_action == 'Authorization' ? 'Authorization' : 'Sale', 'paymentrequestid' => '', 'sellerpaypalaccountid' => ''); /** * If checkout like regular payment */ if (!empty($posted) && WC()->cart->needs_shipping()) { $SECFields['addroverride'] = 1; if (@$posted['ship_to_different_address']) { $Payment['shiptoname'] = $posted['shipping_first_name'] . ' ' . $posted['shipping_last_name']; $Payment['shiptostreet'] = $posted['shipping_address_1']; $Payment['shiptostreet2'] = @$posted['shipping_address_2']; $Payment['shiptocity'] = @$posted['shipping_city']; $Payment['shiptostate'] = @$posted['shipping_state']; $Payment['shiptozip'] = @$posted['shipping_postcode']; $Payment['shiptocountrycode'] = @$posted['shipping_country']; $Payment['shiptophonenum'] = @$posted['shipping_phone']; } else { $Payment['shiptoname'] = $posted['billing_first_name'] . ' ' . $posted['billing_last_name']; $Payment['shiptostreet'] = $posted['billing_address_1']; $Payment['shiptostreet2'] = @$posted['billing_address_2']; $Payment['shiptocity'] = @$posted['billing_city']; $Payment['shiptostate'] = @$posted['billing_state']; $Payment['shiptozip'] = @$posted['billing_postcode']; $Payment['shiptocountrycode'] = @$posted['billing_country']; $Payment['shiptophonenum'] = @$posted['billing_phone']; } } elseif (is_user_logged_in() && WC()->cart->needs_shipping()) { $Payment['shiptostreet'] = WC()->customer->get_shipping_address(); $Payment['shiptostreet2'] = WC()->customer->get_shipping_address_2(); $Payment['shiptocity'] = WC()->customer->get_shipping_city(); $Payment['shiptostate'] = WC()->customer->get_shipping_state(); $Payment['shiptozip'] = WC()->customer->get_shipping_postcode(); $Payment['shiptocountrycode'] = WC()->customer->get_shipping_country(); } $SECFields = AngellEYE_Gateway_Paypal::angelleye_paypal_for_woocommerce_needs_shipping($SECFields); $PaymentData = AngellEYE_Gateway_Paypal::calculate(null, true); $PaymentOrderItems = array(); $ctr = $total_items = $total_discount = $total_tax = $order_total = 0; if ($this->send_items) { foreach ($PaymentData['order_items'] as $item) { $Item = array('name' => $item['name'], 'desc' => '', 'amt' => $item['amt'], 'number' => $item['number'], 'qty' => $item['qty'], 'taxamt' => '', 'itemurl' => '', 'itemcategory' => '', 'itemweightvalue' => '', 'itemweightunit' => '', 'itemheightvalue' => '', 'itemheightunit' => '', 'itemwidthvalue' => '', 'itemwidthunit' => '', 'itemlengthvalue' => '', 'itemlengthunit' => '', 'ebayitemnumber' => '', 'ebayitemauctiontxnid' => '', 'ebayitemorderid' => '', 'ebayitemcartid' => ''); array_push($PaymentOrderItems, $Item); } $Payment['order_items'] = $PaymentOrderItems; } else { $Payment['order_items'] = array(); } /** * Shipping/tax/item amount */ $Payment['taxamt'] = $PaymentData['taxamt']; $Payment['shippingamt'] = $PaymentData['shippingamt']; $Payment['itemamt'] = $PaymentData['itemamt']; /* * Then we load the payment into the $Payments array */ array_push($Payments, $Payment); $BuyerDetails = array('buyerid' => '', 'buyerusername' => '', 'buyerregistrationdate' => ''); // For shipping options we create an array of all shipping choices similar to how order items works. $ShippingOptions = array(); $Option = array('l_shippingoptionisdefault' => '', 'l_shippingoptionname' => '', 'l_shippingoptionlabel' => '', 'l_shippingoptionamount' => ''); array_push($ShippingOptions, $Option); global $pp_settings, $pp_pro, $pp_payflow; $PayPalRequestData = array('SECFields' => $SECFields, 'SurveyChoices' => $SurveyChoices, 'Payments' => $Payments); $PayPalRequestData = AngellEYE_Gateway_Paypal::angelleye_paypal_for_woocommerce_paypal_billing_agreement($PayPalRequestData); // Pass data into class for processing with PayPal and load the response array into $PayPalResult $PayPalResult = $PayPal->SetExpressCheckout($PayPalRequestData); /** * cURL Error Handling #146 * @since 1.1.8 */ AngellEYE_Gateway_Paypal::angelleye_paypal_for_woocommerce_curl_error_handler($PayPalResult, $methos_name = 'SetExpressCheckout', $gateway = 'PayPal Express Checkout', $this->error_email_notify); /* * Log API result */ $this->add_log('Test Mode: ' . $this->testmode); $this->add_log('Endpoint: ' . $this->API_Endpoint); $PayPalRequest = isset($PayPalResult['RAWREQUEST']) ? $PayPalResult['RAWREQUEST'] : ''; $PayPalResponse = isset($PayPalResult['RAWRESPONSE']) ? $PayPalResult['RAWRESPONSE'] : ''; $this->add_log('Request: ' . print_r($PayPal->NVPToArray($PayPal->MaskAPIResult($PayPalRequest)), true)); $this->add_log('Response: ' . print_r($PayPal->NVPToArray($PayPal->MaskAPIResult($PayPalResponse)), true)); /* * Error handling */ if ($PayPal->APICallSuccessful($PayPalResult['ACK'])) { $token = urldecode($PayPalResult["TOKEN"]); $this->set_session('TOKEN', $token); } /* * Return the class library result array. */ return $PayPalResult; }
/** * CallSetExpressCheckout * * Makes a request to PayPal's SetExpressCheckout API * to setup the checkout and obtain a token. * * @paymentAmount (double) Total payment amount of the order. * @returnURL (string) URL for PayPal to send the buyer to after review and continue from PayPal. * @cancelURL (string) URL for PayPal to send the buyer to if they cancel the payment. */ function CallSetExpressCheckout($paymentAmount, $returnURL, $cancelURL, $usePayPalCredit = false, $posted, $lineitems, $order) { /* * Display message to user if session has expired. */ if (sizeof(WC()->cart->get_cart()) == 0) { $ms = sprintf(__('Sorry, your session has expired. <a href=%s>Return to homepage →</a>', 'paypal-for-woocommerce'), '"' . home_url() . '"'); $set_ec_message = apply_filters('angelleye_set_ec_message', $ms); wc_add_notice($set_ec_message, "error"); } /* * Check if the PayPal class has already been established. */ if (!class_exists('Angelleye_PayPal')) { require_once 'lib/angelleye/paypal-php-library/includes/paypal.class.php'; } /* * Create PayPal object. */ $PayPalConfig = array('Sandbox' => $this->testmode == 'yes' ? TRUE : FALSE, 'APIUsername' => $this->api_username, 'APIPassword' => $this->api_password, 'APISignature' => $this->api_signature); $PayPal = new Angelleye_PayPal($PayPalConfig); /** * Prepare PayPal request data. */ /** * If Gift Wrap options are enabled, then MAXAMT is required * in SetExpressCheckout. * * https://github.com/angelleye/paypal-woocommerce/issues/142 */ if ($this->gift_wrap_enabled == 'yes') { $maxAmount = $paymentAmount * 2; $maxAmount = $maxAmount + $this->gift_wrap_amount; $maxAmount = number_format($maxAmount, 2, '.', ''); } else { $maxAmount = ''; } if (isset($_POST['order_comments']) && !empty($_POST['order_comments'])) { $is_ordernote = "0"; } else { $is_ordernote = "1"; } $SECFields = array('token' => '', 'maxamt' => $maxAmount, 'returnurl' => urldecode($returnURL), 'cancelurl' => urldecode($cancelURL), 'callback' => '', 'callbacktimeout' => '', 'callbackversion' => '', 'reqconfirmshipping' => '', 'noshipping' => '', 'allownote' => $is_ordernote, 'addroverride' => '', 'localecode' => $this->use_wp_locale_code == 'yes' && get_locale() != '' ? get_locale() : '', 'pagestyle' => '', 'hdrimg' => $this->checkout_logo_hdrimg, 'logourl' => $this->checkout_logo, 'hdrbordercolor' => '', 'hdrbackcolor' => '', 'payflowcolor' => '', 'skipdetails' => $this->skip_final_review == 'yes' ? '1' : '0', 'email' => '', 'channeltype' => '', 'giropaysuccessurl' => '', 'giropaycancelurl' => '', 'banktxnpendingurl' => '', 'brandname' => $this->brand_name, 'customerservicenumber' => $this->customer_service_number, 'buyeremailoptionenable' => '', 'surveyquestion' => '', 'surveyenable' => '', 'totaltype' => '', 'notetobuyer' => '', 'buyerid' => '', 'buyerusername' => '', 'buyerregistrationdate' => '', 'allowpushfunding' => '', 'taxidtype' => '', 'taxid' => ''); /** * If Gift Wrap options are enabled, add them to SEC */ if (strtolower($this->gift_wrap_enabled) == 'yes') { $SECFields['giftwrapenable'] = '1'; // Enable gift wrap widget on the PayPal Review page. Allowable values are 0 and 1. $SECFields['giftmessageenable'] = $this->gift_message_enabled ? '1' : ''; // Enable gift message widget on the PayPal Review page. Allowable values are 0 and 1 $SECFields['giftreceiptenable'] = $this->gift_receipt_enabled ? '1' : ''; // Enable gift receipt widget on the PayPal Review page. Allowable values are 0 and 1 $SECFields['giftwrapname'] = $this->gift_wrap_name; // Label for the gift wrap option such as "Box with ribbon". 25 char max. $SECFields['giftwrapamount'] = $this->gift_wrap_amount; // Amount charged for gift-wrap service. } /** * If PayPal Credit is being used, override the necessary parameters */ if ($usePayPalCredit) { $SECFields['solutiontype'] = 'Sole'; $SECFields['landingpage'] = 'Billing'; $SECFields['userselectedfundingsource'] = 'BML'; } elseif (strtolower($this->paypal_account_optional) == 'yes' && strtolower($this->landing_page) == 'billing') { $SECFields['solutiontype'] = 'Sole'; $SECFields['landingpage'] = 'Billing'; $SECFields['userselectedfundingsource'] = 'CreditCard'; } elseif (strtolower($this->paypal_account_optional) == 'yes' && strtolower($this->landing_page) == 'login') { $SECFields['solutiontype'] = 'Sole'; $SECFields['landingpage'] = 'Login'; } // Basic array of survey choices. Nothing but the values should go in here. $SurveyChoices = array('Choice 1', 'Choice2', 'Choice3', 'etc'); /* * Get tax amount. */ /* * ************************ Tax amount MD****************************************** */ foreach ($order->get_tax_totals() as $code => $tax) { $tax_string_array[] = $tax->formatted_amount; } $current_currency = get_woocommerce_currency_symbol(get_woocommerce_currency()); if (isset($tax_string_array) && !empty($tax_string_array)) { $striped_amt = strip_tags($tax_string_array[0]); $tot_tax = str_replace($current_currency, '', $striped_amt); } /* * ************************ Tax amount MD*********************** */ if (get_option('woocommerce_prices_include_tax') == 'yes') { $shipping = $order->get_total_shipping(); //+ $order->order_shipping_tax; $tax = '0.00'; } else { $shipping = $order->get_total_shipping(); if (isset($tot_tax) && !empty($tot_tax)) { $tax = $tot_tax; } } if ('yes' === get_option('woocommerce_calc_taxes') && 'yes' === get_option('woocommerce_prices_include_tax')) { // $tax = wc_round_tax_total($tot_tax + WC()->cart->shipping_tax_total); if (isset($tot_tax) && !empty($tot_tax)) { $tax = $tot_tax; // ($tot_tax + $order->order_shipping_tax); } } if (isset($tax) && !empty($tax)) { $tax = $tax; } else { $tax = '0.00'; } $Payments = array(); $Payment = array('amt' => number_format($paymentAmount, 2, '.', ''), 'currencycode' => get_woocommerce_currency(), 'shippingamt' => number_format($shipping, 2, '.', ''), 'shippingdiscamt' => '', 'insuranceamt' => '', 'insuranceoptionoffered' => '', 'handlingamt' => '', 'taxamt' => number_format($tax, 2, '.', ''), 'desc' => '', 'custom' => '', 'invnum' => preg_replace("/[^0-9]/", "", $order->id), 'notifyurl' => '', 'shiptoname' => '', 'shiptostreet' => '', 'shiptostreet2' => '', 'shiptocity' => '', 'shiptostate' => '', 'shiptozip' => '', 'shiptocountrycode' => '', 'shiptophonenum' => '', 'notetext' => '', 'allowedpaymentmethod' => '', 'paymentaction' => $this->payment_action == 'Authorization' ? 'Authorization' : 'Sale', 'paymentrequestid' => '', 'sellerpaypalaccountid' => ''); /** * If checkout like regular payment */ if (!empty($posted) && WC()->cart->needs_shipping()) { $SECFields['addroverride'] = 1; if (@$posted['ship_to_different_address']) { $Payment['shiptoname'] = $posted['shipping_first_name'] . ' ' . $posted['shipping_last_name']; $Payment['shiptostreet'] = $posted['shipping_address_1']; $Payment['shiptostreet2'] = @$posted['shipping_address_2']; $Payment['shiptocity'] = @$posted['shipping_city']; $Payment['shiptostate'] = @$posted['shipping_state']; $Payment['shiptozip'] = @$posted['shipping_postcode']; $Payment['shiptocountrycode'] = @$posted['shipping_country']; $Payment['shiptophonenum'] = @$posted['shipping_phone']; } else { $Payment['shiptoname'] = $posted['billing_first_name'] . ' ' . $posted['billing_last_name']; $Payment['shiptostreet'] = $posted['billing_address_1']; $Payment['shiptostreet2'] = @$posted['billing_address_2']; $Payment['shiptocity'] = @$posted['billing_city']; $Payment['shiptostate'] = @$posted['billing_state']; $Payment['shiptozip'] = @$posted['billing_postcode']; $Payment['shiptocountrycode'] = @$posted['billing_country']; $Payment['shiptophonenum'] = @$posted['billing_phone']; } } $PaymentOrderItems = array(); $order_items_own = array(); $ctr = $total_items = $total_discount = $total_tax = $order_total = 0; $counter = 1; foreach (WC()->cart->get_cart() as $cart_item_key => $values) { /* * Get product data from WooCommerce */ $_product = $values['data']; $qty = absint($values['quantity']); $sku = $_product->get_sku(); $values['name'] = html_entity_decode($_product->get_title(), ENT_NOQUOTES, 'UTF-8'); /* ------------------------------------------------------------------------------------------------- */ if (in_array($values['product_id'], $lineitems)) { $arraykey = array_search($values['product_id'], $lineitems); $item_position = str_replace('product_number_', '', $arraykey); $get_amountkey = 'amount_' . $counter; $get_qtykey = 'quantity_' . $counter; $switcher_amt = $lineitems[$get_amountkey]; $switcher_qty = $lineitems[$get_qtykey]; $counter = $counter + 1; } /* ------------------------------------------------------------------------------------------------- */ /* * Append variation data to name. */ if ($_product->product_type == 'variation') { $meta = WC()->cart->get_item_data($values, true); if (empty($sku)) { $sku = $_product->parent->get_sku(); } if (!empty($meta)) { $values['name'] .= " - " . str_replace(", \n", " - ", $meta); } } $quantity = absint($values['quantity']); $Item = array('name' => $values['name'], 'desc' => '', 'amt' => round($switcher_amt, 2), 'number' => $sku, 'qty' => $quantity, 'taxamt' => '', 'itemurl' => '', 'itemcategory' => '', 'itemweightvalue' => '', 'itemweightunit' => '', 'itemheightvalue' => '', 'itemheightunit' => '', 'itemwidthvalue' => '', 'itemwidthunit' => '', 'itemlengthvalue' => '', 'itemlengthunit' => '', 'ebayitemnumber' => '', 'ebayitemauctiontxnid' => '', 'ebayitemorderid' => '', 'ebayitemcartid' => ''); array_push($PaymentOrderItems, $Item); $total_items += round($switcher_amt, 2) * $switcher_qty; $order_items_own[] = round($switcher_amt, 2) * $switcher_qty; $ctr++; } /** * Add custom Woo cart fees as line items */ foreach (WC()->cart->get_fees() as $fee) { $Item = array('name' => $fee->name, 'desc' => '', 'amt' => number_format($fee->amount, 2, '.', ''), 'number' => $fee->id, 'qty' => 1, 'taxamt' => '', 'itemurl' => '', 'itemcategory' => '', 'itemweightvalue' => '', 'itemweightunit' => '', 'itemheightvalue' => '', 'itemheightunit' => '', 'itemwidthvalue' => '', 'itemwidthunit' => '', 'itemlengthvalue' => '', 'itemlengthunit' => '', 'ebayitemnumber' => '', 'ebayitemauctiontxnid' => '', 'ebayitemorderid' => '', 'ebayitemcartid' => ''); array_push($PaymentOrderItems, $Item); $total_items += $fee->amount * $Item['qty']; $order_items_own[] = $fee->amount * $Item['qty']; $ctr++; } /* * Get discount(s) */ //if (WC()->cart->get_cart_discount_total() > 0) { if ($order->get_total_discount() > 0) { // foreach (WC()->cart->get_coupons('cart') as $code => $coupon) { $Item = array('name' => 'Cart Discount', 'number' => 'Coupons', 'qty' => '1', 'amt' => '-' . number_format($order->get_total_discount(), 2, '.', '')); array_push($PaymentOrderItems, $Item); $total_discount += number_format($order->get_total_discount(), 2, '.', ''); $order_items_own[] = '-' . round($order->get_total_discount(), 2); // } } if (!$this->is_wc_version_greater_2_3()) { // if (WC()->cart->get_order_discount_total() > 0) { if ($order->get_total_discount() > 0) { //foreach (WC()->cart->get_coupons('order') as $code => $coupon) { $Item = array('name' => 'Order Discount', 'number' => 'Coupons', 'qty' => '1', 'amt' => '-' . number_format($order->get_total_discount(), 2, '.', '')); array_push($PaymentOrderItems, $Item); $total_discount += number_format($order->get_total_discount(), 2, '.', ''); $order_items_own[] = '-' . round($order->get_total_discount(), 2); // } } } if (isset($total_discount)) { $total_discount = round($total_discount, 2); } if ($this->send_items) { /* * Now that all the order items are gathered, including discounts, * we'll push them back into the Payment. */ $Payment['order_items'] = $PaymentOrderItems; /* * Now that we've looped and calculated item totals * we can fill in the ITEMAMT */ $Payment['itemamt'] = number_format($total_items - $total_discount, 2, '.', ''); } else { $Payment['order_items'] = array(); /* * Now that we've looped and calculated item totals * we can fill in the ITEMAMT */ $Payment['itemamt'] = number_format($total_items - $total_discount, 2, '.', ''); } /* * Then we load the payment into the $Payments array */ array_push($Payments, $Payment); $BuyerDetails = array('buyerid' => '', 'buyerusername' => '', 'buyerregistrationdate' => ''); // For shipping options we create an array of all shipping choices similar to how order items works. $ShippingOptions = array(); $Option = array('l_shippingoptionisdefault' => '', 'l_shippingoptionname' => '', 'l_shippingoptionlabel' => '', 'l_shippingoptionamount' => ''); array_push($ShippingOptions, $Option); $BillingAgreements = array(); $Item = array('l_billingtype' => '', 'l_billingagreementdescription' => '', 'l_paymenttype' => '', 'l_billingagreementcustom' => ''); array_push($BillingAgreements, $Item); $PayPalRequestData = array('SECFields' => $SECFields, 'SurveyChoices' => $SurveyChoices, 'Payments' => $Payments); if (isset($tax) && !empty($tax)) { $tax = $tax; } // Rounding amendment if (trim(number_format($paymentAmount, 2, '.', '')) !== trim(number_format($total_items - $total_discount + $tax + $shipping, 2, '.', ''))) { $diffrence_amount = $this->get_diffrent($paymentAmount, $total_items - $total_discount + $tax + $shipping); if ($shipping > 0) { $PayPalRequestData['Payments'][0]['shippingamt'] = round($shipping + $diffrence_amount, 2); } elseif ($tax > 0) { $PayPalRequestData['Payments'][0]['taxamt'] = round($tax + $diffrence_amount, 2); } else { $PayPalRequestData['Payments'][0]['itemamt'] = round($PayPalRequestData['Payments'][0]['itemamt'] + $diffrence_amount, 2); } } /* rounding amount */ $order_item_total = 0; foreach ($order_items_own as $keypayment => $valuepayment) { $order_item_total = $order_item_total + $valuepayment; } if ($shipping <= 0 && $tax <= 0) { $diffrence_amount_rounded = $this->get_diffrent($paymentAmount, $order_item_total); $PayPalRequestData['Payments'][0]['itemamt'] = round($PayPalRequestData['Payments'][0]['itemamt'] - $diffrence_amount_rounded, 2); $PayPalRequestData['Payments'][0]['amt'] = round($PayPalRequestData['Payments'][0]['amt'] - $diffrence_amount_rounded, 2); } // Pass data into class for processing with PayPal and load the response array into $PayPalResult $PayPalResult = $PayPal->SetExpressCheckout($PayPalRequestData); /* * Log API result */ $this->add_log('Test Mode: ' . $this->testmode); $this->add_log('Endpoint: ' . $this->API_Endpoint); $PayPalRequest = isset($PayPalResult['RAWREQUEST']) ? $PayPalResult['RAWREQUEST'] : ''; $PayPalResponse = isset($PayPalResult['RAWRESPONSE']) ? $PayPalResult['RAWRESPONSE'] : ''; $this->add_log('Request: ' . print_r($PayPal->NVPToArray($PayPal->MaskAPIResult($PayPalRequest)), true)); $this->add_log('Response: ' . print_r($PayPal->NVPToArray($PayPal->MaskAPIResult($PayPalResponse)), true)); /* * Error handling */ if ($PayPal->APICallSuccessful($PayPalResult['ACK'])) { $token = urldecode($PayPalResult["TOKEN"]); $this->set_session('TOKEN', $token); } /* * Return the class library result array. */ return $PayPalResult; }