Feasibility study — Stripe subscription with checkout
Feasibility study — Stripe subscription with checkout
Sample: https://508st.sse.codesandbox.io/
Let us try to achieve a specific billing module using the below documentation as reference:
https://stripe.com/docs/payments/checkout/subscriptions/starting
Stripe has two modes — Test Data and Live Data. This post will contain instructions for both modes in general, unless specified exclusively.
Payment processing, reporting usage and invoice notification are possible only through Live Data mode.
Prerequisite:
- Create a Stripe account — https://dashboard.stripe.com/register and complete the e-mail ID verification.
2. Create a Product with required values — https://dashboard.stripe.com/test/subscriptions/products and then a Pricing Plan on it’s consecutive page with Recurring quantity, desired Price per unit value and other default values.
Metered usage Pricing Plan doesn’t allow to create subscription with the checkout model which is described in this post.
3. Complete Account settings by verifying the phone number — https://dashboard.stripe.com/account
4. [Required only for Live Data mode]
Activate the account — https://dashboard.stripe.com/account/details/v2
5. Note down the below details from Stripe Dashboard
- Publishable key, Secret key — https://dashboard.stripe.com/test/apikeys
- Pricing Plan ID — https://dashboard.stripe.com/test/subscriptions/products (click the product and then the listed plan to view it’s ID)
The Pricing Plan ID will resemble the plan_* format
Steps:
- Create a Checkout Session on Stripe [Client & Server]
Scenario: From the UI, when the customer clicks the Purchase button, an API call will be made to the back-end server, and a Checkout Session must be created on Stripe through an API call from the back-end server.
Ref: https://stripe.com/docs/payments/checkout/subscriptions/starting#create-checkout-session
Note down the ID from the response JSON. The ID will resemble cs_test_* for Test Data mode and cs_live_* for Live Data mode.
2. Process the checkout [Client only]
Scenario: Once the UI receives the Checkout Session ID as response, then it can handover the control to the Stripe page where it will take the necessary inputs from the customer to process the checkout.
Ref: https://stripe.com/docs/payments/checkout/subscriptions/starting#redirect-checkout
To ease this step, I have created a simple page to enter the Checkout_Session_ID and the Publishable_key so that we can test both Test data and Live data mode.https://prakash-ces.github.io/stripe_poc
3. Update Subscription to enable Usage threshold [Server only, may be with use of Stripe’s webhooks]
Ref: https://stripe.com/docs/api/subscriptions/update#update_subscription-billing_thresholds
This step has NOT been trialed in Live Data mode yet
4. Verify payment and invoice [Live Data mode only]
After a Subscription is created, we should check if the payment passed through and if the customer received an invoice via the registered e-mail.
In order to arrive at this step, the Live Data mode and real payment methods must be used right from Step 1.
5. Report Usage [Server only, Live Data mode only]
Send an usage report to Stripe with units exceeding the Subscription plan’s permitted unit and check if the subscription gets renewed immediately by processing the payment and by sending an invoice to the customer.
Ref: https://stripe.com/docs/billing/subscriptions/metered-billing#reporting-usage
By completing all the above steps in Live Data mode, we can confirm the feasibility of the model.