SetExpressCheckout Examples
Notes
If the SetExpressCheckout() request is successful, you will receive a token back, which you need to store, and after which you need to call SetExpressCheckoutSuccessfulRedirect() to redirect the customer to PayPal to proceed.
Request
// Create instance of the phpPayPal class $paypal = new phpPayPal(); // Set the amount total for this order. $paypal->amount_total = '50.49'; // You can manually set the return and cancel URLs, or keep the one's pre-set in the class definition $paypal->return_url = 'http://www.example.com/successful_return.php'; $paypal->cancel_url = 'http://www.example.com/failed.php'; // Make the request $paypal->SetExpressCheckout(); // If successful, we need to store the token, and then redirect the user to PayPal if(!$paypal->_error) { // Store your token $_SESSION['token'] = $paypal->token; // Now go to PayPal $paypal->SetExpressCheckoutSuccessfulRedirect(); }
For more information on field descriptions, requirements and corresponding PayPal fields, see the parameters list.
Required Fields
return_urlcancel_urlamount_total
Optional Fields
currency_codeamount_maxpayment_action- default is 'sale'emaildescriptioncustominvoice_numberrequire_confirmed_shipping_addressno_shippingaddress_overridetokenlocal_codepage_stylehdr_imagehdr_border_colorbdr_back_colorhdr_flow_colorpayflow_colorchannel_typesolution_type- Shipping Address
shipping_nameshipping_address1shipping_address2shipping_cityshipping_stateshipping_postal_codeshipping_country_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:
token
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.