How to setup PayPal Express Checkout with SilverStripe

The SilverStripe Payment module is really handy, its useful to have a payment module completely separate from ecommerce because it gives you so much freedom. The Payment-Test module is an ideal example of this. I used Payment-Test to create a basic booking system for instance, its a really good example of how to hook up a payment gateway to your site.

The Payment module supports a number of payment gateways, I have personally tried the DPS hosted payment (pxpay from memory), PayPal and also the PayPal Express Checkout gateway.

Install the Payment modules

Setting up a PayPal sandbox account and testing express checkout payments can be a bit of a rocky road, first you want to grab the Payment module and also the PayPal Express Checkout module and install them in the usual way.

The download for the express checkout module you can find here as payment_paypal_1.1.zip at time of writing.

After placing those in the root directory of your SilverStripe install run a /dev/build?flush=1.

Set up a PayPal sandbox account

Sign up to developer.paypal.com and once you are logged in go to 'Test Accounts' and create a new Preconfigured test account. We are going to create a test account for both a Seller and a Buyer.

So for the Buyer account I suggest you use the email address buyer@... - its important to note that this email address does not actually have to exist. Its useful to change your password to something sensible and also put some money in your account balance (the limit is $9999.00). Also, make sure your account type is 'Buyer' obviously.

For the Seller account use seller@... and its much the same as above except account type is 'Seller'.

Get PayPal seller sandbox account API details

Back on the 'Test Accounts' page in the PayPal sandbox you should see listed 2 test accounts, one seller and one buyer. Select the radio for the seller account and click to 'Enter Sandbox Test Site' - this is going to log you in to that seller account on sandbox.paypal.com (as opposed to developer.paypal.com).

Once you are logged in as the seller, click on 'Profile' and on the Profile page under 'Account Information' there is a link to 'API Access' which you should follow.

Option 2 on the API access page is for requesting API credentials, so click on the link in that box: 'View API Signature'.

You should now see a page with API signature, password and username - these are going to be used for configuration of the express checkout module.

Configure the Payment modules

There are quite a few configuration options for the Payment module so I am just going to put an example configuration for testing the paypal express checkout, its not a complete list of configuration options.

//Payment gateway
Payment::set_site_currency('NZD');
Geoip::$default_country_code = "NZ";
i18n::set_locale('en_NZ');
setlocale (LC_TIME, 'en_NZ@dollar', 'en_NZ.UTF-8', 'en_NZ', 'nz', 'nz');

Payment::set_supported_methods(array(
  'ChequePayment' => 'Cheque Or Pay On Site',
  'PayPalExpressCheckoutPayment' => 'PayPal Express (Credit Card)'
));

PayPalExpressCheckoutPayment::set_test_config_details(
  'your API username',
  'your API password',
  'your API signature'
);

PayPalPayment::set_test_mode('your seller account email address');
//PayPalPayment::set_account_email('your PayPal account email address');

In this example configuration Cheque payment and PayPal Express Checkout Payment are both enabled. The API credentials follow that and then we set the site into test mode.

Processing Test Payments

An easy way to test is by installing a SilverStripe ecommerce module and creating a few products. Simply add those products to your cart and proceed to checkout.

I have had some trouble with the PayPal sandbox, so I suggest you log in to your sandbox account on PayPal (developer.paypal.com) and then open the sandbox test site for your test buyer account in the same browser (sandbox.paypal.com) and leave those both open while you process these test payments.

Enter the email address of your buyer sandbox account on the checkout page and whatever address and other details you want. After filling out the checkout form and proceeding to payment your browser should be redirected to the PayPal express checkout hosted on PayPal.com.

Here is where you need to enter dummy credit card details to complete the payment. If you go back to your sandbox developer account on developer.paypal.com and view your test accounts, click on 'View details' for the buyer account. There should be a credit card number and an expiry date for this credit card, use those for processing the payment. The CVV number can be whatever you want (123 works for me).

If everything goes according to plan, after entering all your payment details you should be redirected back to SilverStripe and be viewing a breakdown of your order and payment.

Useful Links

Technical documentation- technical details about all the different payment options
Standard payment overview - details about standard paypal payments, the different standard options how to use PayPal
Variables for standard payments - API variables etc.
Non standard payments - other payment methods
All services
Setting up test accounts pdf
API PayPal express integration guide
API reference
Express Checkout API reference
Test credit card details