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...
 PHP
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.
 PHP
$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:
 PHP
$apiContext = new ApiContext(new OAuthTokenCredential($paypalId, $paypalSecret));
$apiContext->setConfig([
'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.

-i

Hope you found this post useful...

...so please read on! I love writing articles that provide beneficial information, tips and examples to my readers. All information on my blog is provided free of charge and I encourage you to share it as you wish. There is a small favour I ask in return however - engage in comments below, provide feedback, and if you see mistakes let me know.

If you want to show additional support and help me pay for web hosting and domain name registration, donations, no matter how small, are always welcome!

Use of any information contained in this blog post/article is subject to this disclaimer.
comments powered by Disqus
Other posts you may like...