BuildShip Logo
BuildShipย Community

Stripe Subscriptions

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.

385

Report this template

Select the reason for reporting

Describe the issue in detail

Share template

Link to template

https://templates.buildship.com/template/ARpOluLb1BB1/

This template contains 4 flows:

No examples available for this flow.

Read me

๐Ÿ“– Read Me

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 the Stripe testing cards available to simulate payments to test your integration without moving any real money.

Prerequisites

  1. Note down your secret key from your Stripe accountstripe secret key
  2. A Stripe product to create subscriptions for. See Stripe documentation for more details regarding creating a product with pricing options.
    1. Your product should have at least one recurring pricing option attached to it.stripe secret key
    2. For testing, make a note of the ID for one of your product prices.stripe secret key

โœ๏ธ 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.

stripe secret key

Setup โš™๏ธ:

  1. Before testing you need to add your Stripe secret key to the "Create Subscription Session" node.stripe secret key

Test ๐Ÿงช:

  1. To test the Flow you need to input:
    1. Price Id - refer to the prerequisites section to see how to get your price ID
    2. Quantity - number of subscription to purchase
    3. Return URL - a URL to redirect to after checkoutstripe secret key
  2. 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:

  1. checkout.session.completed - When triggered we'll save partial subscription details such as the customer ID and subscription ID to the database.
  2. customer.subscription.created - When triggered we'll save additional subscription details such as the current period start, current period end, etc.
  3. customer.subscription.updated - When triggered we'll save the updated price ID, quantity, or metadata.
  4. customer.subscription.deleted - When triggered we'll update the subscription in the database by setting it's status to canceled.

Setup โš™๏ธ:

  1. You need to configure the Stripe Webhook trigger to add your Stripe integration key stripe secret key
  2. Connect the trigger and Ship your workflow. After your workflow is shipped you should notice a new Webhook created in your Stripe dashboard

Test ๐Ÿงช:

  1. First you need to create a checkout session using the previous template and submit the form. This should then trigger the Handle Events workflow.
  2. Confirm the subscription is synced to database:
    1. Open the BuildShip database.stripe secret key
    2. 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.
    3. 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 โš™๏ธ:

  1. Before testing you need to add your Stripe secret key to the "Update Subscription" node.

Test ๐Ÿงช:

To test the Flow you need to input:

  1. Subscription ID - the ID of the subscription to update
  2. New Price ID - a price ID to change the plan attached to the subscription
  3. 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 โš™๏ธ:

  1. Before testing you need to add your Stripe secret key to the "Cancel Subscription" node.

Test ๐Ÿงช:

To test the Flow you need to input:

  1. 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๐Ÿ’ก๐Ÿš€.

๐Ÿ”— Resources

Any additional information like demo links or YouTube tutorials.