Set up Stripe Subscription Payments for your SaaS product with this starter template, designed to help you create, manage, and track subscriptions while seamlessly syncing subscription and customer data to your database.
Implement Stripe subscription processing for your products with seamless workflows to generate checkout links, manage subscription events in your database, and update or cancel subscriptions effortlessly.
This use case illustrates how to manage Stripe subscriptions for a fictional BuildShip product while keeping the database up-to-date.
NOTE โโ๏ธโ: During development you can enable test mode in your Stripe dashboard and use any of theStripe testing cardsavailable to simulate payments to test your integration without moving any real money.
Prerequisites
Note down your secret key from your Stripe account
A Stripe product to create subscriptions for. See Stripe documentation for more details regarding creating a product with pricing options.
Your product should have at least one recurring pricing option attached to it.
For testing, make a note of the ID for one of your product prices.
โ๏ธ How to Use
Step 1: Use the Create Checkout template to create a checkout form
This template creates a subscription checkout session for a specified product Price ID and returns the checkout session URL to sign up for the subscription.
Setup โ๏ธ:
Before testing you need to add your Stripe secret key to the "Create Subscription Session" node.
Test ๐งช:
To test the Flow you need to input:
Price Id - refer to the prerequisites section to see how to get your price ID
Quantity - number of subscription to purchase
Return URL - a URL to redirect to after checkout
Open the checkout URL returned and submit the checkout form to sign up for the subscription.
This will trigger several Stripe webhook events, which will be captured and processed by the Handle Events template. Continue reading below to learn how to configure and ship the Handle Events template.
Step 2: Use the Handle Events template to process the subscription
After submitting the checkout form, what happens next is entirely up to you. For this scenario, we want to store the subscription details in our BuildShip database.
These are the events we will monitor:
checkout.session.completed - When triggered we'll save partial subscription details such as the customer ID and subscription ID to the database.
customer.subscription.created - When triggered we'll save additional subscription details such as the current period start, current period end, etc.
customer.subscription.updated - When triggered we'll save the updated price ID, quantity, or metadata.
customer.subscription.deleted - When triggered we'll update the subscription in the database by setting it's status to canceled.
Setup โ๏ธ:
You need to configure the Stripe Webhook trigger to add your Stripe integration key
Connect the trigger and Ship your workflow. After your workflow is shipped you should notice a new Webhook created in your Stripe dashboard
Test ๐งช:
First you need to create a checkout session using the previous template and submit the form. This should then trigger the Handle Events workflow.
Confirm the subscription is synced to database:
Open the BuildShip database.
Look for a table named stripe_subscriptions. If it's your first time using the template then you'll need to go through a short setup and import wizard.
If everything worked as expected then you should see your saved subscriptions.
Bonus ๐
Update Subscription
You can use the Update Subscription template to test updating subscriptions.
Setup โ๏ธ:
Before testing you need to add your Stripe secret key to the "Update Subscription" node.
Test ๐งช:
To test the Flow you need to input:
Subscription ID - the ID of the subscription to update
New Price ID - a price ID to change the plan attached to the subscription
New Quantity - change the subscription quantity
This will update the subscription in Stripe and trigger the customer.subscription.updated condition in the Handle Events workflow to update the subscription in the database.
Cancel Subscription
You can use the Cancel Subscription template to test canceling subscriptions.
Setup โ๏ธ:
Before testing you need to add your Stripe secret key to the "Cancel Subscription" node.
Test ๐งช:
To test the Flow you need to input:
Subscription ID - This will cancel the subscription in Stripe and trigger the customer.subscription.deleted condition in the Handle Events workflow to cancel the subscription in the database.
REMIX
These workflows provide a starting point for managing subscriptions on your apps and websites. Depending on your payment processing needs, BuildShip offers numerous integrations to perform various tasks, including generating invoice PDFs, saving orders to spreadsheets, sending email notifications, and more.
What you choose to do from here is entirely up to you๐ก๐.