Stripe API
Endpoints for managing payments, subscriptions, and billing via Stripe.
Create Checkout Session
This endpoint creates a Stripe Checkout session to handle customer subscriptions. It validates the selected plan and addons, calculates reseller commissions, and configures the session for either new or existing customers.
curl -X POST "https://api.ainstein.ai/stripe/checkout" \
-H "Content-Type: application/json" \
-d '{
"plan": "pro",
"addons": { "extra_users": "10" },
"referrer": "reseller-slug",
"customerEmail": "customer@example.com"
}'Body
plan(string)The identifier for the subscription plan (e.g., "pro").
addons(object)A key-value map of addons and their quantities.
referrer(string)The referral slug or Clerk User ID of the reseller.
customerEmail(string)The customer's email, required for anonymous checkouts.
Responses
{
"sessionId": "cs_test_a1...",
"url": "https://checkout.stripe.com/c/pay/cs_test_a1...",
"plan": "Pro Plan",
"totalCents": 9900
}{
"error": "Invalid plan or addon configuration",
"details": ["Invalid addon: 'extra_users'"]
}Create Portal Session
This endpoint creates a Stripe Billing Portal session, allowing an authenticated user to manage their subscription details, view invoices, and update payment methods.
# This endpoint requires an active user session (authentication cookie).
curl -X POST "https://api.ainstein.ai/stripe/portal" \
-H "Authorization: Bearer <AUTH_TOKEN>"Responses
{
"url": "https://billing.stripe.com/p/session/bpa_1..."
}{
"error": "Unauthorized"
}{
"error": "No active subscription found"
}Stripe Webhooks
This endpoint handles incoming webhooks from Stripe to keep the application's data in sync with Stripe events. It processes events for checkouts, subscriptions, invoices, and more.
# The request body is a Stripe event object, and headers must include a valid 'stripe-signature'.
# This endpoint is typically called by Stripe, not by a user.Responses
{
"received": true
}{
"error": "Invalid signature"
}