Stripe Payment Gateway Integration
As Stripe becomes de facto payment gateway, its time to look closer at the Stripe Payment Gateway Integration. To begin with, let me tell you integrating a Stripe into your project’s native language is not at all difficult. Firstly you need to understand it’s flow and how does Stripe actually work. Here we will describe the functional flow of a Stripe subscription of a plan and Webhooks.
Before we move ahead, you should have little knowledge about the WebHooks on Stripe. It is because we think before starting with making payment events you should know something called WebHooks on Stripe.
WebHooks is just an HTTP Post Callback, that sends you a notification if any new event occurs on your Stripe account. In more easy language if Stripe Charges any customer then WebHook will send a notification of “charge.succeeded” to the registered WebHook URL. Same it does for “charge.failure”, “invoice.created” and much more you can find it out on Stripe documentation. It may be a case that for a single payment charge there may occur multiple events. Like as soon as charges have been deducted from the customer Stripe account an invoice for that charge is also created so for one customer we will get two WebHooks notification one for “charge.succeeded” and other for “invoice.creation.succeeded”.
Also, Stripe gives let’s you pick what all events you want to get notified, as per our requirement. Like you can only select an event of “charge.succeeded” so you will only be notified just for that particular event.
By WebHooks, We can be assured for charges success and invoice created for a particular customer. If our charges are in recursive order and also based on our project requirements.
To Subscribe to any plan on Stripe user has to follow below 4 steps in following order:
- Get Card Details of a user (at this point user is not a customer in terms of Stripe) (No need API for this)
- Create a Card Token from the above card details: https://stripe.com/docs/api#create_card_token
- Next create a Customer from above card token on Stripe: https://stripe.com/docs/api#create_customer
- Now create a Subscription to a plan with above Customer id: https://stripe.com/docs/api#create_subscription.
- Before using Subscription you have to create some plans on Stripe. It can be created from your Stripe dashboard or from calling Stripe API’s. https://stripe.com/docs/api#create_plan
Here you go now you can play with Stripe Subscription any time by keeping in mind the above four steps. All these steps can be accomplished practically by calling their respective API’s for them, provided on Stripe documentation.
As soon as the customer subscribes to another plan then that particular customer is unsubscribed from the old plan. The charges are cut on a basis on proration and the proration is taken care by Stripe so you don’t have to worry about it.
For more understanding, you can visit https://stripe.com/docs/api Stripe documentation and can read about Tokens, Customers, Subscriptions and Plans in respective order.