How to Implement PayPal Express Checkout for Digital Good in CakePHP - Part 126 Feb 2012 Add Comments Intermediate Level
PayPal Digital Goods for Express Checkout Provides a very easy and user friendly way for users to make payment. All transactions happen in an overlayer modal box, users will not need to leave your site during the whole process unlike other methods, where users will be redirected to PayPal official site to make payment.
In this tutorial, we will show you how to implement PayPal Express Checkout for Digital Good in CakePHP. We have divided this tutorial into two parts, first part we will roughly discuss the process of PayPal Digital Goods for Express Checkout, and write a model class which acts as a wrapper for PayPal API functions.
Table Of Content
The flow of PayPal Digital Goods for Express Checkout is discussed very clearly on the official page,
if you have never heard or used it before; we suggest you spend some time reading the documentation firstly.
To implement PayPal Digital Goods for Express Checkout in CakePHP, the simplest way is to implement two main API calls which are SetExpressCheckout and DoExpressCheckoutPayment.
Some notes to take before we get started:
- Intermedia knowledge of CakePHP is required, we will not go though the process of installing CakePHP, so you will need to have some basic understanding of CakePHP.
- This tutorial is based on CakePHP 1.3, but adapting it to CakePHP 2.x should be easy.
- PayPal API version used in this tutorial is 65.1 .
- We are using Name/Value Pair (NVP) API in this tutorial.
To communicate with PayPal, we use the concept of model class in CakePHP. This class will perform two main API calls to PayPal; it will return us needed information such as token and transaction id from PayPal upon on success, error message otherwise.
Copy the class below to your CakePHP directory app/models/paypal.php, and we will go through each function later.
- function PPHttpPost($methodName, $nvpStr): this function uses cURL to send post request to PayPal API server.
- function getPaypalUrl($token): this function returns correct PayPal Url based on application environment(sandbox or live).
- function setExpressCheckout($nvpStr): this function does API call(SetExpressCheckout),and it will set token if success, error messages if failed.
- function doExpressCheckoutPayment($nvpStr): this function does API call(DoExpressCheckoutPayment),and it will set transId if success, error messages if failed.
Now we have the core backend class to communicate with PayPal API server.
In next tutorial, we will go through the front part of implementing PayPal Express Checkout for Digital Good in CakePHP. And the front script will utilize the PayPal model class to
set and get information from PayPal.
Stay tuned for next tutorial.
Hopefully this simple tutorial helped you with your development.
If you like our post, please follow us on Twitter and help spread the word. We need your support to continue.
If you have questions or find our mistakes in above tutorial, do leave a comment below to let us know.