curl -X POST https://your-domain.com/api/create-checkout-session \
-H "Content-Type: application/json" \
-d '{
"userId": "user_123abc",
"planId": "weekly"
}'
{
"sessionId": "cs_test_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0"
}
Create a Stripe checkout session for subscription or one-time payments
curl -X POST https://your-domain.com/api/create-checkout-session \
-H "Content-Type: application/json" \
-d '{
"userId": "user_123abc",
"planId": "weekly"
}'
{
"sessionId": "cs_test_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0"
}
client_reference_id in the Stripe session."weekly" for recurring subscriptions or "one-time" for lifetime access.weekly - Creates a subscription mode checkout with recurring billingone-time - Creates a one-time payment mode checkoutstripe.redirectToCheckout({ sessionId }).subscription for weekly plans, payment for one-time purchases/subscription/success?session_id={CHECKOUT_SESSION_ID}/subscription?canceled=trueuserId and planId for webhook processingSTRIPE_WEEKLY_PRICE_ID environment variableSTRIPE_ONE_TIME_PRICE_ID environment variable{
"error": "Missing userId or planId"
}
{
"error": "An error occurred"
}
curl -X POST https://your-domain.com/api/create-checkout-session \
-H "Content-Type: application/json" \
-d '{
"userId": "user_123abc",
"planId": "weekly"
}'
{
"sessionId": "cs_test_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0"
}
STRIPE_SECRET_KEY environment variable2023-10-16userId and planId for webhook processingclient_reference_id is set to the userId for easy user identification in webhookscheckout.session.completed webhook event