Get started
Create a Payin once. Send the customer to our PayPage, or use the returned payment instructions in your own checkout.
1. Set your API key
Get your API origin and key from the Merchant back office. Use the matching Sandbox hostname and key for testing. Set PG_API_ORIGIN and PG_API_KEY in your server's secret manager.
Download the helper into your server project. No npm package is needed:
- Node.js 22+: client.mjs
- 64-bit PHP 8.1+ with ext-curl: PgMerchantClient.php
- curl example: curl.mjs, alongside
client.mjs
2. Test your key
import { clientFromEnv } from './client.mjs';
const client = clientFromEnv();
const result = await client.authenticate();
if (!result.ok) throw new Error(result.data?.error?.code ?? 'api_error');
// result.data.available_minor is the available balance in satang.The helper handles Bearer authentication and HMAC signing. There is no additional login or access-token request.
3. Create a Payin
// Save this key with the order before sending. Keep the same body/key for retries.
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');
// orderStore is your application's order storage. Persist before the first send.
await orderStore.saveRequest('ORDER-1001', {
method: request.method, path: request.path, query: request.query,
rawBody: request.rawBody, idempotencyKey: request.idempotencyKey, apiVersion: request.apiVersion,
});
const result = await request.send();
if (!result.ok) throw new Error(result.data?.error?.code ?? 'api_error');
// Pass only the required fields into this customer's secure checkout session.
// Do not log result.data: it contains payment information and capabilities.Replace sample identity fields with the real permitted sender for that mode. Use bank codes confirmed by your service provider. No customer or bank lookup API is required first.
4. Choose your checkout
| Option | Next step |
|---|---|
| Our PayPage | Redirect to the returned checkout_url. PayPage handles waiting, payment instructions, and slip upload. |
| Your checkout | Render legs[] when status = awaiting_payment, then upload the slip. |
PayPage starts with a ready-to-use default. Optionally open Merchant back office → Settings → PayPage Editor (/) to preview/save your display name, subtitle, accent color, background color, and corner radius. No theme selection or code is required.
Display name and subtitle cannot contain invisible formatting/direction controls or runs of 6 or more digits. Merchant text appears separately from the system payment instructions.
On LIVE, 201 awaiting_payment means a match exists: use only current, unexpired payment data. 202 awaiting_liquidity means the order exists but has no destination yet. Your own checkout must poll GET / with backoff until expires_at, then obtain slip-token when payable as described in Payin. Do not wait for a matching webhook or ask the customer to transfer early. checkout_url requires PayPage configuration for this Merchant and mode.
Sandbox 201 has no real transfer legs[], upload capability, or slip-token. Use POST / or the amount ranges in Sandbox payments. Do not transfer real money.
LIVE emits only deposit.settled, deposit.canceled, withdrawal.created, withdrawal.partial_fill, and withdrawal.terminal; see the Live P2P profile. Use GET for readiness, under_review, rejected, and expired transitions. Confirm funds from verified settled evidence. A successful create, slip intake, or return from PayPage does not prove payment.
Six guides
| Guide | Endpoint |
|---|---|
| Authen | Test with GET / |
| Payin | POST / |
| Payin upload slip | POST / at the returned URL |
| Payin cancel | POST / |
| Payout | POST / |
| Get Merchant Balance | GET / |
Amounts, retries, and final results
- The helper accepts positive integer minor units as a number or canonical decimal string:
10000or'10000', sending a JSON integer. Maximum:9007199254740991. Payin must be whole baht (amount_minor % 100 == 0) and meet provider policy. Sandbox accepts whole baht from THB 1 to 10,000,000 (100–1000000000minor units) per request. - Persist each POST key before sending. Retry the same prepared
request.send(); the helper generates a fresh nonce/signature. It does not automatically retry. - Store the exact JSON text in
request.rawBodyas text/bytea, not JSONB, with method/path/query/key/API version before the first send. Protect retained PII. After restarting, useclient.rebuild(await orderStore., thenloadRequest('ORDER- 1001')) send(). Never parse/re-serialize the body or generate a new key after a timeout. - Slip intake
202accepts evidence. Wait forsettledbefore confirming funds; see LIVE results and status reads. - PHP and curl · Detailed existing contract