Let’s create a Stripe Checkout to set up a subscription and let our webhook handle the logic to provide access to the user. TurboStack supports both one-time payments and subscriptions. We currently supports stripe payment flow, but we have plans to include paddle and lemon squeezy for our integrations.Documentation Index
Fetch the complete documentation index at: https://docs.turbostack.io/llms.txt
Use this file to discover all available pages before exploring further.
Getting Started with Stripe
We will need a Stripe account, you can create your account here. After creating your account, you need to activate it for receiving payments (boring stuff detected). When you’re ready for receiving payments, go to the “Developers Page” and copy your keys and add them toSTRIPE_SECRET_KEY and NEXT_PUBLIC_STRIPE_PB_KEY in your .env.local file.
You’re ready to proceed with webhooks for now.
Configuring Webhooks
When going to production, you will need the webhook URL and the events you want to listen in Stripe. The webhook path configured on turbostack is/api/webhook/stripe. If your app are (or are going to be) hosted on myapp.com domain, then you can enter https://app.myapp.com/api/webhook/stripe at “Endpoint URL” input.
We need to listen to the following events to make things works properly:
checkout.session.completedcustomer.subscription.updatedcustomer.subscription.deletedcustomer.session.expired(optional, you may need this if you want to send an email for an abandoned checkout flow)
checkout.session.async_payment_succeededcustomer.session.async_payment_failed
/apps/web/app/api/webhook/stripe/route.ts file
Creating your Plans
Go to “Product Catalog Page” and click the “Create Product” button.
price_ and add it to your Pro plan in your packages/utils/src/constants/pricing.ts file.
Repeat this process to all your plans and you’ll be ready to go.
Configuring Billing Portal
Stripe requires you to set up the “Customer Portal”, so your users can manage their billing information and get their invoices from there.
- Please make sure to enable the setting that lets users switch plans
- Configure the behavior of the cancellation according to your needs
Testing your Stripe integration
You can set up a webhook integration locally, to do this, you need to enable the “Test Mode” switch at the top of your toolbar at Stripe. After that, install the “Stripe CLI” which will help you setup a tunnel that forwards requests from Stripe to your application. Login into the Stripe CLI running the following command:STRIPE_WEBHOOK_SECRET in your .env.local file.
Follow the instructions at Stripe Documentation to guarantee that your integration is working properly.