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

PayPal's REST APIs are a very easy way to add e-Commerce functionality to your web project. There is a PHP SDK available for it, and there is a very good API Samples site that covers just about anything you would want to do with the SDK. However something that I thought was missing from this documentation was how to create your PayPal App and Sandbox accounts as well as the autoload.php file that's references but never actually included in the package.

This post is in response to this missing bit of documentation. I won't attempt to cover anything more than the official documentation covers since it does a really good job in that respect already.

To get started you need to head over to the Sandbox Accounts page and create two accounts that you will use during development and testing. These are for the Sandbox PayPal site. When creating these accounts you can assign the amount of money they will contain, whether they are verified, etc. You need at least the business account, but it's best to create a business and a personal account straight away. Remember these are just for the sandbox and will not affect the live PayPal servers.
ppacc1.png




Once the accounts are created, you can go over to the My Apps page and start creating an App by clicking the Create App button.
ppapp1.png


Fill in the App name and select the Sandbox developer account for the app, then click Create App.
ppapp2.png


The next screen will display your App's credentials, for now you can scroll past those all the way to the bottom and select the features that your app will use. It's best to select a minimal set of features rather than have everything available. Not all apps will have all features unlocked, this depends on your country. The Return URL is not necessary because you specify this when making a call to PayPal anyway. Click Save when done.
ppapp3.png


You should take note of the Client ID and Secret from your App's information page, this is used in your bootstrap.php file later.
ppapp4.png



Now you are almost ready to use the SDK. I opted for the 'direct download' approach without using Composer. This meant that I needed to use an auto-loader. The API examples keep referencing the autoload.php script in the PayPal directory from the SDK, but this is nowhere to be found, so I've created the following as a quick fix.
 PayPal/autoload.php
<?php
function PayPal_PHP_SDK_autoload($className)
{
$classPath = explode('\\', $className);
if ($classPath[0] != 'PayPal') {
return;
}
$classPath = array_slice($classPath, 1, 2);
$filePath = dirname(__FILE__) . '/' . implode('/', $classPath) . '.php';
if (file_exists($filePath)) {
require_once($filePath);
}
}
spl_autoload_register('PayPal_PHP_SDK_autoload');
?>


To make use of that in your code, simply use the following snippet:
 Your Code
require __DIR__ . '/PayPal/autoload.php';


Now you are ready for the rest of the SDK. Good luck!

-i

Please leave your comments or feedback below!
comments powered by Disqus
Other posts you may like...
Hi! You can search my blog here ⤵
Or browse the recent top tags...

Recent Blog Posts

Mini review of the Sonoff B1 WiFi light bulb

Coherence cache performance optimistic vs replicated schemes

Coherence and weblogic.xml in different types of J2EE web app deployments

Atari Lynx repair - Part 5 - McWill LED screen mod installation

Atari Lynx repair - Part 4 - screen cover replacement

Atari Lynx repair - Part 3 - broken speaker replacement

Atari Lynx repair - Part 2 - re-capping the motherboard

Atari Lynx repair - Part 1 - introduction and case disassembly

jPhotoFrame updated to version 0.3.1 with an image rotation correction utility

iOS 11 pre-GM mini review before it gets revealed next week

Recent Galleries

Atari Lynx repair - Part 5 - McWill LED screen mod installation

Atari Lynx repair - Part 4 - screen cover replacement

Atari Lynx repair - Part 2 - re-capping the motherboard

Atari Lynx repair - Part 3 - broken speaker replacement

Atari Lynx repair - Part 1 - introduction and case disassembly

Building a custom Atari Lynx game box storage shelf unit in a day

Protecting old Atari Lynx game boxes with snug fit plastic sleeves

Monument Valley 2 is released and does not disappoint

Space Food - Chocolate Ice Cream with Chocolate Chips

Legeod Star Wars AT-DP kit

Blogs and Friends

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity