VietBilling
VietBilling Docs

Checkout

Tạo và đối soát Checkouts cho recurring Products trên PayOS.

Tạo checkout trên server

Checkout gắn Customer với ProductPrice đang live của recurring Product. Bạn có thể truyền Customer hiện tại hoặc để VietBilling resolve/tạo Customer từ external_customer_id và 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)

Kiểm tra khi quay lại

Trang success không phải bằng chứng thanh toán. Server nên lấy trạng thái bằng GET /public/v2/checkouts/{checkoutId}; việc cấp quyền cuối cùng vẫn dựa trên webhook hợp lệ.

Tránh session cũ

Retry cùng intent bằng một Idempotency-Key. Không tái sử dụng checkout_url đã succeeded; Checkout open hết hạn sau 30 phút.