Use PayPal Express
Use the getPayPalExpressCheckoutRedirectURL method to retrieve the RedirectURL by sending an Order object with PAYPAL_EXPRESS payment method.
Workflow
Authentication via login API method.
Retrieve PayPal redirect URL. When you retrieve the PayPal redirect URL, apart from the token you will also receive 2 parameters that are encoded:
billingDetailsanddeliveryDetails. These have to be base64_decoded and the information should be used in the placeOrder API call (email, billing address etc.).Place the order with PayPal Express using the token sent by PayPal.
Request parameters
sessionID
Required (string)
Session identifier, the output of the Login method. Include sessionID into all your requests. 2Checkout throws an exception if the values are incorrect. The sessionID expires in 10 minutes.
Required (object) Object designed to collect all data necessary for an order, including billing, product/subscription plan and payment details. Use PAYPAL_EXPRESS as the payment method.
Request sample
Retrieve PayPal redirect URL
<?php
require ('PATH_TO_AUTH');
$Order = new stdClass();
$Order->Language = 'en';
$Order->CustomerReference = 'APITEST'; // set customer reference (optional)
$Order->Currency = 'EUR';
$Order->Items = array();
$Order->Items[0] = new stdClass();
$Order->Items[0]->Code = 'my_subscription_1'; // send the product code
$Order->Items[0]->Quantity = 1;
$Order->PaymentDetails = new stdClass();
$Order->PaymentDetails->Type = 'PAYPAL_EXPRESS'; // payment method, must be PAYPAL_EXPRESS for the express flow to take place.
$Order->PaymentDetails->Currency = 'EUR';
$Order->PaymentDetails->CustomerIP = '91.220.121.21';
$Order->PaymentDetails->FundingSource = 'Credit'; // set the funding source (optional), can be Standard (default, existing payment method) and Credit (the payment method will be PayPal credit)
$PayPalExpress = new stdClass();
$PayPalExpress->Email = 'customer@email.com';
$PayPalExpress->ReturnURL = 'http://' . $_SERVER['HTTP_HOST'] . '/api/place_order_api_json_paypal_express_response.php';
$PayPalExpress->CancelURL = 'http://' . $_SERVER['HTTP_HOST'] . '/api/place_order_api_json_paypal_express_response.php?cancel=true';
$Order->PaymentDetails->PaymentMethod = $PayPalExpress;
// Call the method for retrieving Express Checkout redirect URL
$jsonRpcRequest = new stdClass();
$jsonRpcRequest->jsonrpc = '2.0';
$jsonRpcRequest->method = 'getPayPalExpressCheckoutRedirectURL';
$jsonRpcRequest->params = array($sessionID, $Order);
$jsonRpcRequest->id = $i++;
$redirectUrl = callRPC($jsonRpcRequest, $host);
header('Location:' . $redirectUrl);Place order with PayPal Express
Response parameters
PayPalExpressCheckoutRedirectURL
String
Last updated
Was this helpful?