Note: This guide walks you how we setup stripe in the boilerplate. you don’t need to implement it in the boiler plate since its already implemented.
Prerequisites
- A Stripe account (Sign up at stripe.com)
- Go to your dashboard top right corner and turn on test mode
- Create a product in the dashboard
- Required environment variables: in
apps/server/.env
Installation
Install the required dependencies:Server-Side Configuration
- Initialize the Stripe client: in
apps/server/src/lib/stripe.ts
- Configure BetterAuth with Stripe plugin: in
apps/server/src/lib/auth.ts
Client-Side Configuration
Set up the auth client with Stripe support:Product Configuration
Define your products in a configuration file: inapps/server/src/utils/stripeProduct.ts
apps/server/src/lib/auth.ts
Webhook Handling
The plugin automatically handles common webhook events:checkout.session.completed
: Updates subscription status after checkoutcustomer.subscription.updated
: Updates subscription details when changedcustomer.subscription.deleted
: Marks subscription as canceled
apps/server/src/lib/auth.ts
Managing Subscription
Users can manage their subscription through the Stripe Customer Portal:UI Components
The boilerplate includes pre-built UI components for Stripe integration:Common Issues
-
Webhook Signature Verification
- Ensure the webhook secret is correctly set
- Verify the signature in the webhook handler
-
Subscription Status Sync
- Implement proper webhook handling
- Update the database on subscription changes
-
Checkout Session
- Set correct success and cancel URLs
- Handle failed payments gracefully