VietBilling
VietBilling Docs

Xác thực API

Gọi VietBilling Public API an toàn bằng Organization API key.

Dùng Organization API key ở server

Mọi request Public API cần API key thuộc đúng Organization. Gửi key trong header Authorization và không gọi VietBilling trực tiếp từ trình duyệt.

const response = await fetch(
  `${process.env.VIETBILLING_API_URL}/public/v2/customers`,
  {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.VIETBILLING_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ external_id: user.id, email: user.email }),
  },
)

Xử lý lỗi

Không log nguyên header xác thực. Với lỗi 401, kiểm tra key và môi trường; với 403, kiểm tra Organization hoặc Customer Limit. Chỉ retry lỗi mạng hoặc 5xx bằng exponential backoff, không retry mù lỗi validation.

Xoay vòng key

Tạo key mới, cập nhật secret store và xác nhận request chạy ổn trước khi thu hồi key cũ. Tách key giữa staging và production.