Igor's Blog

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

, , , ,
About — I'm an enthusiastic software engineer and consultant interested in many fields including J2EE, programming, electronics, 3D printing, video games, wood working and gardening.
See my Resume for more information.
The views expressed in this blog are my own and not those of my employer.
comments powered by Disqus
My other posts you may like...
Programming, DIY, Games, Hacks, Tech and more.
Follow me on...
Current and Past Projects
See my Resume

Subscribe


RSS Feed

My Other Web Sites

Igor and Elise's Travels
Riverside Expressway Cam
StrFunc() Online
300 George St Blogumentary
Guru JSON-RPC Tester
Extrudifier Object Designer

Recent Blog Posts

NeoOffice Viewer macOS Word Document viewer vs Preview and Microsoft Word

Importance of cleaning the internal fans and heatsinks in a MacBook Pro

Adding an email subscribe feature to your Blog with Blogtrottr

How to remove Google's logo from your G Suite applications

Pedestal fan transformed into a ceiling fan

Testing the Velvet WiFi Hotshot signal strength

Improving slow download speeds on the PS4 and PSN

Add batch image resize functionality to macOS using Automator

Show transfer percentage and speed when copying files in Linux and Bash

So I finally got to try eating some space food

Recent Galleries

Space Food - Chocolate Ice Cream with Chocolate Chips

Legeod Star Wars AT-DP kit

DIY spare parts computer build with a RAIDMAX Anura case

Fake 'Lepin' brand Lego packaging

Hardwood garden bench with clear resin void filler

Fixing a 3D printer extruder that stopped heating up

Easily increase disk space in a Lenovo Ideapad 100S 14" laptop with an M.2 SSD

Making a multi-piece 3D printed solder spool holder stand

DIY indoor apartment grow light wiring

Good Friday Electronics fun Easter Bunny LED PCB Kit IBEABU-01.0

Top Categories

Blogs I follow

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth

Friends

RAWS Parts Online
Alpha Dimensions Hosting
Kristensen Photography
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity
Please follow me on...