Pay Sessions
View .mdOpen in ClaudeOpen in ChatGPT

Pay Sessions

Create short-lived pay_tokens for hosted card storage and scoped Pay requests. Your backend mints a pay token (client-authenticated), and the hosted Elements iframe validates it to read its scope before rendering. Hosted payment execution remains gated until launch.

Related guides: Schedule Bill Payments · Elements SDK

The Pay Token object

A pay token is a short-lived, single-purpose credential your backend mints (client-authenticated) and hands to the hosted Elements iframe. It is the browser's only credential — your client secret never reaches the frontend, and card PAN/CVV never leave the BillerAPI-hosted page.

Attributes

pay_token*stringThe pay token used to initialize the Elements add-payment-method / pay flows
pay_token_id*stringUnique identifier for the pay token
client_id*stringYour client ID (authoritative — taken from the credential, never the body)
client_user_id*stringYour unique identifier for the end user
statusstringAWAITING_PAYMENT_METHOD | AWAITING_PAYMENT | COMPLETED | EXPIRED
bill_idstringBill the token is scoped to (required to run a payment)
amount_valueintegerAmount in minor units (cents); 0 when unscoped
amount_currencystringISO 4217 currency code, e.g. "USD"
expires_atstringISO 8601 timestamp of when the token expires (15-minute TTL)
The Pay Token object
{
  "pay_token": "payt_5f3c…",
  "pay_token_id": "ptid_789xyz",
  "client_id": "your_client_id",
  "client_user_id": "user_12345",
  "status": "AWAITING_PAYMENT",
  "bill_id": "bill_abc123",
  "amount_value": 1299,
  "amount_currency": "USD",
  "expires_at": "2026-06-29T12:15:00Z"
}
POST/v1/pay-tokens

Server-to-server. Mint a pay token for the hosted Elements flows. Requires client credentials (API key / API key); the client_id is taken from the credential — a mismatched body value is rejected with 403. Tokens are short-lived (15 minutes).

Request body

client_user_id*stringYour unique identifier for the end user
bill_idstringBill to pay (required for the pay flow; omit for add-payment-method only)
amountobject{ value: integer (minor units), currency: string } — the amount to authorize
payment_method_idstringPre-bind a saved payment method
metadata_jsonstringOpaque JSON string echoed back on the token
Sample uses your_client_id · sign in to auto-fill your sandbox key
curl -X POST https://sandbox.api.billerapi.com/v1/pay-tokens \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $BILLERAPI_API_KEY" \
  -d '{
    "client_user_id": "user_12345",
    "bill_id": "bill_abc123",
    "amount": { "value": 1299, "currency": "USD" }
  }'
Response201 Created
{
  "success": true,
  "pay_token": "payt_5f3c…",
  "pay_token_id": "ptid_789xyz",
  "expires_at": "2026-06-29T12:15:00Z"
}
POST/v1/pay-tokens/validate

Unauthenticated — the token itself is the credential (capability URL). The hosted Elements page calls this on load to confirm the token and read its scope (bill, amount, status) before rendering. You normally don't call this directly; the SDK does.

Request body

pay_token*stringThe pay token to validate
Sample uses your_client_id · sign in to auto-fill your sandbox key
curl -X POST https://sandbox.api.billerapi.com/v1/pay-tokens/validate \
  -H "Content-Type: application/json" \
  -d '{ "pay_token": "payt_5f3c…" }'
Response200 OK
{
  "valid": true,
  "pay_token_id": "ptid_789xyz",
  "client_id": "your_client_id",
  "client_user_id": "user_12345",
  "status": "AWAITING_PAYMENT",
  "bill_id": "bill_abc123",
  "amount_value": 1299,
  "amount_currency": "USD",
  "expires_at": "2026-06-29T12:15:00Z"
}

Next: choose the supported flow

Hosted .pay() is gated in sandbox and production with 501 PAYMENT_EXECUTION_NOT_AVAILABLE and does not call onSuccess. Use the direct sandbox REST endpoint to create a synthetic attempt. Its 201 response includes an attempt_id, which you can retrieve or follow through sandbox webhooks. Hosted .addPaymentMethod() remains available for card storage.

Sandbox REST simulation
const response = await fetch('https://sandbox.api.billerapi.com/v1/pay/payments', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${pay_token}`,
    'Content-Type': 'application/json',
    'Idempotency-Key': crypto.randomUUID(),
  },
  body: JSON.stringify({
    bill_id: 'bill_abc123',
    payment_method_id: 'sb_pm_abc123',
  }),
});

const result = await response.json();
if (!response.ok) throw new Error(result.error_message);
const { attempt_id } = result; // 201 Created; synthetic sandbox attempt
Was this page helpful?