← Back to list

How to Build a Billing System using Stripe: Complete Setup Guide from My Experience

Part 2: Create Subscription

Raviraj Ghare in nonstopio · 2026-04-02 09:10 · 252 claps · 5.5 min read
#billing-system #stripe #subscription #software-development #backend-development
Open on Medium ↗
Wiki topics: 🌐 · Web Development

How to Build a Billing System using Stripe: Complete Setup Guide from My Experience

Part 2: Create Subscription

Welcome back to the second part of this series! In this part, we will understand and set up how to create a subscription for a customer using different approaches. Before we dive in, make sure you have the following Stripe keys configured in your .env file as a prerequisite:

STRIPE_SECRET_KEY=your_stripe_secret_key
STRIPE_PUBLISHABLE_KEY=your_stripe_publishable_key
STRIPE_WEBHOOK_SECRET=your_stripe_webhook_secret

You can find all these keys in your Stripe Dashboard. If you are not sure how to set this up, Part 1 covers it in detail.

A subscription is simply a recurring billing for a product at a set interval of time, weekly, monthly, yearly, and so on.

We can create a subscription in Stripe using the following methods:

  1. Stripe Checkout
  2. Stripe API
  3. Stripe Dashboard
  4. Stripe Payment Links

Stripe Checkout

Stripe Checkout is a low-code option where we create a Stripe Checkout Session from our backend, and Stripe handles the rest. It opens a built-in payment UI where the user can select a product or plan and complete the payment. Once done, Stripe automatically creates the subscription against that customer.

Here’s how the flow works:

  1. Our backend creates a Checkout Session and returns the session URL to our frontend.
  2. The user is redirected to that URL and completes the payment on Stripe’s hosted page.
  3. Once the subscription is created, Stripe fires a webhook event checkout.session.completedto our server via our registered API endpoint.
  4. In that webhook payload, we get everything we need: customer ID, subscription ID, user email, and more.
  5. We then save this data in our database for all future subscription handling in our system.

While creating the Checkout Session, we can pass several parameters like:

  • customer_email (We can pass this if we already have the user's email. But if we want Stripe to collect the email directly on the checkout page, simply skip this parameter, and Stripe will show an email input field on the payment page itself.)
  • mode (set to subscription)
  • line_items (the product or plan)
  • success_url (the URL where Stripe redirects the user after a successful payment)
  • cancel_url (the URL where Stripe redirects the user if they close or cancel the checkout page without completing the payment)
  • …and more depending on your use case

You can explore all available parameters here: https://docs.stripe.com/api/checkout/sessions

function to create a stripe checkout session

function to create a stripe checkout session

Handle Checkout session completed webhook once subscription is created using stripe checkout session

Handle Checkout session completed webhook once subscription is created using stripe checkout session

We can also customize the Checkout page to match our company branding, like colors, fonts, and logo. Just go to Stripe DashboardSettings → Payments → Checkout and Payment Links and configure it from there.

Stripe Checkout Session Create Subscription UI

Stripe Checkout Session Create Subscription UI

That’s how we create a subscription in Stripe using the Checkout Session approach.

Stripe API

We can also create a subscription directly using the Stripe API. We can refer to the official documentation here: https://docs.stripe.com/api/subscriptions/create

In this approach, we collect the user’s details on our own UI and call the Stripe API from our backend. Here’s how the flow works:

  • If we are creating a subscription for a new user, we first create a Stripe Customer using their email, and then pass that customer_id while creating the subscription.
  • If the user already exists in our system and we have their information customer_id stored, we directly pass it while creating the subscription; there is no need to create a customer again.

Create Subscription using stripe api

Create Subscription using stripe api

Once we call the Create Subscription API with the required parameters, Stripe creates the subscription and fires a webhook event customer.subscription.created to our server.

In that webhook payload, we get all the details we need: customer ID, subscription ID, email, price, and more. We then save this in our database.

webhook to handle subscription created webhook

webhook to handle subscription created webhook

We don’t need to store everything from Stripe. We only need to save the customer ID and subscription ID. Using just these two, we can always call the Stripe API anytime to fetch everything else, like the user’s product, billing interval, customer metadata, and so on. Stripe holds all of that for us.

Stripe Dashboard

The third option is creating a subscription directly from the Stripe Dashboard, no code involved. This is especially useful for system admins who need to manually manage customers and subscriptions.

Step 1: Create a Customer

Go to Stripe Dashboard → Customers → Add Customer, fill in the required details like name, email, etc., and save. Once the customer is created, Stripe fires a customer.created webhook to our server, where we can capture and store the customer details we need.

Step 2: Create a Subscription for the Customer

If the customer already exists, go to Stripe Dashboard → Customers → Select the Customer → Create Subscription. In the subscription pop-up, you can configure everything

  • Select the product and plan
  • Set the billing interval
  • Add free trial days
  • Apply coupons or discounts

Once the subscription is created, Stripe fires a customer.subscription.created webhook, and we can listen to it on our backend to get all the details we need: customer ID, subscription ID, plan details, and so on.

This approach gives great flexibility to system admins to manually add or manage subscriptions for users, whether it’s for testing, offering trials, applying special coupons, or handling edge cases without touching any code.

Create Customer on Stripe Dashboard

Create Customer on Stripe Dashboard

Create Subscription for a customer on Stripe Dashboard

Create Subscription for a customer on Stripe Dashboard

Stripe Payment Links

The fourth option is creating a subscription using Stripe Payment Links. You can refer to the official documentation here: https://docs.stripe.com/payment-links

This is the simplest no-code option. We create a payment link once and just share it with the user. No backend, no checkout session, nothing.

Here’s how to create a Payment Link:

Go to Stripe Dashboard → Products → Payments → Payment Links → Create Payment Link. While creating the link, we can configure things like

  • Select the product and plan
  • Collect customer information like name, email, and address
  • Add free trial days
  • Apply coupons or discounts

Once the payment link is created, we just share it with the user via email, WhatsApp, or anywhere. The user opens the link, fills in the required details, completes the payment, and Stripe automatically creates the subscription for them.

Just like the other approaches, we can listen to the checkout.session.completed or customer.subscription.created webhook on our backend to get all the information we need and update our database accordingly.

This approach is great when we just want to quickly onboard users without building any custom payment UI.

Crate Stripe Payment Link

Crate Stripe Payment Link

So these are all the ways by which we can create a subscription using Stripe. You can choose whichever fits our use case best.

Also, all the code changes we discuss in this series are available in our repository: 👉 https://github.com/RAVIGHARE/stripe-go

In the next part, we will look at how to handle subscription updates like upgrading, downgrading, and cancelling. Stay tuned!

Here to make the community stronger by sharing our knowledge. Follow me and my team to stay updated on the latest and greatest in the web & mobile tech world.


메타데이터
post_id
4c6dfe547a54
slug
building-a-flexible-and-robust-billing-system-with-stripe-part-ii-create-subscription-4c6dfe547a54
url
https://blog.nonstopio.com/building-a-flexible-and-robust-billing-system-with-stripe-part-ii-create-subscription-4c6dfe547a54
canonical_url
https://blog.nonstopio.com/building-a-flexible-and-robust-billing-system-with-stripe-part-ii-create-subscription-4c6dfe547a54
author_url
https://medium.com/@ravighare1892
status
ok
fetched_at
2026-08-02 15:42:38