Checkout widgetbeta
Show the hosted checkout inside your own page, with no redirect.
Beta
Your server creates the payment with your secret API key. Your page gets only that payment's id and client_secret, and opens the checkout in a frame served by CamBill. No redirect, and the key never reaches the browser.
The flow
Steps 7 to 10 are not optional
onSuccess runs in the customer's browser, so it is a hint for your UI (show a thank-you). Anyone can fake it. Ship the goods only after your server sees succeeded, from the status read (steps 8 and 9) or the signed webhook (step 10).
Set it up
List your site
Dashboard → Checkout → Embed on your site. Add every site that may show the checkout, one exact origin per line (https://shop.example.com). No wildcards, paths or credentials; http://localhost:* works for development. Any other site is blocked by the frame's frame-ancestors.
Create the payment on your server
// POST /api/checkout (Next.js route handler; any backend works)
import { CamBill } from "@cubis/cambill"
const cambill = new CamBill({ apiKey: process.env.CAMBILL_API_KEY! })
export async function POST(req: Request) {
const { orderId, amount } = await req.json()
const intent = await cambill.paymentIntents.create({
amount, // minor units: 1050 = $10.50
currency: "USD",
external_id: orderId, // creating twice returns the same payment
})
// Send the page only what it needs. Never the API key.
return Response.json({ id: intent.id, client_secret: intent.client_secret })
}Open it in your page
The @cubis/cambill package has components for React, Vue and Svelte (frameworks are optional peer dependencies, and the server-side client is not pulled into your bundle). They load the loader once per page, close the frame when the component goes away, and are safe to render on the server. Or load /widget/v1/loader.js yourself. Pick your stack:
npm install @cubis/cambillimport { CamBillCheckout } from "@cubis/cambill/react"
function Pay({ orderId }: { orderId: string }) {
const [pay, setPay] = useState<{ id: string; client_secret: string }>()
const start = async () =>
setPay(await (await fetch("/api/checkout", { method: "POST", body: JSON.stringify({ orderId, amount: 1050 }) })).json())
const confirm = () => fetch(`/api/orders/${orderId}/confirm`, { method: "POST" }) // your server checks the status
if (!pay) return <button onClick={start}>Pay $10.50</button>
return <CamBillCheckout intent={pay.id} secret={pay.client_secret} onSuccess={confirm} />
}For a modal, use the hook: const { open } = useCamBillCheckout() and call open({ intent, secret, onSuccess }) from a click. Changing a callback never reopens the frame.
Allow the frame in your CSP
If your site sets a Content Security Policy, add frame-src https://cambill.cubis.tech (and script-src for the loader).
Or let the component call your server
Pass endpoint (your route) and body in place of intent and secret. The component POSTs body as JSON, with your cookies, and opens the payment your route answers. checkout() from @cubis/cambill/next (or /remix, /tanstack-start) makes that route in a few lines. See Frameworks.
<CamBillCheckout endpoint="/api/cambill/checkout" body={{ orderId: "1001" }} onSuccess={showThanks} />Options and callbacks
CamBill.open returns { close() }.
| Option | Use |
|---|---|
intent, secret | The payment's id and client_secret. |
endpoint, body, headers | Instead of intent and secret: your route that answers { id, client_secret }, and what to POST to it. A failure calls onError with endpoint_failed. |
container | A selector or element to render in. Omit for a modal. |
layout | modal (default), sheet (right drawer, a bottom sheet on phones), bottom or inline (needs container). Without it the widget uses the default set in Dashboard, Checkout, Widget layout. An unknown value opens the modal. |
height | 240 to 1400 px (default 480), kept until the frame reports its own size. |
width, overlay, closeColor | Dialog layouts: width 280 to 640 px, backdrop and close button colour (a plain CSS colour; anything else is ignored). |
autoClose | true closes the widget 3 seconds after a successful payment; a number is the wait in seconds (0 to 60). Not set: it stays until the payer or your code closes it. |
redirect | false keeps your page where it is. By default, when the payment was created with a success_url (or cancel_url), the widget sends your page there after success (waiting autoClose, else 3 s) or on expiry. Your callback runs first. |
compact | true for tighter spacing, for a small slot. |
flat | true removes the card's border, shadow and corners so the checkout sits on the surface you give it. |
footer | "center" centres "Payments secured by CamBill" and puts the language and theme switchers under it (default: side by side). |
confirmClose | false turns off the "Leave this payment?" question the payer sees when closing a dialog layout. It is never asked once the payment succeeded or expired, nor when your code calls handle.close(). |
onReady | The frame has loaded. |
onSuccess({ id, status, returnUrl }) | The customer paid. A hint: confirm on your server. returnUrl is where the widget is about to go, or null. |
onExpired({ id, returnUrl }) | The QR or payment expired. Create a new payment. |
onError({ code, message }) | The checkout reported an error. |
onClose | The modal was closed. Closing never redirects. |
The close button sits in a bar the loader draws above the frame, so the checkout's language and theme controls never sit under it and the frame cannot hide it.
The redirect URL comes only from the payment (see Bring the customer back), and the loader acts only on messages from CamBill's own frame, so another script on your page cannot send your customer elsewhere.
What the page and the frame say to each other
How it stays safe
- Only listed sites can frame it. The frame page's
frame-ancestorsis built from your exact origins, so a copied snippet on another site shows nothing. - The secret stays out of logs. It and your page's origin travel in the URL fragment, which is never sent to a server. The frame removes it from the address at once.
- Messages go to one origin. The frame talks only to a parent whose origin you listed, with that exact origin as the target (never
*). The loader accepts messages only from its own frame. - The frame is sandboxed (no top navigation) and sends no referrer.
Confirm on your server
// POST /api/orders/:id/confirm
const { status } = await cambill.paymentIntents.status(intentId)
if (status === "succeeded") await markOrderPaid(orderId)status is one indexed read with its own, larger rate budget, so it suits polling. It does not ask the bank: settlement happens through the checkout and the reconciler, so the webhook (payment_intent.succeeded) stays the source of truth. Check that the amount and external_id are what you created.
Staying up to date
/widget/v1/loader.js is revalidated on every load (an ETag answer is a tiny 304), so a release reaches your page on its next load, with no change in your code. The checkout inside the frame is always the current one. To freeze a release instead, pin it below.
Pin a version
GET /widget/v1/integrity returns the loader's content version and its Subresource Integrity hash. /widget/v1/loader.js?v=<version> is immutable. To pin a release:
<script
src="https://cambill.cubis.tech/widget/v1/loader.js?v=VERSION"
integrity="sha384-…"
crossorigin="anonymous"
></script>