Payments [PRO]
To be able to accept payments in your app, this boilerplate comes with the Stripe (opens in a new tab) integration. With Stripe, you can accept one-time payments, manage subscriptions and many more.
The payments package with the configuration is located at packages/payments
. The webhook listener is located at apps/webpro/src/app/api/payments/webhook/route.ts
The Stripe actions are located at apps/webpro/src/actions/payments/
.
Stripe Setup
Make sure to develop in Test Mode locally first. Then use the Production credentials when deploying your app.
-
You need to create a new account on Stripe (opens in a new tab) if you don't have any.
-
In the Stripe Dashboard (opens in a new tab), note the Publishable Key and Secret key.
-
Now create 2 products of type subscription. Go to Product catalogue and click + Add product. Set the product name, price and billing period, feel free to add other details. For both products, note the price ID.
-
Create a webhook by going to Developers > Webhooks. Click + Add endpoint, add Endpoint URL as
<your-domain>/api/payments/checkout-webhook
. Select all Checkout and Subscription Schedule events and add them. Then save the webhook. Note the signing secret. -
Add the Publishable Key, Secret key, price IDs and webhook signing secret to the
.env
file.
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=
STRIPE_SECRET_KEY=
STRIPE_WEBHOOK_SECRET=
STRIPE_TEAM_TIER_PRICE_ID=
STRIPE_ENTERPRISE_TIER_PRICE_ID=
- Done! You can now test the flow by going to
http://localhost:3000/billing
.
After subscribing users are able to manage their subscription by initialising Stripe Billing portal at /billing
.
Refer to Stripe docs (opens in a new tab) to learn more.