Customers
Create customers idempotently and map them to application users.
One customer per billing account
You may create a Customer before Checkout, or let Checkout resolve/create it. Use a stable account id from your application as external_id to prevent duplicates.
const customer = await fetch(
`${apiUrl}/public/v2/customers`,
{
method: "POST",
headers: apiHeaders,
body: JSON.stringify({
external_id: account.id,
email: account.ownerEmail,
name: account.name,
}),
},
).then((res) => res.json())
Store the mapping
Store customer.data.id next to your internal billing account. Active Customer email and external_id are unique inside an Organization, but external_id should remain your stable mapping.
| Field | Purpose |
|---|---|
external_id | Stable id from your system |
email | Billing identity and contact |
name | Person or organization name |
Idempotency
If a request times out, inspect the mapping you already store before creating another customer. Your system should guarantee one VietBilling customer per billing account.