All documentation
Hosted Checkout - cred.diy API documentation
Hosted Checkout
Let your users purchase credits through a Stripe-powered checkout. Set up pricing tiers in the dashboard and generate checkout sessions via API. Payments go directly to your connected Stripe account.
Create Checkout Session
Generate a checkout URL and redirect your users to complete their purchase.
// Create a hosted checkout session for credit purchases
const response = await fetch(
'https://eutdgemlrpvnxfkkpvlu.supabase.co/functions/v1/hosted-checkout',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': 'sk_live_your_api_key'
},
body: JSON.stringify({
user_id: 'user_123',
user_email: 'user@example.com',
pricing_tier_id: 'your_pricing_tier_id',
success_url: 'https://yourapp.com/success',
cancel_url: 'https://yourapp.com/cancel',
// billing: 'recurring' // Explicitly opt in to monthly billing
})
}
);
const result = await response.json();
// {
// url: 'https://checkout.stripe.com/...',
// session_id: '...',
// purchase_id: '...'
// }
// Redirect user to result.url to complete purchaseCheckout Parameters
| Parameter | Type | Description |
|---|---|---|
| user_id | string | Your end-user's external identifier |
| user_email | string | User's email for receipt |
| pricing_tier_id | string | ID of the pricing tier to purchase |
| success_url | string | Redirect URL after successful payment |
| cancel_url | string | Redirect URL if user cancels |
Stripe Connect
Connect your Stripe account to receive payments directly. Set up Stripe Connect from the Payments page in your dashboard. A small platform fee is applied to each transaction.
Your first credit is one request away.
Create a project, copy an API key, and issue a credit from your server.
