To start with, let me tell you integrating a Stripe into your project’s native language is not very hard rather than first understanding it’s flow and how does Stripe 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 because we think before starting with making payment events you should know something called WebHooks on Stripe.
WebHooks is nothing but it 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 has given us the WebHook feature for choosing some number of an event from all set of events to get notified, as per our requirement, like you can only select an event of “charge.succeeded” so you will only be notified of that particular event not other than it.
By WebHook we can get 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 four steps in 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
- Create a Customer from above card token on Stripe: https://stripe.com/docs/api#create_customer
- 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 either 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, which is provided on Stripe documentation https://stripe.com/docs/api#intro.
As soon as the customer subscribes to another plan then that particular customer is unsubscribed from the old plan and 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.