* we'll add that to our $Payment array.
 */
$Payment['order_items'] = $PaymentOrderItems;
/**
 * Here we push our single $Payment into our $Payments array.
 */
array_push($Payments, $Payment);
/**
 * Now we gather all of the arrays above into a single array.
 */
$PayPalRequestData = array('SECFields' => $SECFields, 'Payments' => $Payments);
/**
 * Here we are making the call to the SetExpressCheckout function in the library,
 * and we're passing in our $PayPalRequestData that we just set above.
 */
$PayPalResult = $PayPal->SetExpressCheckout($PayPalRequestData);
/**
 * Now we'll check for any errors returned by PayPal, and if we get an error,
 * we'll save the error details to a session and redirect the user to an 
 * error page to display it accordingly.
 *
 * If all goes well, we save our token in a session variable so that it's
 * readily available for us later, and then redirect the user to PayPal
 * using the REDIRECTURLDIGITALGOODS returned by the SetExpressCheckout() function.
 *
 * This is an important difference between a regular Express Checkout
 * and a Digital Goods Express Checkout!  You need to make sure you use
 * the correct redirect URL to PayPal.
 */
if ($PayPal->APICallSuccessful($PayPalResult['ACK'])) {
    $_SESSION['paypal_token'] = isset($PayPalResult['TOKEN']) ? $PayPalResult['TOKEN'] : '';
require_once '../includes/config.php';
require_once '../autoload.php';
$PayPalConfig = array('Sandbox' => $sandbox, 'APIUsername' => $api_username, 'APIPassword' => $api_password, 'APISignature' => $api_signature, 'APIVersion' => '97.0', 'APISubject' => '', 'PrintHeaders' => $print_headers, 'LogResults' => $log_results, 'LogPath' => $log_path);
$PayPal = new angelleye\PayPal\PayPal($PayPalConfig);
$SECFields = array('token' => '', 'maxamt' => '200.00', 'returnurl' => $domain . 'standard/samples/DoExpressCheckoutPayment-Callback.php', 'cancelurl' => $domain . 'standard/cancel.php', 'callback' => $domain . 'standard/includes/paypal.nvp.callback.php', 'callbacktimeout' => '6', 'callbackversion' => '', 'reqconfirmshipping' => '0', 'noshipping' => '', 'allownote' => '1', 'addroverride' => '', 'localecode' => '', 'pagestyle' => '', 'hdrimg' => '', 'hdrbordercolor' => '', 'hdrbackcolor' => '', 'payflowcolor' => '', 'skipdetails' => '1', 'email' => '', 'solutiontype' => 'Sole', 'landingpage' => 'Login', 'channeltype' => '', 'giropaysuccessurl' => '', 'giropaycancelurl' => '', 'banktxnpendingurl' => '', 'brandname' => 'Angell EYE', 'customerservicenumber' => '555-555-5555', 'giftmessageenable' => '1', 'giftreceiptenable' => '1', 'giftwrapenable' => '1', 'giftwrapname' => 'Box with Ribbon', 'giftwrapamount' => '2.50', 'buyeremailoptionenable' => '1', 'surveyquestion' => '', 'surveyenable' => '1', 'buyerid' => '', 'buyerusername' => '', 'buyerregistrationdate' => '2012-07-14T00:00:00Z', 'allowpushfunding' => '');
// Basic array of survey choices.  Nothing but the values should go in here.
$SurveyChoices = array('Yes', 'No');
$Payments = array();
$Payment = array('amt' => '81.00', 'currencycode' => 'USD', 'itemamt' => '80.00', 'shippingamt' => '1.00', 'insuranceoptionoffered' => '', 'handlingamt' => '', 'taxamt' => '', 'desc' => 'This is a test order.', 'custom' => '', 'invnum' => '', 'notifyurl' => '', 'shiptoname' => '', 'shiptostreet' => '', 'shiptostreet2' => '', 'shiptocity' => '', 'shiptostate' => '', 'shiptozip' => '', 'shiptocountry' => '', 'shiptophonenum' => '', 'notetext' => 'This is a test note before ever having left the web site.', 'allowedpaymentmethod' => '', 'paymentaction' => 'Sale', 'paymentrequestid' => '', 'sellerpaypalaccountid' => '');
$PaymentOrderItems = array();
$Item = array('name' => 'Widget 123', 'desc' => 'Widget 123', 'amt' => '40.00', 'number' => '123', 'qty' => '1', 'taxamt' => '', 'itemurl' => 'http://www.angelleye.com/products/123.php', 'itemcategory' => '', 'itemweightvalue' => '', 'itemweightunit' => '', 'itemheightvalue' => '', 'itemheightunit' => '', 'itemwidthvalue' => '', 'itemwidthunit' => '', 'itemlengthvalue' => '', 'itemlengthunit' => '', 'ebayitemnumber' => '', 'ebayitemauctiontxnid' => '', 'ebayitemorderid' => '', 'ebayitemcartid' => '');
array_push($PaymentOrderItems, $Item);
$Item = array('name' => 'Widget 456', 'desc' => 'Widget 456', 'amt' => '40.00', 'number' => '456', 'qty' => '1', 'taxamt' => '', 'itemurl' => 'http://www.angelleye.com/products/456.php', 'itemcategory' => '', 'itemweightvalue' => '', 'itemweightunit' => '', 'itemheightvalue' => '', 'itemheightunit' => '', 'itemwidthvalue' => '', 'itemwidthunit' => '', 'itemlengthvalue' => '', 'itemlengthunit' => '', 'ebayitemnumber' => '', 'ebayitemauctiontxnid' => '', 'ebayitemorderid' => '', 'ebayitemcartid' => '');
array_push($PaymentOrderItems, $Item);
$Payment['order_items'] = $PaymentOrderItems;
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' => 'true', 'l_shippingoptionname' => 'UPS', 'l_shipingpoptionlabel' => 'UPS', 'l_shippingoptionamount' => '1.00', 'l_taxamt' => '0.00', 'l_insuranceamount' => '1.00');
array_push($ShippingOptions, $Option);
$Option = array('l_shippingoptionisdefault' => 'false', 'l_shippingoptionname' => 'UPS', 'l_shipingpoptionlabel' => 'UPS', 'l_shippingoptionamount' => '18.00', 'l_taxamt' => '0.00', 'l_insuranceamount' => '1.00');
array_push($ShippingOptions, $Option);
$BillingAgreements = array();
$Item = array('l_billingtype' => 'MerchantInitiatedBilling', 'l_billingagreementdescription' => 'Billing Agreement', 'l_paymenttype' => 'Any', 'l_billingagreementcustom' => '');
array_push($BillingAgreements, $Item);
$PayPalRequest = array('SECFields' => $SECFields, 'SurveyChoices' => $SurveyChoices, 'Payments' => $Payments, 'ShippingOptions' => $ShippingOptions);
$_SESSION['SetExpressCheckoutResult'] = $PayPal->SetExpressCheckout($PayPalRequest);
echo '<a href="' . $_SESSION['SetExpressCheckoutResult']['REDIRECTURL'] . '">Click here to continue.</a><br /><br />';
echo '<pre />';
print_r($_SESSION['SetExpressCheckoutResult']);
 public function setEC()
 {
     //set creentials
     $this->set_credentials();
     $PayPalConfig = array('Sandbox' => $this->payment_mode, 'APIUsername' => trim($this->api_username), 'APIPassword' => trim($this->api_password), 'APISignature' => trim($this->api_signature), 'APIVersion' => '97.0', 'APISubject' => '', 'PrintHeaders' => false, 'LogResults' => false, 'LogPath' => '');
     $PayPal = new angelleye\PayPal\PayPal($PayPalConfig);
     $SECFields = array('token' => '', 'maxamt' => '', 'returnurl' => $this->_return_url, 'cancelurl' => $this->_cancel_url, 'callback' => '', 'callbacktimeout' => '', 'callbackversion' => '', 'reqconfirmshipping' => '0', 'noshipping' => '', 'allownote' => '1', 'addroverride' => '1', 'localecode' => '', 'pagestyle' => isset($this->_page_design['pagestyle']) ? $this->_page_design['pagestyle'] : '', 'hdrimg' => isset($this->_page_design['hdrimg']) ? $this->_page_design['hdrimg'] : '', 'logoimg' => isset($this->_page_design['logoimg']) ? $this->_page_design['logoimg'] : '', 'cartbordercolor' => isset($this->_page_design['cartbordercolor']) ? $this->_page_design['cartbordercolor'] : '', 'hdrbordercolor' => isset($this->_page_design['hdrbordercolor']) ? $this->_page_design['hdrbordercolor'] : '', 'hdrbackcolor' => isset($this->_page_design['hdrbackcolor']) ? $this->_page_design['hdrbackcolor'] : '', 'payflowcolor' => isset($this->_page_design['payflowcolor']) ? $this->_page_design['payflowcolor'] : '', 'skipdetails' => '', 'email' => '', 'solutiontype' => 'Sole', 'landingpage' => 'Login', 'channeltype' => 'Merchant', 'giropaysuccessurl' => '', 'giropaycancelurl' => '', 'banktxnpendingurl' => '', 'brandname' => isset($this->_page_design['channel_name']) ? $this->_page_design['channel_name'] : '', 'customerservicenumber' => '', 'giftmessageenable' => '', 'giftreceiptenable' => '', 'giftwrapenable' => '', 'giftwrapname' => 'Box with Ribbon', 'giftwrapamount' => '', 'buyeremailoptionenable' => '1', 'surveyquestion' => '', 'surveyenable' => '1', 'buyerid' => '', 'buyerusername' => '', 'buyerregistrationdate' => '', 'allowpushfunding' => '');
     // Basic array of survey choices.  Nothing but the values should go in here.
     $SurveyChoices = array('Yes', 'No');
     $PaymentOrderItems = array();
     $itemTotalValue = 0;
     $taxTotalValue = 0;
     foreach ($this->_cart as $val) {
         $itemTotalValue += $val['price'] * $val['qty'];
         $Item = array('name' => $val['name'], 'desc' => strip_tags($val['desc']), 'amt' => $val['price'], 'number' => $val['options']['product_id'], 'qty' => $val['qty'], 'taxamt' => 0, 'itemurl' => '', 'itemcategory' => '', 'itemweightvalue' => '', 'itemweightunit' => '', 'itemheightvalue' => '', 'itemheightunit' => '', 'itemwidthvalue' => '', 'itemwidthunit' => '', 'itemlengthvalue' => '', 'itemlengthunit' => '', 'ebayitemnumber' => '', 'ebayitemauctiontxnid' => '', 'ebayitemorderid' => '', 'ebayitemcartid' => '');
         array_push($PaymentOrderItems, $Item);
     }
     if (!empty($this->_discount) && $this->_discount != 0) {
         $itemTotalValue += -round_amount($this->_discount);
         $discount_apply = array('name' => 'Discount', 'amt' => -round_amount($this->_discount), 'number' => '', 'qty' => 1, 'taxamt' => 0);
         array_push($PaymentOrderItems, $discount_apply);
     }
     if (!empty($this->_coupon) && $this->_coupon != 0) {
         $itemTotalValue += -round_amount($this->_coupon);
         $coupon_apply = array('name' => 'Coupon', 'amt' => -round_amount($this->_coupon), 'number' => '', 'qty' => 1, 'desc' => $_SESSION['coupon_details']['code'], 'taxamt' => 0);
         array_push($PaymentOrderItems, $coupon_apply);
     }
     $shippingTotal = round_amount($this->_shipping_charge);
     $taxTotalValue = round_amount($this->_tax);
     $discountTotal = round_amount($this->_discount);
     $orderTotal = $itemTotalValue + $taxTotalValue + $shippingTotal;
     $orderTotal = $orderTotal - $this->_shipping_discount;
     $Payments = array();
     $Payment = array('amt' => round_amount($orderTotal), 'currencycode' => 'USD', 'itemamt' => $itemTotalValue, 'shippingamt' => $shippingTotal, 'shipdiscamt' => -$this->_shipping_discount, 'insuranceoptionoffered' => '', 'handlingamt' => '', 'redeemedofferamount' => '', 'taxamt' => $taxTotalValue, 'desc' => '', 'custom' => '', 'invnum' => '', 'notifyurl' => $this->_notify_url, 'shiptoname' => $this->address_fill('S', 'name'), 'shiptostreet' => $this->address_fill('S', 'address'), 'shiptocity' => $this->address_fill('S', 'city'), 'shiptostate' => $this->address_fill('S', 'state'), 'shiptozip' => $this->address_fill('S', 'zip_code'), 'shiptocountry' => $this->address_fill('S', 'country'), 'shiptophonenum' => $this->address_fill('S', 'phone'), 'notetext' => '', 'allowedpaymentmethod' => 'InstantPaymentOnly', 'paymentaction' => 'Sale', 'paymentrequestid' => '', 'sellerpaypalaccountid' => '');
     $Payment['order_items'] = $PaymentOrderItems;
     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' => 'MerchantInitiatedBilling', 'l_billingagreementdescription' => 'Billing Agreement', 'l_paymenttype' => 'Any', 'l_billingagreementcustom' => '');
     array_push($BillingAgreements, $Item);
     $PayPalRequest = array('SECFields' => $SECFields, 'SurveyChoices' => $SurveyChoices, 'BillingAgreements' => $BillingAgreements, 'Payments' => $Payments);
     $SetExpressCheckoutResult = $PayPal->SetExpressCheckout($PayPalRequest);
     //echo '<a href="' . $SetExpressCheckoutResult['REDIRECTURL'] . '">Click here to continue.</a><br /><br />';
     //echo '<pre />';
     return $SetExpressCheckoutResult;
 }