Developing recurring payment on WordPress with Stripe

Developing recurring payment on WordPress with Stripe

Before you have the wrong expectation, I will be clear here and now. I am not sharing a tutorial to develop Stripe recurring payments on WordPress. I am not going to share any codes either. If you’re expecting such a tutorial or functions, this is the wrong page.

Let me start with the reason I develop such a function on WordPress. One of my clients needs to collect recurring payments through one of his WordPress sites. But, there are no plugins out there which meet their need. The closest one, though it’s a paid one, is heavy, sluggish and slow. This is why they ask me for building it.

Yet, I don’t want to do this from scratch. It will take too much time. I try to follow the DRY principle as much as possible. I look for a decent WordPress plugin for Stripe.

After searching for a while, we agree to use this one:

It’s a decent plugin. Unfortunately, it didn’t provide recurring payment functions we need. So, I must build the recurring payment function myself.

Fortunately, the plugin’s codes are using PHP with the object-oriented approach. The code structure is easy to understand. The flow is clear to follow. It even provides a class for writing the debug message on the log file. 

Even when I need to debug an array, the debugger class already provided me with a method to do so. It saves my time to write the method on my own. Somehow, the “print_r” method doesn’t work. Maybe I miss something here, not sure though.

With some readings on Stripe Subscription API documentation, along with a good understanding of the existing codes on the plugin, I manage to combine both of them to work together, to provide recurring payment handled by Subscription API object.

I’ll share a bit about how I added this recurring payment function.

  • The first step is to understand the existing plugin codes. Since the plugin developer writes their codes with the object-oriented approach, it’s easier for me to finish this first step.
  • After understanding existing codes, I read the Stripe Subscription API documentation and their getting started tutorial.
  • Then, I start writing my codes to retrieve the existing Stripe customer object ID. According to Stripe documentation, this is mandatory for creating a Subscription object.
  • It didn’t go smoothly. The existing Customer object didn’t have a payment method attribute. At this point, I read more about updating existing customer object and add the attribute. Fortunately, the payment method object is already there.
  • Once I am sure other requirements to create Subscription are met, I write the codes to create a Subscription object, with monthly frequency.
  • At last, Stripe will handle the rest.

The codes are already available on Stripe documentation. Not only the provided example for PHP but they also give examples in Ruby and Java. Although once you grasp the concept, any language is just a matter of learning the syntax and convention.

Now, this enhanced plugin can handle the monthly recurring payment. It’s light, fast, and meets all the owner’s needs.

Veerotech Web Hosting: 50% off for first month with code: 1stmonth50. Plus free $10 credit. Click here