VietBilling
VietBilling Docs

Checkout

Learn to create idempotent Checkout sessions for recurring plans in VND, manage redirect URLs safely, and reconcile payment status via Checkout ID.

Create checkout on the server

A Checkout joins a Customer to the current live ProductPrice of a recurring Product. You may identify an existing Customer or let VietBilling resolve/create one from external_customer_id and email.

const result = await fetch(
  `${apiUrl}/public/v2/checkouts`,
  {
    method: "POST",
    headers: apiHeaders,
    body: JSON.stringify({
      external_customer_id: account.id,
      customer_email: account.ownerEmail,
      customer_name: account.name,
      product_id: productId,
      success_url: `${appUrl}/billing/success`,
      cancel_url: `${appUrl}/billing`,
    }),
  },
).then((res) => res.json())

redirect(result.data.checkout_url)

Check the return

A success page is not proof of payment. Your server should fetch GET /public/v2/checkouts/{checkoutId}; final access decisions still depend on a verified webhook.

Avoid stale sessions

Retry the same logical request with the same Idempotency-Key. Do not reuse a succeeded checkout_url; an open Checkout expires after 30 minutes.