Implementing Subscriptions/Recurring Payments using Stripe

Published On: 18 August 2022.By .
  • Digital Engineering
  • Ecommerce

What is Stripe ?

Stripe is a payment gateway which provides traders the opportunity to sell their products on their platforms and charge their customers based on the product. It provides users the opportunity to sell their product globally with complete security over the transaction. Traders can sell their product in the form of orders as well as subscriptions.

Why Stripe ?

Stripe provides users the opportunity to make transactions in multiple international currencies.  Besides that traders can integrate stripe even without the use of code.  Stripe provides the option to easily manage payments easily and you can integrate stripe on all the platforms. As there is a large community for stripe so you can get your issue resolved easily.

Advantages of Stripe

  • You can setup stripe easily without any setup fee. It has a fixed rate for all payments.
  • Supports multiple currencies and payment methods
  • Greatly customizable.
  • Easy to learn and setup.

Disadvantages of Stripe

  • High Charge
  • Stripe continuously surveillance its user’s accounts. It checks their daily working and habits, after reviewing the account if they find it quite risky, then they hold or cancel your account, without any permission.

Why use Subscriptions ?

Subscription provide customers the opportunity to buy products in a periodical state. Like there are many products such as as dairy products like milk that one needs to buy daily so instead of making an order for milk they can take a subscription in which they will get milk daily and will be charged automatically bu the payment gateway. they can upgrade or cancel the subscription anytime as well.

How Stripe manages subscriptions ?

Stripe manages subscriptions in various steps:

  1. Register our Customers on stripe.
  2. Add Payment Methods and link them to their respective customers.
  3. Create Products and their respective Prices.
  4. Create Subscription linked with a customer and price.
  5. Every subscription has multiple Invoices while the user needs to pay to continue their services.

Database Architecture for making Stripe Subscriptions

  1. The Users table will be responsible for storing the users information. This information will be directly stored in stripes customer database as well. Stripe will return an id for every customer which will be stored in stripe_customer_id.
  2. The products table will be responsible for storing the product details and these details will be stored in the stripes product  table as well. We can update the information later using the stripe_product_id which is the unique id for every product.
  3. The Prices table will be linked to the product table and every price stored here will have a country code corresponding to the price in that country. We can update the prices in stripe using the stripe_price_id. The type field in prices table will be used to specify whether the given price is for basic subscription plan or pro subscription plan.
  4. Once user decides to buy a subscription using a particular product and price we will create a subscription plan for that user in stripe. And after that we will store the subscription details in our database. If we want to fetch details for a given subscription we can store the subscription id in stripe_subscription_id.
  5. For every subscription created an invoice will be created by stripe as well and we will use that invoice id to fetch invoice details we will create the invoices on our end as well.  We will provide user an invoice url to pay invoices directly on stripe.

Communications between the app and stripe

Once the invoice is created user can pay the subscription by clicking on invoice url link. If user pays the invoice then the invoice gets paid on stripe. There are several tasks that are handled using cron jobs.

We can run the cron jobs using task scheduler. As the subscriptions status updates on stripe they will be updated on our database as well.  The invoices will be updated along with the subscriptions as well.

Upgrade or cancel subscription

For upgrading a subscription we will first check that user has already paid all the active invoices. If user has paid all the invoices of that subscription then user is eligible for upgrading the subscription. Then we will send the old price id, subscription id and new price id to stripe. Stripe will remove the old price id and link the subscription with new price id.

For cancelling a subscription we will first check that user has already paid all the active invoices. If user has paid all the invoices of that subscription then user is eligible for cancelling the subscription. Then we will call stripe for cancelling the subscription and the subscription will be cancelled immediately and  no new invoices will generate for those subscription.

how do payment gateways manage recurring payments without authentication from user

Payment Processors transfer the data between customer, merchants, issuing bank and acquiring bank.

Payment Gateways or Payment Service Providers transfer the transaction details to the payment processors. They are used to ensure faster, safer and seamless online transactions. They are not responsible for transferring the funds instead they approve that the funds are transferred from customer’s account to merchant’s account in a secure way.

Conclusion

Stripe is an excellent payment gateway and we can use it in many ways to collect transactions like invoicing, subscriptions or payment intents. Stripe supports multiple platforms and multiple languages which makes it easier to integrate on all the platforms. Let us know your valuable thought about why Stripe is a better payment gateway? Share in the comments below.

Reference Links

Related content

That’s all for this blog

Go to Top