Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// 1. Autoload the SDK Package. This will include all the files and classes to your autoloader
require __DIR__ . '/PayPal-PHP-SDK/autoload.php';
// 2. Provide your Secret Key. Replace the given one with your app clientId, and Secret
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
'AYSq3RDGsmBLJE-otTkBtM-jBRd1TCQwFf9RGfwddNXWz0uFU9ztymylOhRS', // ClientID
'EGnHDxD_qRPdaLdZz8iCr8N7_MzF-YHPTkjs6NKYQvQSBngp4PTTVWkPZRbL' // ClientSecret
// 3. Lets try to create a Payment
$payer = new \PayPal\Api\Payer();
$amount = new \PayPal\Api\Amount();
$transaction = new \PayPal\Api\Transaction();
$redirectUrls = new \PayPal\Api\RedirectUrls();
$payment = new \PayPal\Api\Payment();
// 4. Make a Create Call and print the values
try {
echo $payment;
echo "\n\nRedirect user to approval_url: " . $payment->getApprovalLink() . "\n";
catch (\PayPal\Exception\PayPalConnectionException $ex) {
// This will print the detailed information on the exception.
echo $ex->getData();
Copy link

xbaheeg commented Aug 9, 2016


Copy link

carloaudino commented Apr 20, 2017


Copy link

dlepold commented Jul 14, 2017

Trying this i get an error:
Fatal error: Uncaught exception 'PayPal\Exception\PayPalConfigurationException' with message 'Getter function for 'links' in 'PayPal\Api\CreditCard' class should have a proper return type.' in /srv/www/project/html/pp_sdk/rest-api-sdk-php/l .............. etc-

Copy link

nikkolai14 commented Jul 20, 2017

This code is working! Thanks! :)

Copy link

vishaldu123 commented Jul 28, 2017

Hi Jay
How can we Configure it for sandbox?

Copy link

cyberguroo commented Apr 14, 2018


 $apiContext = new \PayPal\Rest\ApiContext(
         new \PayPal\Auth\OAuthTokenCredential(
         'xxxx', // ClientID
         'xxxx'      // ClientSecret
        'mode' => 'live'

More on this here

Copy link

PhilippeI commented Jan 21, 2019

Hi , thanks for this code,
I m new on paypal .. i try to implement the server rest solution on web site.
Question : the '\PayPal\Auth\OAuthTokenCredential(' on Sandbox context is for the seller .. ? xxx-facilitator@xxx.xx ?
Or the Buyer credential .. in this case your script is an 'Pay Button' emulation .. isn't it ?

Copy link

xicom commented Aug 21, 2019

When I am using the api with live credentials it gives me error like "Access token does not have required scope". Is there any setting that I need to do in merchant account?
My code is below -
$apiContext = new \PayPal\Rest\ApiContext(new \PayPal\Auth\OAuthTokenCredential('client id', 'secreat key'));
'mode' => 'live',

Please help

Copy link

vonuyvico commented Jan 23, 2021


Copy link

wgrnihao commented Jul 8, 2021


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment