Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

The PayPal SDK makes it really easy to integrate with PayPal. Unfortunately, the out of the box examples are not designed to work with Google App Engine. Since the PayPal PHP SDK writes to the local file system it will not work without a few configuration changes. Luckily these changes are minor.

I've written about the PayPal SDK in the past, there's an article about a quick start with the PayPal PHP SDK. Check that out if you need help getting started with creating your PayPal App, getting your App ID and App Secret, etc.

For the most part you use the PayPal SDK as is. The only change required is when creating the API Context.

First make sure you are using the required classes from the SDK...
use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;

Next some variables are required to hold your App's data, fill these in as appropriate to your App and set whether you're using the 'live' or 'sandbox' environments.
$paypalId = 'YOUR_APP_ID_HERE';
$paypalSecret = 'YOUR_APP_SECRET_HERE'
$paypalMode = 'sandbox'; /* set to 'live' to use the live environment */

Next the API Context can be created like so:
$apiContext = new ApiContext(new OAuthTokenCredential($paypalId, $paypalSecret));
'mode' => $paypalMode,
'log.LogEnabled' => false,
'validation.level' => 'log',
'cache.enabled' => true,
'cache.FileName' => 'gs://#default#/PayPal.cache'

The two notable settings here are - 1) logging is disabled 2) cache file name is set to write to the default bucket in the Cloud DataStore.

I could not get logging to work with the Cloud DataStore even though there is a way to specify the log file name. However it is possible to create your own custom logger. I've not tried doing that and once I do I'll write another article on how to do it with App Engine.

After creating the API Context as above, use the SDK as you would normally.


A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. Use of any information from my blog posts should be at own risk and I do not hold any liability towards any information misuse or damages caused by following any of my posts.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
Hi! You can search my blog here ⤵
NOTE: (2022) This Blog is no longer maintained and I will not be answering any emails or comments.

I am now focusing on Atari Gamer.