Skip to content
API documentationP2P EasyPay

Payin ​

End-to-end payin flow
  1. Create a payin
    POST /v1/pay/deposits
    Inline sender + saved Idempotency-Key
  2. Two successful LIVE responses
    201 · awaiting_payment
    Payment instructions ready
    legs[] + expires_at + slip_upload
    Use the current instructions for this order.
    201 → transfer
    OR
    202 · awaiting_liquidity
    Wait for a destination
    GET /v1/pay/deposits/{id}
    Poll with backoff, respect Retry-After, stop at expires_at. No transfer yet.
    When awaiting_payment
    POST /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
  3. Payer transfers using current instructions
    checkout_url or legs[]
    Open PayPage when configured, or show every leg and its expiry. Transfer from the declared sender account.
  4. Upload the payment slip
    POST upload_url
    Use slip_upload from CREATE 201, or the top-level capability from slip-token 200. Durable intake returns 202 accepted + receipt_id; verification follows.
  5. Read the current payment result
    GET /v1/pay/deposits/{id}
    Use status and version. Verify webhooks: LIVE emits deposit.settled and deposit.canceled; read other status changes through GET.
  6. Decide from the snapshot
    status = settled
    Credit the accepted amount
    amount_received_minor
    Apply a version guard. settled can later be reversed.
    OR
    Any other status
    Do not credit yet
    status + is_terminal
    If reversed, claw back the prior credit. Otherwise continue or stop according to state and expiry; elapsed time does not prove payment.
Use the same order throughout. Only a verified settled snapshot permits credit; HTTP 202 and the return URL do not.

POST /v1/pay/deposits

js
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();

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.rebuild(storedRequest).send() 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 ​

ResultMeaningNext step
LIVE 201 awaiting_paymentA match existsOpen checkout_url, or use current legs[] and accept the slip.
LIVE 202 awaiting_liquidityOrder created; waiting for a destinationWait 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 /v1/pay/sandbox/deposits/{id}/simulate. 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:

js
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.

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_payload when present. Fetch qr_image_url through your authenticated signing backend and serve the image into the payer's session.
  • When receiver.account_number is 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 sender account, 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
js
const latest = await client.prepare('GET', `/v1/pay/deposits/${order.id}`).send();
// CREATE replay preserves the original create result. Use GET for current status.

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 /v1/pay/deposits/{id}/slip-token with an empty body and required Idempotency-Key before revealing payment instructions. PayPage handles this flow for you:

js
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.
php
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.
    }
}

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.

เอกสารชุดนี้อิงสัญญา API เวอร์ชัน 2026-08-01