$_SESSION['ShipToPhoneNumber'] = isset($Payment['SHIPTOPHONENUM']) ? $Payment['SHIPTOPHONENUM'] : '';
    $_SESSION['ShipToAddressStatus'] = isset($Payment['ADDRESSSTATUS']) ? $Payment['ADDRESSSTATUS'] : '';
    $_SESSION['CustomerNotes'] = isset($Payment['NOTETEXT']) ? $Payment['NOTETEXT'] : '';
    if ($_SESSION['ShipToCountryCode'] != 'US' && $_SESSION['ShipToState'] == '') {
        $_SESSION['ShipToState'] = $_SESSION['ShipToCountryCode'];
    }
}
$_SESSION['ShippingCalculationMode'] = isset($GECDResult['SHIPPINGCALCULATIONMODE']) ? $GECDResult['SHIPPINGCALCULATIONMODE'] : '';
$_SESSION['InsuranceOptionSelected'] = isset($GECDResult['INSURANCEOPTIONSELECTED']) ? $GECDResult['INSURANCEOPTIONSELECTED'] : '';
$_SESSION['ShippingOptionIsDefault'] = isset($GECDResult['SHIPPINGOPTIONISDEFAULT']) ? $GECDResult['SHIPPINGOPTIONISDEFAULT'] : '';
$_SESSION['ShippingOptionAmount'] = isset($GECDResult['SHIPPINGOPTIONAMOUNT']) ? $GECDResult['SHIPPINGOPTIONAMOUNT'] : '';
$_SESSION['ShippingOptionName'] = isset($GECDResult['SHIPPINGOPTIONNAME']) ? $GECDResult['SHIPPINGOPTIONNAME'] : '';
echo '<b>GetExpressCheckoutDetails</b><br /><pre>';
print_r($GECDResult);
echo '<br /><br /></pre>';
$DECPFields = array('token' => $_SESSION['SetExpressCheckoutResult']['TOKEN'], 'payerid' => $GECDResult['PAYERID'], 'returnfmfdetails' => '1', 'giftmessage' => '', 'giftreceiptenable' => '', 'giftwrapname' => '', 'giftwrapamount' => '', 'buyermarketingemail' => '', 'surveyquestion' => '', 'surveychoiceselected' => '', 'allowedpaymentmethod' => '', 'buttonsource' => '');
$Payments = array();
$Payment = array('amt' => number_format(80 + $_SESSION['ShippingOptionAmount'], 2), 'currencycode' => 'USD', 'itemamt' => '80.00', 'shippingamt' => $_SESSION['ShippingOptionAmount'], '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', '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', 'itemweightvalue' => '', 'itemweightunit' => '', 'itemheightvalue' => '', 'itemheightunit' => '', 'itemwidthvalue' => '', 'itemwidthunit' => '', 'itemlengthvalue' => '', 'itemlengthunit' => '', 'ebayitemnumber' => '', 'ebayitemauctiontxnid' => '', 'ebayitemorderid' => '', 'ebayitemcartid' => '');
array_push($PaymentOrderItems, $Item);
$Payment['order_items'] = $PaymentOrderItems;
array_push($Payments, $Payment);
$UserSelectedOptions = array('shippingcalculationmode' => '', 'insuranceoptionselected' => '', 'shippingoptionisdefault' => '', 'shippingoptionamount' => '', 'shippingoptionname' => '');
$PayPalRequest = array('DECPFields' => $DECPFields, 'Payments' => $Payments);
$_SESSION['PayPalResult'] = $PayPal->DoExpressCheckoutPayment($PayPalRequest);
echo '<b>DoExpressCheckoutPayment</b><br /><pre>';
print_r($_SESSION['PayPalResult']);
echo '<br /><br /></pre>';
<?php

// Include required library files.
require_once '../includes/config.php';
require_once '../autoload.php';
// Create PayPal object.
$PayPalConfig = array('Sandbox' => $sandbox, 'APIUsername' => $api_username, 'APIPassword' => $api_password, 'APISignature' => $api_signature, 'PrintHeaders' => $print_headers, 'LogResults' => $log_results, 'LogPath' => $log_path);
$PayPal = new angelleye\PayPal\PayPal($PayPalConfig);
// Prepare request arrays
$DECPFields = array('token' => '', 'payerid' => '', 'returnfmfdetails' => '', 'giftmessage' => '', 'giftreceiptenable' => '', 'giftwrapname' => '', 'giftwrapamount' => '', 'buyermarketingemail' => '', 'skipbacreation' => '', 'usesessionpaymentdetails' => '', 'surveyquestion' => '', 'surveychoiceselected' => '', 'allowedpaymentmethod' => '');
$Payments = array();
$Payment = array('amt' => '', 'bucketcategorytype' => '', 'currencycode' => '', 'itemamt' => '', 'shippingamt' => '', 'shippingdiscamt' => '', 'insuranceoptionoffered' => '', 'handlingamt' => '', 'taxamt' => '', 'desc' => '', 'custom' => '', 'invnum' => '', 'notifyurl' => '', 'shiptoname' => '', 'shiptostreet' => '', 'shiptostreet2' => '', 'shiptocity' => '', 'shiptostate' => '', 'shiptozip' => '', 'shiptocountrycode' => '', 'shiptophonenum' => '', 'notetext' => '', 'allowedpaymentmethod' => '', 'paymentaction' => '', 'paymentrequestid' => '', 'sellerpaypalaccountid' => '', 'sellerid' => '', 'sellerusername' => '', 'sellerregistrationdate' => '', 'softdescriptor' => '');
$PaymentOrderItems = array();
$Item = array('name' => '', 'desc' => '', 'amt' => '', 'number' => '', 'qty' => '', 'taxamt' => '', 'itemurl' => '', '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);
$UserSelectedOptions = array('shippingcalculationmode' => '', 'insuranceoptionselected' => '', 'shippingoptionisdefault' => '', 'shippingoptionamount' => '', 'shippingoptionname' => '');
$PayPalRequestData = array('DECPFields' => $DECPFields, 'Payments' => $Payments, 'UserSelectedOptions' => $UserSelectedOptions);
// Pass data into class for processing with PayPal and load the response array into $PayPalResult
$PayPalResult = $PayPal->DoExpressCheckoutPayment($PayPalRequestData);
// Write the contents of the response array to the screen for demo purposes.
echo '<pre />';
print_r($PayPalResult);
 public function doEC()
 {
     $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);
     $DECPFields = array('token' => $this->_token, 'payerid' => $this->_payer_id, 'returnfmfdetails' => '', 'giftmessage' => '', 'giftreceiptenable' => '', 'giftwrapname' => '', 'giftwrapamount' => '', 'buyermarketingemail' => '', 'surveyquestion' => '', 'surveychoiceselected' => '', 'allowedpaymentmethod' => 'InstantPaymentOnly', 'buttonsource' => '');
     $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, 'taxamt' => 0, 'desc' => $_SESSION['coupon_details']['code']);
         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' => 'This is a test order.', 'custom' => http_build_query($this->_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' => 'This is a test note before ever having left the web site.', 'allowedpaymentmethod' => 'InstantPaymentOnly', 'paymentaction' => 'Sale', 'paymentrequestid' => '', 'sellerpaypalaccountid' => '');
     $Payment['order_items'] = $PaymentOrderItems;
     array_push($Payments, $Payment);
     $UserSelectedOptions = array('shippingcalculationmode' => '', 'insuranceoptionselected' => '', 'shippingoptionisdefault' => '', 'shippingoptionamount' => '', 'shippingoptionname' => '');
     $PayPalRequest = array('DECPFields' => $DECPFields, 'Payments' => $Payments);
     $PayPalResult = $PayPal->DoExpressCheckoutPayment($PayPalRequest);
     return $PayPalResult;
 }