You decided to integrate your website with PayPal and you don’t know where to start. There are several ways to integrate your website with PayPal, and in this post I will explain you how to communicate with PayPal API and how to make PayPal Express Checkout payments.

PayPal payment options

There are several different payment options provided by PayPal:

  • PayPal Payments Standard (aka PayPal IPN)
  • PayPal Express Checkout – Explained in this post
  • Website Payments Pro
  • PayPal Payments Advanced

PayPal payment standard (PayPal IPN)

PayPal Payments Standard or PayPal IPN redirects customer to the PayPal after the checkout process is finished on your website. This method is really popular when implementing “Donate” buttons, and some other really easy straightforward transactions. Customer can make transaction without having PayPal account which is sometimes really useful. After payment, customer is redirected to the desired “success” page, and your website (store) is informed about completed payment. PayPal servers send IPN requests (yes, you can receive serveral requests for the same payment) to your website, and you should process requests and make changes in your database.

I do not suggest you to implement this method if you are running e-Commerce website with dynamic prices, discounts etc. Also, if there is communication error between PayPal server and your server, transaction in your database will never be marked as successful (because you never processed IPN request), and your customer will be disappointed because customer can’t access content on your website even he paid for it.

PayPal Express Checkout

If you are running e-Commerce website with dynamic prices, discount coupons, discount actions, and other features, then go ahead and implement PayPal Express Checkout. With Express Checkout, customer can login to their PayPal before checkout process on your site (this enables customer to prefil checkout forms on your site with data from PayPal, which is cool thus customer doesn’t have to write personal data every time), and after checkout process.

Express checkout doesn’t completely rely on IPN requests in order to make transaction. An order is stored immediately after payment is completed, and this happens while customer is actively engaged on your website. Simply said, when payment is complete, customer is redirected to your website, but your website is immediately informed by PayPal (not in a form of IPN request) weather transaction was successful or not. This enables your to change transaction status immediatelly after payment in your database, and to redirect user to the resource he bought (or to send email saying “Thank you for buying item”).

Express checkout doesn’t fully rely on IPN requests, but if you want to implement refund functionality or to make some order adjustments, you have to implement IPN listener too. This IPN listener will listen for IPN requests and will make transaction changes in your database, based on the content in IPN request. IPN listener is also required when you want to implement recurring payments.

Website Payments Pro

You embed credit card HTML form on your website, where customer has to enter credit card details. Customer is not redirected to the PayPal, and order is processed directly on your website (technically transaction is processed via PayPal but customer has no idea of that). As in Express Checkout, you have to implement IPN listener in order to support refund or order adjustments.


As previously said, in this post I will concentrate on Express Checkout payments. Here is nice diagram explaining Express Checkout flow:

Express Checout



Here is step by step explanation:

Step 1: Customer visits your page, and buys an item or several items. He clicks on the PayPal Pay button. SetExpressionCheckout REST service is called (you are calling PayPal’s API) in order to obtain PayPal TOKEN. At this stage you will not be redirected to the PayPal. When you obtain a TOKEN, you have to provide it in any subsequent API calls.

Step 2: REST service returns you the TOKEN. The TOKEN is valid some period of time and has to be provided in any further API call.

Step 3: Using provided TOKEN, you redirect a user to the PayPal (TOKEN is provided as HTTP GET parameter). User logs in to a PayPal account and confirms order.

Step 4: User is redirected from PayPal, to your page.

Step 5: User is reviewing and confirming an order. Depending on your requirements, you can skip process of displaying checkout details page (but you always have to call GetExpressCheckoutDetails method). If you want to implement order details and confirmation page on your website then you will call GetExpressCheckoutDetails API once user clicks “Confirm” button on confirmation page. If you don’t want to implement and display order confirmation page, then just call GetExpressCheckoutDetails API method and wait for result. You have to pass result from the GetExpressCheckoutDetails to DoExpressCheckout API method.

Step 6: DoExpressCheckoutPayment method is called in order to make a payment. If the payment is good, API method will return success, and if not, you will receive failure message.

Now when we have explain everything, let’s start with code.

PHP Library

In order to make integration with PayPal really easy, I implemented PHP library which you can download and use in your project. Library is available on my GitHub page.

Library contains only one PHP file (which can be imported simply by calling require_once function), and one certificate file for making HTTPS requests. On GitHub page you can find detailed steps about library installation.

Code example

Here is code which you can use in your project in order to implement PayPal integration:

The code above covers Step 1, Step 2, Step 3, Step 4.

If user confirmed order in PayPal, he will be redirected to the RETURN url specified in the order. Transaction still didn’t occurred, and we are preparing to call DoExpressCheckout API method. In order to call it, we have to call GetExpressCheckout API method.

In PHP which will generate RETURN URL page, you have to add the following code:

Let me now explain Step 5, Step 6. In Step 5, just call GetExpressionCheckoutDetails method, and as result you should get PAYERID parameter, which is required parameter for DoExpressionCheckout method. As last step, just call DoExpressionCheckoutPayment method:

Recurring Payments

Sometimes you would like to implement recurring payments. Recurring payment is payment which frequently happens in some specific time period. This could be really nice of you want to enable subscription for example magazine you are publishing, or specific resource or service you are providing. Good example of recurring payments are implemented in hosting plans, where you can check option to automatically renew hosting plan after one year.

In order to implement recurring payments, you have to call CreateRecurringPaymentsProfile API method. Here is example:

Once when a recurring payment profile is created, they are available/visible in PayPal account of the customer. In order to process recurring payment, you have to implement your IPN listener. Every time when new recurring payment occurs, PayPal will send you IPN request.

Here I want to write few words about PROFILEREFERENCE field. If you set this field when creating recurring payment profile, then this field and its value will be resent in IPN request once recurring payment occurs. If you set this field to be USER_ID from your database, then once you receive IPN request, you exactly know to whom this IPN request is belonging to, and you can extend subscription to this user, and send him an “Thank you” email or you can take any other action.

IPN Requests

In order to implement IPN listener, you can use one of the many available IPN listener PHP libraries. One I used in several projects is the following one.


In this post I wanted to share how to easily integrate your website with PayPal using Express Checkout Payments. If you have any questions or if you find my article useful please share it, so it can help anyone else. Also, please leave comments for suggestions.

How to integrate your website with PayPal API using PHP DuranLibrariesPHPProgrammingTutorialsExpress Checkout Payments,library,PayPal,PHP
Intro You decided to integrate your website with PayPal and you don't know where to start. There are several ways to integrate your website with PayPal, and in this post I will explain you how to communicate with PayPal API and how to make PayPal Express Checkout payments. PayPal payment options There are several different...