Payin
- Create a payinPOST /
v1/ pay/ deposits Inline sender + saved Idempotency-Key - Two successful LIVE responses201 · awaiting_paymentPayment instructions readylegs[] + expires_at + slip_uploadUse the current instructions for this order.201 → transferOR202 · awaiting_liquidityWait for a destinationGET /
v1/ pay/ deposits/ { id} Poll with backoff, respect Retry-After, stop at expires_at. No transfer yet.When awaiting_paymentPOST /v1/ pay/ deposits/ { id}/ slip-token Backend sends an empty body + required Idempotency-Key before revealing instructions. The 200 response is a top-level SlipUploadCapability.202 → payable → capability → transfer - Payer transfers using current instructionscheckout_url or legs[]Open PayPage when configured, or show every leg and its expiry. Transfer from the declared sender account.
- Upload the payment slipPOST upload_urlUse slip_upload from CREATE 201, or the top-level capability from slip-token 200. Durable intake returns 202 accepted + receipt_id; verification follows.
- Read the current payment resultGET /
v1/ pay/ deposits/ { id} Use status and version. Verify webhooks: LIVE emits deposit.settled and deposit.canceled; read other status changes through GET. - Decide from the snapshotstatus = settledCredit the accepted amountamount_received_minorApply a version guard. settled can later be reversed.ORAny other statusDo not credit yetstatus + is_terminalIf reversed, claw back the prior credit. Otherwise continue or stop according to state and expiry; elapsed time does not prove payment.
POST /
import { clientFromEnv } from './client.mjs';
const client = clientFromEnv();
const request = client.payin({
amount_minor: '10000', // THB 100
currency: 'THB',
merchant_reference: 'ORDER-1001',
end_user_ref: 'customer-1',
sender: {
bank_code: '002',
account_number: '1234567890',
account_name_th: 'สมชาย ใจดี',
},
}, 'order-1001-payin'); // Read the persisted key from your order.
const result = await request.send();2
3
4
5
6
7
8
9
10
11
12
13
14
Before the first send, persist request.rawBody as text/bytea, not JSONB, with method/path/query/idempotencyKey/apiVersion as shown in Get started. Retry the same request.send(), or client. after restarting; never re-serialize the body. Use the real sender's account and a provider-confirmed bank code. Omit titles from the sender's name. Payin must be whole baht (amount_minor % 100 == 0).
Use the result
| Result | Meaning | Next step |
|---|---|---|
LIVE 201 awaiting_payment | A match exists | Open checkout_url, or use current legs[] and accept the slip. |
LIVE 202 awaiting_liquidity | Order created; waiting for a destination | Wait on PayPage, or poll GET with backoff. Do not transfer or create another order. |
Sandbox 201 is simulated: it has no real payment instructions, upload capability, or slip-token. Use POST /. Amounts of THB 1,001–2,000 settle, 2,001–3,000 reject, 3,001–4,000 reverse, 4,001–5,000 expire; other amounts wait for simulation. Use whole baht from THB 1 to 10,000,000 (100–1000000000 minor units). See Sandbox payments.
Read the existing response fields directly:
if (!result.ok) throw new Error(result.data?.error?.code ?? 'api_error');
const order = result.data;
const payPageUrl = order.checkout_url; // Pass through this customer's checkout session.
const instructions = order.legs; // Use only when awaiting_payment.
const upload = order.slip_upload; // Capability for slip upload. Never log it.2
3
4
5
checkout_url requires PayPage to be enabled and configured for this Merchant and mode. An absent URL does not mean creation failed. Keep the existing order and have your service provider configure PayPage.
Build your own checkout
Display every returned leg using its sequence/total, amount_minor, and expires_at. Multiple legs are transfer steps to complete, not alternative destinations.
- Render
qr_payloadwhen present. Fetchqr_image_urlthrough your authenticated signing backend and serve the image into the payer's session. - When
receiver.account_numberis present, show/copy that destination account with its masked name and this leg's amount. It is limited to internal P2P legs on LIVE that are currently payable, and may be absent at the read quota or when full-data admission is unavailable. Create/GET can still return the masked order. External-provider legs never expose this full number through the Merchant API; use their returned QR and masked fields. - If neither a usable QR nor a full destination account is available, open
checkout_url. Never reconstruct an account from masked digits. - Keep the warning to transfer from the declared
senderaccount, then upload the slip.
Recipient names and sender accounts remain masked. Full destination account numbers are not added to persisted receipts or webhooks. Keep payment instructions out of your database, logs, URLs, and analytics; use only this order's secure checkout session.
Latest status, optional fields, and PHP
const latest = await client.prepare('GET', `/v1/pay/deposits/${order.id}`).send();
// CREATE replay preserves the original create result. Use GET for current status.2
On LIVE your checkout must poll this GET with backoff, 3 → 5 → 10 → 30 seconds between reads, never sooner than the returned Retry-After/retry_after_seconds. Continue until the current expires_at, stopping on a terminal result or that deadline. A passed deadline does not prove payment; never automatically create a replacement Payin. When GET reports awaiting_payment, read fresh legs[]/expires_at, then request POST / with an empty body and required Idempotency-Key before revealing payment instructions. PayPage handles this flow for you:
const tokenRequest = client.slipToken(order.id, 'order-1001-slip-token');
const tokenResult = await tokenRequest.send(); // Retry the same tokenRequest.
// tokenResult.data is the upload capability.2
3
require __DIR__ . '/PgMerchantClient.php';
$apiKey = (string) getenv('PG_API_KEY');
$client = new PgMerchantClient((string) getenv('PG_API_ORIGIN'), $apiKey);
$prepared = $client->payin([
'amount_minor' => '10000', 'currency' => 'THB',
'merchant_reference' => 'ORDER-1001', 'end_user_ref' => 'customer-1',
'sender' => ['bank_code' => '002', 'account_number' => '1234567890', 'account_name_th' => 'สมชาย ใจดี'],
'metadata' => [], // Encodes as {}.
], 'order-1001-payin');
// Before sending: persist method/path/idempotencyKey/apiVersion and rawBody as text/bytea, not JSONB.
$result = $client->send($prepared);
// Retry this same array. After restarting: $prepared = $client->restore($storedFromDatabase);
// Keep rawBody as the exact original text; never re-serialize the body.
// LIVE only: one GET iteration. Repeat GET with the documented backoff/deadline if still waiting.
if (str_starts_with($apiKey, 'sk_live_') && $result['ok']) {
$current = $client->send($client->prepare('GET', '/v1/pay/deposits/' . $result['data']['id']));
if ($current['ok'] && $current['data']['status'] === 'awaiting_payment') {
$tokenRequest = $client->slipToken($current['data']['id'], 'order-1001-slip-token');
// Persist tokenRequest before sending too. Its body is exactly '', not '{}'.
$tokenResult = $client->send($tokenRequest);
// tokenResult.data is the upload capability. Keep it in the backend session; never log it.
}
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
LIVE emits only deposit.settled, deposit.canceled, withdrawal.created, withdrawal.partial_fill, and withdrawal.terminal. There is no webhook for matching, under_review, rejected, or expired; use GET as above. See the Live P2P profile.
Optionally set return_url for PayPage to return to your website. Returning does not prove payment. See the full request/response reference.