Skip to content

A POC to integrate Stripe metered billing to a SaaS Data Management Platform.

Notifications You must be signed in to change notification settings

svenefftinge/stripe-metered-subscriptions

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Stripe Metered Billing

A POC to integrate Stripe metered billing to a SaaS Data Management Platform.

Untitled_.Apr.30.2021.7_22.PM.mp4

This repository contains the source code for an example on how to integrate a SaaS product with Stripe metered billing.

Pre-requisites:

  1. A Stripe Account
  2. React.js
  3. Node.js
  4. (React) Stripe.js

Setup Guide

  1. Client
    • Login to stripe.com and turn on "Viewing test data" on the sidebar menu.
    • Go to https://dashboard.stripe.com/your_username/apikeys and copy the publishable key that starts with pk_test_
    • Paste the publishable key in client/.env as REACT_APP_STRIPE_PUBLISHABLE_KEY = <paste here>
    • Start the client development environment using yarn start or npm run start
  2. Server

Steps involved in creating a stripe metered subscription

  1. Create a customer on stripe using the Customer API when a user signs up to your application. Store this customer_id in the users table of your app's database. This is to ensure that you don't create duplicate customers on stripe (Stripe does not check for duplicate customers, it creates a new customer every time you add a customer with same credentials.)
  2. Create a cart and calculate the total price of a purchase.
  3. Create a payment method using React Stripe.js which returns the payment_method_id
  4. Create a Price (price_id) using the Prices API or using the Stripe dashboard (you can create a product and price on the dashboard manually).
    • Using the API, you can create both the price and the product at once using the prices API (using the product_data object)
  5. Now, using the customer_id, payment_method_id and price_id, create a subscription for the customer.
  6. (Additional step, which is not covered in this example) You can keep track of usage using your own business logic and update this usage to Stripe using their Usage API

References

About

A POC to integrate Stripe metered billing to a SaaS Data Management Platform.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 77.6%
  • JavaScript 12.5%
  • HTML 5.9%
  • CSS 3.6%
  • Shell 0.4%