Use PayPal Express

Use the getPayPalExpressCheckoutRedirectURL method to retrieve the RedirectURL by sending an order object with PAYPAL_EXPRESS payment method.

Workflow

  1. Authentication via login API method.

  2. Retrieve PayPal redirect URL. When you retrieve the PayPal redirect URL, apart from the token you will also receive 2 parameters that are encoded: billingDetails and deliveryDetails. These have to be base64_decoded and the information should be used in the placeOrder API call (email, billing address etc.).

  3. Place the order with PayPal Express using the token sent by PayPal.

Request parameters

Parameter
Type / Description

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 = 'fr';
//$Order->LocalTime = date('Y-m-d G:i:s');
$Order->CustomerReference = 'APITEST'; //uniqid('TESTCUSTOMER:');

$Product = new stdClass();
$Product->Code = 'my_subscription_1';
$Product->Quantity = 1;
$Order->Items[] = $Product;

$Order->Currency = 'EUR';

$Payment = new stdClass();
$Payment->Type = 'PAYPAL_EXPRESS';
$Payment->Currency = 'EUR';
$Payment->CustomerIP = '91.220.121.21';
$Payment->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 = '[email protected]';
$PayPalExpress->ReturnURL = 'http://' . $_SERVER['HTTP_HOST'] . '/api/place_order_api_soap_paypal_express_response.php';
$PayPalExpress->CancelURL = 'http://' . $_SERVER['HTTP_HOST'] . '/api/place_order_api_soap_paypal_express_response.php?cancel=true';

$Payment->PaymentMethod = $PayPalExpress;
$Order->PaymentDetails = $Payment;

// Call the method for retrieving Express Checkout redirect URL
$redirectUrl = $client->getPayPalExpressCheckoutRedirectURL($sessionID, $Order);
header('Location:' . $redirectUrl);

Place order with PayPal Express

Response parameters

Parameter
Type

PayPalExpressCheckoutRedirectURL

String

Last updated

Was this helpful?