Table of Contents

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

Optional Fields

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:

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.

 

code/classes/phppaypal/examples/setexpresscheckout.txt · Last modified: 2008/03/02 23:09 (external edit)