// Implement Stripe payment flows, webhooks, and billing logic. Use when working with payments, subscriptions, checkout, or credit systems.
| name | stripe-integration |
| description | Implement Stripe payment flows, webhooks, and billing logic. Use when working with payments, subscriptions, checkout, or credit systems. |
app/api/webhooks/stripe/route.tsserver/services/stripe.service.tsshared/config/subscription.utils.tsHandle these events for subscriptions:
checkout.session.completed - New subscriptioncustomer.subscription.updated - Plan changescustomer.subscription.deleted - Cancellationinvoice.payment_succeeded - Renewalinvoice.payment_failed - Failed paymentimport Stripe from 'stripe';
const signature = request.headers.get('stripe-signature');
const event = stripe.webhooks.constructEvent(body, signature, process.env.STRIPE_WEBHOOK_SECRET);
const session = await stripe.checkout.sessions.create({
mode: 'subscription',
customer_email: user.email,
line_items: [{ price: priceId, quantity: 1 }],
success_url: `${baseUrl}/success?session_id={CHECKOUT_SESSION_ID}`,
cancel_url: `${baseUrl}/pricing`,
metadata: { userId: user.id },
});
Use Stripe CLI for local webhook testing:
stripe listen --forward-to localhost:3000/api/webhooks/stripe