Skip to content

Latest commit

 

History

History
120 lines (74 loc) · 6.33 KB

README.md

File metadata and controls

120 lines (74 loc) · 6.33 KB

Next.js Subscription Payments Starter

The all-in-one starter kit for high-performance SaaS applications.

Features

Demo

Screenshot of demo

Architecture

Architecture diagram

Deploy with Vercel

The Vercel deployment will guide you through creating a Supabase account and project as well as a Stripe test account and automatically creates the Stripe webhook endpoint for you. After installation of the Supabase and Stripe integrations, all relevant environment variables will be set up so that the project is usable immediately after deployment.

Note: The Stripe integration is still a work-in-progress.

Deploy with Vercel

Screenshot of Vercel deployment

Once the project has been deployed, continue with the configuration steps below.

Configure Supabase Auth

[Optional] - Set up OAuth providers

You can use third-party login providers like GitHub or Google. Refer to the docs to learn how to configure these.

Configure Stripe

Create product and pricing information

For Stripe to automatically bill your users for recurring payments, you need to create your product and pricing information in the Stripe Dashboard. When you create or update your product and price information, the changes are automatically synced with your Supabase database.

Stripe Checkout currently supports pricing plans that bill a predefined amount at a specific interval. More complex plans (e.g. different pricing tiers or seats) are not yet supported.

For example, you can create business models with different pricing tiers, e.g.:

  • Product 1: Hobby
    • Price 1: 10 USD per month
    • Price 2: 100 USD per year
  • Product 2: Freelancer
    • Price 1: 20 USD per month
    • Price 2: 200 USD per year

Configure the Stripe customer portal

  1. Set your custom branding in the settings.
  2. Configure the Customer Portal settings.
  3. Toggle on "Allow customers to update their payment methods".
  4. Toggle on "Allow customers to update subscriptions".
  5. Toggle on "Allow customers to cancel subscriptions".
  6. Add the products and prices that you want to allow customer to switch between.
  7. Set up the required business information and links.

That's it

That's it, you're now ready to earn recurring revenue from your customers 🥳

Going live

Before going live, make sure you archive all your test mode Stripe products, so you don't end up having a mix of test and live mode products on your page. Before creating your live mode products, make sure to follow the steps below to set up your live mode env vars and webhooks.

To run the project in live mode and process real payments with Stripe, you can add the Stripe Go Live integration to your project. This will set up your live API keys and webhook secret as environment variables for the production environment.

Afterward you will need to rebuild your production deployment for the changes to take effect. Within your project Dashboard, navigate to the "Deployments" tab, select the most recent deployment, click the overflow menu button (next to the "Visit" button) and select "Redeploy".

Develop locally

Deploying with Vercel will have created a repository for you which you can clone to your local machine.

Next, use the Vercel CLI to link your project:

vercel login
vercel link

Setting up the env vars locally

Use the Vercel CLI to download the development env vars:

vercel env pull .env.local

This will create a new .env.local file in your project folder. For security purposes you will need to set the SUPABASE_SERVICE_ROLE_KEY manually from your Supabase dashboard (Settings > API). Lastly, the webhook secret differs for local testing vs. when deployed to Vercel. Follow the instructions below to get the corresponding webhook secret.

Use the Stripe CLI to test webhooks

First install the CLI and link your Stripe account.

Next, start the webhook forwarding:

stripe listen --forward-to=localhost:3000/api/webhooks

The CLI will print a webhook secret (such as, whsec_***) to the console. Set STRIPE_WEBHOOK_SECRET to this value in your .env.local file.

Install dependencies and run the Next.js client

npm install
npm run dev
# or
yarn
yarn dev