Skip to Content
CamBillDocs

JavaScript SDK

@cubis/cambill: typed, zero dependencies, retries and idempotency built in.

npm install @cubis/cambill

Node 20+, Bun, Deno and Workers. The client is server only, because the key is a secret.

What to import

ImportFor
@cubis/cambillThe API client (CamBill), errors and webhook verification.
@cubis/cambill/nextNext.js route handlers: checkout and webhook. See Frameworks.
@cubis/cambill/remixThe same for Remix and React Router 7 actions.
@cubis/cambill/tanstack-startThe same for TanStack Start server routes.
@cubis/cambill/serverThe same on plain Request → Response, for Hono, Bun, Deno and Workers.
@cubis/cambill/react, /vue, /svelteThe checkout component for the browser. See Widget.
@cubis/cambill/widgetopenCheckout, without a framework.

The client

import { CamBill, CamBillError } from "@cubis/cambill"

const cambill = new CamBill({
  apiKey: process.env.CAMBILL_API_KEY!, // khpay_test_… or khpay_live_…
  // baseUrl: "https://cambill.cubis.tech",
  // timeout: 30_000, maxRetries: 2,
})

Resources

paymentIntents, customers, products, prices, coupons, taxRates, invoices, subscriptions: each with create, retrieve, list and update where the API has them, plus actions such as paymentIntents.status (just { id, status }, for polling), invoices.finalize, invoices.void, subscriptions.pause and subscriptions.advance. The method names follow the API reference.

What it does for you

  • Idempotency. Every POST carries an Idempotency-Key: yours ({ idempotencyKey }) or a random one, reused on each retry.
  • Retries. 429, 5xx and network errors are retried with backoff (and Retry-After), up to maxRetries.
  • Errors. Failures throw CamBillError with status, title, traceId and retryable. status 0 means no answer arrived.
  • Cancel. Pass { signal } to abort a call and its retries.
  • Webhooks. cambill.webhooks.constructEvent({ payload, signature, secret }) verifies and parses (see Webhooks).

In the browser

The checkout components take a payment's id and client_secret from your server, or an endpoint on your server that answers them. They never take an API key, and they always load the current loader. See Widget.

Types

Every request and response is typed. import type { Invoice, Customer, Subscription } from "@cubis/cambill". Amounts are number (minor units), times are strings.

No SDK for your language?

The API is plain JSON over HTTPS and fully described by openapi.yaml, so any OpenAPI generator works.

On this page