Create checkout
All variants share provider, customer, redirect URLs, optional client IP, and an idempotency key.
const common = { provider: "midtrans", customer: { externalId: "customer-42", email: "buyer@example.com", name: "Buyer", }, successUrl: "https://merchant.example/checkout/success", cancelUrl: "https://merchant.example/checkout/cancel", clientIp: null,} as const;Inline item
Section titled “Inline item”import { createCheckout } from "@byfungsi/sapa";
const checkout = createCheckout({ ...common, type: "single", idempotencyKey: "order-42", item: { name: "Consulting session", amount: 500_000n, currency: "IDR", fulfillment: { type: "billing_only" }, },});Catalog price
Section titled “Catalog price”const checkout = createCheckout({ ...common, type: "catalog", priceId: "price-5e761e68-ab6e-4e67-81d4-36e1811b6272", idempotencyKey: "catalog-order-42",});Seed the complete catalog with seedCatalog before using a catalog price.
Registered offer
Section titled “Registered offer”const checkout = createCheckout({ ...common, type: "offer", offerKey: "workspace.pro", offerRevision: 1, quantity: null, idempotencyKey: "offer-order-42",});For per-seat offers, set quantity to the buyer-selected count.
Subscription renewal
Section titled “Subscription renewal”const checkout = createCheckout({ ...common, type: "subscription_renewal", subscriptionId: "sub-00000000-0000-4000-8000-000000000001", idempotencyKey: "renewal-2026-10-customer-42",});Metered invoice
Section titled “Metered invoice”const checkout = createCheckout({ ...common, type: "invoice", invoiceId: "inv-00000000-0000-4000-8000-000000000001", idempotencyKey: "invoice-checkout-42",});Only an invoice whose collection status is payment_due can create a checkout.
Persist the returned checkoutId before redirecting the customer.