I come across a lot of PHP developers looking to build a recurring payments system with PayPal. I’ve found myself repeating this same information so many times I decided to write up a quick outline and some instruction on how to get this done.
Using these tools you can get a quality recurring payments system in place with a fully automated back-end without much hassle.
First, grab our PayPal PHP library from GitHub. It’s also available on Packagist and ready for Composer if you’re using that.
The API’s you’ll be working with specifically are as follows.
PayPal Express Checkout
- GetExpressCheckoutDetails (optional)
- DoExpressCheckoutPayment (optional / as-needed)
PayPal Payments Pro
- DoDirectPayment (optional / as-needed)
- CreateRecurringPaymentsProfile (same as with Express Checkout, but you’d include card details in the request.)
The CreateRecurringPaymentsProfile request is the one where all of the details about setting up the profile and everything would take place.
There is a caveat when dealing with a free trial that I see come up a lot. The CreateRecurringPaymentsProfile request contains specific parameters for trial amount, trial period, etc. These are only used when you’re offering a discounted trial period, though, and do have an actual amount to use for the trial period.
With a free trial you will actually just leave the trial parameters empty, and instead you’ll setup the regular parameters as required and you’ll set the start date of the profile for 1 month from the current date (or however long the trial is going to be for). This will create an active profile immediately, but it won’t charge anything until the profile start date, which is the date the first payment would trigger if the profile was not canceled or suspended by that time.On that note, you’ll also want to work with the following API’s to help manage the recurring profiles.
Finally, Instant Payment Notification (IPN) is what you’ll use to automate the processing of recurring payments, failed payments, canceled or suspended profiles (and anything else you might want to automate with regards to the PayPal account.)
We provide a PHP template for IPN that is rather rudimentary because it was developed years ago, but we still use it in almost every project we do as it’s fully functional and very useful. There are some other IPN libraries available on Packagist, though, that are more robust in terms of compatibility with PHP 5.3 and namespacing, etc, so you might be more interested in those solutions for IPN.
This is a very quick outline of what it would take to build a recurring payments system on PayPal Express Checkout and Website Payments Pro 3.0 (DoDirectPayment). If you’re already familiar with our PayPal PHP library you could have this all up and running in just a few hours at most. Even if you’ve never used it before it shouldn’t take you more than a day to get comfortable and start banging out recurring payments profiles!
Hi Mr. Angell,
I Dr. Beniamino Ferrari, from Italy, am using your fantastic PayPal library.
I am using PayPal recurring payments and I have created and deleted PayPal profile successfully using your PayPal PHP Library. I have some problem using UpdateRecurringPaymentsProfile (Internal Error – 10001).
Could you suggest me something?
That error is coming back saying that the request is simply timing out. Are you getting that in the sandbox or on the live server? Is it happening every time or just sometimes? Are you able to make calls to other API’s like GetBalance or anything else?
– I get this Error using a Sandbox.
– It happens every time.
– Yes, I am able to make other calls such as SetExpressCheckout, CreateRecurringPaymentsProfile and ManageRecurringPaymentsProfileStatus
Could you suggest me something?
Please submit a ticket here and attach the file you’re working with. I’ll see if I can reproduce the problem.
I have done the sandbox recurring payment(monthly) by express checkout with steps you have metnioned whihc is
DoExpressCheckoutPayment (optional / as-needed)
After payment successful merchant account activity summary have two payment which is payment from buyer name(status is completed) and Recurring payment from buyer name(status is created).While click the recurring payment it shows payment as 0 USD and next due date was not set correctly.Anything missing.please suggest me.
If you are only trying to setup the profile then you would not include DoExpressCheckoutPayment. So I guess I’m not entirely clear on the goal. Are you trying to process a payment when the user signs up for the profile, or are you trying to offer a free trial period, or what exactly is the goal?