DoExpressCheckoutPayment Examples
Notes
NOTICE - When adding items, the amount_items variable will be calculated automatically, but the amount_tax and amount_total variables are NOT calculated automatically based on the items amount and tax values. This is because there can be certain cases when the amount_tax will not just be the amount of all the tax amounts of the items.
Please keep in mind, if ANY of the items have a tax amount set, then you MUST set amount_tax.
Request
// Create instance of the phpPayPal class $paypal = new YipPayPal(); // Set the required fields $paypal->token = $_SESSION['token']; $paypal->payer_id = $_SESSION['payer_id']; // Final total amount and shipping $paypal->amount_total = '50.00'; $paypal->amount_shipping = '10.00'; // Add items to the PayPal transaction (not required) // addItem() function FORMAT - $name, $number, $quantity, $amount_tax, $amount $paypal->addItem('Item Name', 'N102', 1, 0, 20.00); $paypal->addItem('Item Example 2 Name', 'N101', 2, 0, 10.00); // Make the request $paypal->DoExpressCheckoutPayment();
For more information on field descriptions, requirements and corresponding PayPal fields, see the parameters list.
Required Fields
tokenpayment_action(defaults to 'Sale' if not set)payer_idamount_total
Optional Fields
descriptioncustominvoicebutton_sourcenotify_urlamount_items- Total amount of all items, calculated automatically when items are addedamount_shippingamount_handlingamount_tax- Tax amount of all items, NOT calculated automatically when items are added, see notes at topcurrency_code- addItem
namenumberquantityamount_taxamount
shipping_nameshipping_address1shipping_address2shipping_cityshipping_stateshipping_country_codeshipping_postal_codeshipping_phone_number
Response
The class instance will always provide the raw PayPal response to the Response array. During testing (sandbox mode), you can simply output the value of Response to see the PayPal response.
$paypal->Response; // Display the response print_r($paypal->Response);
Success Response
If the transaction was successful, PayPal will return the following values:
tokentransaction_idtransaction_typepayment_typeorder_timeamount_totalcurrency_codeamount_feeamount_settleamount_taxexchange_ratepayment_statuspayment_pending_reasonpayment_reason_code
Error Response
If there was an exception with the interaction with PayPal, _error will return true.
See the error documentation for details about error return values and procedures.