Use Hosted Checkout
Guide
A checkout session is a branded, Ching-hosted payment page. You create it, redirect the customer, and Ching handles card entry, 3DS, charging, and fulfilment of the resulting subscription or one-off purchase.
When to use it
- You want zero PCI scope and no custom card UI.
- You want a consistent upgrade / downgrade flow for subscriptions.
- You're building a marketing site that needs a "Buy now" button.
The Flow
- Create a customer (or re-use an existing one).
- POST
/v1/checkout_sessionswith a price id and your success / cancel URLs. - Redirect the customer to the returned url.
- When the customer completes the session, Ching fires
checkout_session.completedand redirects them to your success URL.
Create the session
curl -X POST https://api.ching.co.il/v1/checkout_sessions \
-H "Authorization: Bearer sk_live_..." \
-H "Content-Type: application/json" \
-d '{
"customer": "cus_V8ltq1pK_MWH",
"price": "price_QA8qF3B3VIqE",
"success_url": "https://app.example.com/welcome",
"cancel_url": "https://app.example.com/pricing"
}'Fulfil server-side
Don't rely on the browser landing on your success URL - customers close tabs. Fulfil from the webhook:
// Pseudo-code inside your webhook handler
if (event.type === "checkout_session.completed") {
const { kind, subscription_id } = event.data;
if (kind === "new" || kind === "upgrade") {
await grantAccess(subscription_id);
}
}Upgrade vs new: If the customer already has an active subscription, Ching classifies the checkout as an upgrade, downgrade, or same-plan change and responds accordingly.