SiamTechPay API
Take deposits (PromptPay QR and bank transfer) and send payouts from your platform. Base URL: https://siamtechpay.com/api/v1. Amounts are in THB with up to 2 decimals (for example 500.50); fees are worked out to the satang, rounded half-up: fee = flat + round(amount × bps ÷ 10000).
Quickstart
- Sign in to the merchant portal and switch Test mode on. Under Developers you find your test API key (
pk_test_…) and secret. - Save your webhook endpoint (a public HTTPS URL) and note its signing secret.
- Sign a request (below) and create a test payment.
- End it as paid in the portal's API Simulator or with
POST /sandbox/payments/{id}/simulate; your endpoint receivespayment.paid. - Do the same for a payout. The portal's Integration checklist ticks each step as your integration does it.
- Switch Test mode off and use your live key (
pk_live_…) with the same code.
Libraries
One file each, no dependencies: payments-client.mjs (Node.js 18+) and PaymentsClient.php (PHP 7.4+ with curl). They sign every request, retry safely (with a fresh signature each time), raise errors with the code and request id, read the event feed, run test outcomes and verify callbacks.
Node.js
import { PaymentsClient } from "./payments-client.mjs"; // https://siamtechpay.com/sdk/payments-client.mjs
const api = new PaymentsClient({ baseUrl: "https://siamtechpay.com", brand: "siamtechpay",
apiKey: process.env.PAY_KEY, apiSecret: process.env.PAY_SECRET });
const p = await api.createPayment({
"amount": 250,
"channel": "QRIS",
"orderId": "ORDER-1001",
"player": {
"id": "player-1001",
"name": "Somchai Jaidee",
"bankAccount": "1234567890",
"bankCode": "SCB"
}
});
// send the player to p.checkout_url (our hosted payment page), or show p.qr_image
// in your callback route (raw body, before any JSON parsing):
const event = PaymentsClient.verifyCallback(rawBody, req.headers, process.env.PAY_CALLBACK_SECRET, { brand: "siamtechpay" });PHP
<?php
require 'PaymentsClient.php'; // https://siamtechpay.com/sdk/PaymentsClient.php
$api = new PaymentsClient('https://siamtechpay.com', getenv('PAY_KEY'), getenv('PAY_SECRET'), 'siamtechpay');
$p = $api->createPayment(json_decode('{ "amount": 250, "channel": "QRIS", "orderId": "ORDER-1001", "player": { "id": "player-1001", "name": "Somchai Jaidee", "bankAccount": "1234567890", "bankCode": "SCB" } }', true));
header('Location: ' . $p['checkout_url']); // or show $p['qr_image']
// in your callback script:
$event = PaymentsClient::verifyCallback(file_get_contents('php://input'), getallheaders(), getenv('PAY_CALLBACK_SECRET'), 'siamtechpay');Keys and test mode
Your account has two sets of credentials. Live keys move real money. Test keys belong to a separate test account with its own balance, webhook endpoint and signing secret: test payments and payouts run on our simulator, no bank and no payment provider is involved, and nothing appears in your live balance or reports. Test mode demands what live demands (for example the payer on every deposit), so an integration that passes in test works in live.
Protect the live account: limit API calls to your server IPs (portal → Settings), turn on two-factor sign-in for every Admin, and rotate keys yourself from Developers if one may have leaked (the old key keeps working for 24 hours).
Each secret (API secret and webhook signing secret) is shown once: an Admin reveals it on Developers with the payout PIN and an authenticator code. Store it in your secret manager. Lost it? Rotate keys on Developers (same PIN and code): you get a new API key and secret at once, no request to us, and the old key keeps working for 24 hours while you switch. Rotating the webhook signing secret works the same way (both signatures are sent for 24 hours).
Signing requests
Every request carries X-API-Key, X-Timestamp (ISO 8601, within 5 minutes of our clock) and X-Signature = hex HMAC-SHA256 with your API secret over METHOD:path:timestamp:sha256hex(body). The path includes the query string; a GET signs an empty body. A signature works once.
Node.js
import crypto from "node:crypto";
// Every request: X-API-Key, X-Timestamp (ISO 8601, within 5 minutes) and X-Signature.
// path = the request path INCLUDING the query string; a GET signs an empty body.
function signedHeaders(method, path, body, apiKey, apiSecret) {
const ts = new Date().toISOString();
const bodyHash = crypto.createHash("sha256").update(body ?? "").digest("hex");
const sig = crypto.createHmac("sha256", apiSecret)
.update(`${method.toUpperCase()}:${path}:${ts}:${bodyHash}`).digest("hex");
return { "Content-Type": "application/json", "X-API-Key": apiKey, "X-Timestamp": ts, "X-Signature": sig };
}PHP
<?php
// Every request: X-API-Key, X-Timestamp (ISO 8601, within 5 minutes) and X-Signature.
function signed_headers(string $method, string $path, string $body, string $apiKey, string $apiSecret): array {
$ts = gmdate('Y-m-d\TH:i:s.000\Z');
$canonical = strtoupper($method) . ':' . $path . ':' . $ts . ':' . hash('sha256', $body);
return [
'Content-Type: application/json',
'X-API-Key: ' . $apiKey,
'X-Timestamp: ' . $ts,
'X-Signature: ' . hash_hmac('sha256', $canonical, $apiSecret),
];
}Python
import datetime, hashlib, hmac
# Every request: X-API-Key, X-Timestamp (ISO 8601, within 5 minutes) and X-Signature.
def signed_headers(method, path, body, api_key, api_secret):
ts = datetime.datetime.now(datetime.timezone.utc).isoformat(timespec="milliseconds").replace("+00:00", "Z")
canonical = f"{method.upper()}:{path}:{ts}:{hashlib.sha256(body.encode()).hexdigest()}"
sig = hmac.new(api_secret.encode(), canonical.encode(), hashlib.sha256).hexdigest()
return {"Content-Type": "application/json", "X-API-Key": api_key, "X-Timestamp": ts, "X-Signature": sig}Payments
POST /payments. Amount 3 THB or more. channel is QRIS (PromptPay) or VA (bank transfer; add method = the bank code from GET /channels). Send player (who pays): the provider checks the payer's name and account. orderId is yours and makes the call safe to retry: the same orderId returns the same payment. Several websites on one account? See Sub-merchants.
POST https://siamtechpay.com/api/v1/payments
{
"amount": 250,
"channel": "QRIS",
"orderId": "ORDER-1001",
"player": {
"id": "player-1001",
"name": "Somchai Jaidee",
"bankAccount": "1234567890",
"bankCode": "SCB"
}
}The response's data has id, status (UNPAID), amount, fee, net and how the player pays: qr_content and a ready PNG qr_image, or va_number, or payment_url (the provider's own page). Every payment also has checkout_url: our hosted payment page that shows the player how to pay and updates itself until paid. Redirect to it and you need no payment screen of your own. It ends as PAID, EXPIRED, CANCELED, FAILED or later REFUNDED; you hear it by callback, and GET /payments/{id} always tells the current state.
Sub-merchants
Run several websites or brands on one account, with one API key and one callback, and see turnover for each. In the portal, Sub-merchants (Account) adds, renames, archives and restores them and shows each one's id (SITE-…, copyable) with today's and the last 30 days' turnover.
- Add each website on Sub-merchants and copy its id into that website's config.
- Send it as
siteIdon everyPOST /payments. The response andGET /payments/{id}return it assite_id;GET /payments?site_id=lists one sub-merchant's payments. - Reports shows Turnover by sub-merchant per day, with CSV export. Payments without a valid
siteIdappear as Unassigned, so the rows add up to your total.
POST https://siamtechpay.com/api/v1/payments
{ "amount": 250, "channel": "QRIS", "orderId": "ORDER-1002", "siteId": "SITE-a1b2c3d4",
"player": { "id": "player-1002", "name": "Somchai Jaidee", "bankAccount": "1234567890", "bankCode": "SCB" } }A siteId is only for reporting: an unknown, archived or another account's id never blocks the payment, it is recorded unassigned (site_id: null). Your balance and payouts stay one pool for the whole account. Test mode is a separate account: create your sub-merchants there too to test with them.
Payouts
POST /disbursements with amount (25 THB or more), bank, account, accountName (the account holder), playerId; no PIN is needed, the signed request is enough. Always send an Idempotency-Key header: a retry with the same key returns the same payout and never pays twice; the same key with a different amount or account is refused (409). Statuses: PROCESSING → COMPLETED or FAILED (the money returns to your balance); AWAITING_APPROVAL when above your approval threshold.
Callbacks
We POST each event to your endpoint the moment it happens, as JSON { event, id, created_at, data }, with headers x-siamtechpay-event, x-siamtechpay-delivery, x-siamtechpay-timestamp (when this attempt was sent) and x-siamtechpay-signature = hex HMAC-SHA256 with your webhook signing secret over timestamp + "." + rawBody. While you rotate the secret (portal → Developers), we also send x-siamtechpay-signature-previous, signed with the old one, for 24 hours.
- Answer 2xx within a few seconds, then process. Anything else is retried: 13 attempts over about 3 days. Failed ones can be resent from the portal.
- The same event can arrive more than once and not always in order: deduplicate on
idand readdata.status, or askGET /payments/{id}. - Refuse a callback whose timestamp is more than 5 minutes old (a replay). Every retry is stamped afresh.
- Choose which events you receive, and send payout events (
disbursement.*,withdrawal.*) to a separate endpoint if you like: portal → Developers → Webhooks. - Callbacks come from
159.223.134.64: you can allow-list them.
When the amount does not match
Players sometimes send a different amount, pay late, or pay with no order. Nothing is guessed: every case below is confirmed with the payment provider before any money moves, and each arrives as an ordinary payment.paid.
- Paid less than the order: the payment is credited for what arrived.
amount,feeandnetare that figure andrequested_amountis what the order asked. Always credit the playeramount, never the amount you sent. - Paid more: the order is paid as asked, and the difference arrives as a separate make-up deposit: its own
payment_id,adjustment_type: "SHORTFALL", andorigin_payment_id/origin_order_idnaming the original. - Paid after the order expired: the expired order stays expired (you were told
payment.expired); the money arrives as a make-up deposit withadjustment_type: "EXPIRED"naming it. - Paid with no order (for example to bank details from an earlier order): our team traces it and credits it as a make-up deposit with
adjustment_type: "UNMATCHED"and the order id you give us.
A make-up deposit is charged your normal deposit fee and settles like any deposit. Deduplicate on payment_id: one player transfer can produce two payments (the original and its make-up).
Node.js
import crypto from "node:crypto";
// rawBody = the exact bytes received (do not re-serialise the JSON).
function verifyCallback(rawBody, headers, callbackSecret) {
const ts = headers["x-siamtechpay-timestamp"];
if (!ts || Math.abs(Date.now() - Date.parse(ts)) > 5 * 60_000) return false; // refuse replays
const expected = crypto.createHmac("sha256", callbackSecret).update(ts + "." + rawBody).digest("hex");
// During a secret rotation we also send -previous (signed with your old secret).
return [headers["x-siamtechpay-signature"], headers["x-siamtechpay-signature-previous"]].some((s) =>
typeof s === "string" && s.length === expected.length && crypto.timingSafeEqual(Buffer.from(s), Buffer.from(expected)));
}PHP
<?php
$raw = file_get_contents('php://input'); // the exact bytes received
$ts = $_SERVER['HTTP_X_SIAMTECHPAY_TIMESTAMP'] ?? '';
if ($ts === '' || abs(time() - strtotime($ts)) > 300) { http_response_code(400); exit; } // refuse replays
$expected = hash_hmac('sha256', $ts . '.' . $raw, $callbackSecret);
$ok = false;
foreach (['HTTP_X_SIAMTECHPAY_SIGNATURE', 'HTTP_X_SIAMTECHPAY_SIGNATURE_PREVIOUS'] as $h) {
if (!empty($_SERVER[$h]) && hash_equals($expected, $_SERVER[$h])) $ok = true;
}
if (!$ok) { http_response_code(400); exit; }
http_response_code(200); // answer first, then process the event (dedupe on its "id")Python
import datetime, hashlib, hmac
def verify_callback(raw_body: bytes, headers, callback_secret: str) -> bool:
ts = headers.get("x-siamtechpay-timestamp", "")
try:
sent = datetime.datetime.fromisoformat(ts.replace("Z", "+00:00"))
except ValueError:
return False
if abs((datetime.datetime.now(datetime.timezone.utc) - sent).total_seconds()) > 300:
return False # refuse replays
expected = hmac.new(callback_secret.encode(), ts.encode() + b"." + raw_body, hashlib.sha256).hexdigest()
return any(hmac.compare_digest(expected, headers.get(h, ""))
for h in ("x-siamtechpay-signature", "x-siamtechpay-signature-previous"))| payment.paid | The player paid. Credit their wallet once per payment id. |
| payment.expired | Not paid in time; the payment is closed. |
| payment.canceled | You (or we) cancelled it before it was paid. |
| payment.refunded | A paid payment was refunded. |
| disbursement.completed | The payout reached the bank account. |
| disbursement.failed | The payout did not go through; the money is back in your balance. Return it to the player. |
| disbursement.awaiting_approval | Above your approval threshold: held until your team approves it. |
| settlement.completed | A settlement to your bank account was made. |
| webhook.test | Sent by Send test event in the portal. |
Event feed
GET /events lists every event sent to your endpoints, oldest first, as the same { id, event, created_at, data } bodies plus where each delivery stands. After downtime, walk it from your last cursor: ?after=<next_cursor> (or ?since= an ISO time), optional &type=payment.paid, up to 200 per page; keep going while has_more is true.
Every API response carries X-Request-Id (send your own to have it echoed). Quote it when you contact us: it points at the exact request.
Testing outcomes
With test keys, end any test payment or payout yourself, from code or the portal's API Simulator. We book it on your test balance and send the real signed callback; the response tells you what your endpoint answered.
POST https://siamtechpay.com/api/v1/sandbox/payments/{id}/simulate {"outcome": "paid" | "expired"}
POST https://siamtechpay.com/api/v1/sandbox/payouts/{id}/simulate {"outcome": "completed" | "failed"}
→ { "data": { "id": "…", "status": "PAID", "callback": { "event": "payment.paid", "delivered": true, "code": 200 } } }Shortcuts for automated tests, no call needed: a test payment whose amount ends in 99 pays itself and one ending in 98 expires; a test payout ending in 99 completes and one ending in 98 fails, within about 20 seconds. A test payment's checkout_url page also has a “Simulate: player paid” button.
Live keys are refused (403 live_account): live money only moves when a real payment or payout happens.
Errors
Errors are JSON { error, message }: error is a stable code, message says what to fix.
| HTTP | error | What to do |
|---|---|---|
| 401 | unauthenticated, invalid_signature, stale_request | Missing/unknown key, wrong signature, or X-Timestamp more than 5 minutes off. |
| 409 | replay_detected | That exact signature was already used: sign every request afresh. |
| 403 | ip_not_allowed, merchant_inactive | Call from an allow-listed IP; the account must be approved. |
| 429 | rate_limited | Slow down (see Retry-After). |
| 400 | invalid_body, invalid_amount, invalid_channel, payer_required, va_bank_required | Fix the request; the message says which field. |
| 402 | insufficient_funds | Not enough available balance for the payout and its fee. |
| 403 | daily_cap_exceeded, payouts_disabled | Payout limits. |
| 409 | idempotency_mismatch | That Idempotency-Key was used for a different payout. |
| 502 | provider_error | The payment provider refused or failed the request: retry with the same orderId / Idempotency-Key. |
| 503 | gateway_unavailable | No payment route right now: retry later. |
Versioning and changes
The API is /api/v1. Within v1 we only add: new endpoints, new optional request fields, new response fields and new event types. Your code must ignore fields and event types it does not know. Anything that would break an integration (removing or renaming a field, changing a meaning) comes as v2, announced at least 90 days ahead, with v1 kept running meanwhile.
- 22 Oct 2026: sub-merchants: create them in the portal and send
siteIdon payments; turnover per sub-merchant on Sub-merchants and Reports. - 21 Oct 2026: rotate API keys yourself on Developers, no request to us; the old key works for 24 hours.
- 13 Oct 2026:
checkout_urlon every payment;GET /events;X-Request-Id; test shortcuts (amounts ending 99 / 98); choose events and a separate payout endpoint; Node and PHP libraries. - 13 Oct 2026: callbacks sent the moment they happen and retried for about 3 days; each attempt signed with its own timestamp;
x-siamtechpay-signature-previousduring a secret rotation; reusing anIdempotency-Keyfor a different payout returns 409. - 12 Oct 2026: test mode on the simulator;
POST /sandbox/payments|payouts/{id}/simulate.
Endpoint reference
From the OpenAPI spec (openapi.json), with every field and response; the Postman collection signs requests for you.
POST/api/v1/auth/tokenGet a bearer token
Authenticate with account credentials `{ email, password }` to obtain an opaque bearer token. Rate limited to 10 requests/min/IP; repeated failures lock the account for 15 minutes.
GET/api/v1/meGet current user
GET/api/v1/transactionsList transactions
Module: transactions.
GET/api/v1/settlementsList settlements
Module: settlement.
GET/api/v1/payoutsList payouts
Module: payout.
GET/api/v1/missing-transactionsList missing transactions
Module: missing_transactions.
GET/api/v1/alertsList alerts
Module: alerts.
POST/api/v1/alertsUpdate alerts
Mark alerts read. Requires manage access to the alerts module.
GET/api/v1/paymentsList payments
List the merchant's payments, newest first. HMAC-signed; GET requests sign an empty body string. The signed path includes the query string.
POST/api/v1/paymentsCreate a payment
Create a payment (REAL money). HMAC-signed — see the `apiKeyHmac` scheme. Idempotent on (merchant, orderId): retrying with the same orderId returns the same payment. Returns 201 with status UNPAID and the QR / VA details.
GET/api/v1/payments/{id}Get a payment
Fetch a single payment's status and details. HMAC-signed; GET requests sign an empty body string.
POST/api/v1/payments/{id}/refundRefund a payment
Refund a captured (PAID) payment (REAL money). HMAC-signed. Reverses the ledger capture and moves the payment to status REFUNDED.
POST/api/v1/payments/{id}/cancelCancel a payment
Cancel (void) an UNPAID payment so its QR / VA can no longer be paid. HMAC-signed. Moves the payment to status CANCELED. Not available when the acquirer cannot cancel (APC Pay): 400 `cancel_unsupported` — the deposit closes on its own when the acquirer expires it.
POST/api/v1/payments/{id}/receiptAttach a transfer slip to a bank-transfer deposit
Bank transfer, step 2: send the player's transfer slip or their bank reference for an UNPAID bank-transfer (VA) deposit. We forward it to the acquirer, which verifies the transfer (APC Pay scans the slip QR). HMAC-signed. The image is validated (PNG or JPEG, at most 5 MB) and never stored. At most 5 uploads per payment.
GET/api/v1/balanceGet ledger balance
The merchant's real ledger balance, broken down into available, pending and reserved. HMAC-signed.
GET/api/v1/disbursementsList disbursements
List payouts, newest first. HMAC-signed; GET requests sign an empty body string. The signed path includes the query string.
POST/api/v1/disbursementsCreate a disbursement (payout)
Send a payout to a bank account (REAL money). HMAC-signed. Funds are reserved atomically (available → reserved) Supply an idempotency key — either the `Idempotency-Key` header or the body field `idempotency_key` — to make retries safe: a repeat with the same key returns the original payout instead of sending a second bank transfer. Returns 201 on success, 402 `insufficient_funds` if the amount exceeds the available balance. No transaction PIN is needed: the signed request is the authorisation (an old `pin` field is ignored).
POST/api/v1/sandbox/payments/{id}/simulateSimulate how a test payment ends
Test mode only — call with your TEST keys (pk_test_…). Test-mode payments run on our simulator, never at a bank or payment provider; this ends one the way a provider would (paid / expired), books it on your test balance and POSTs the real signed callback to your webhook endpoint. The response says whether your endpoint accepted it. Refused (403 live_account) with live keys, and (400 not_simulated) for anything not created in test mode.
POST/api/v1/sandbox/payouts/{id}/simulateSimulate how a test payout ends
Test mode only — call with your TEST keys (pk_test_…). Test-mode payouts run on our simulator, never at a bank or payment provider; this ends one the way a provider would (completed / failed), books it on your test balance and POSTs the real signed callback to your webhook endpoint. The response says whether your endpoint accepted it. Refused (403 live_account) with live keys, and (400 not_simulated) for anything not created in test mode.
GET/api/v1/disbursements/{id}Get a disbursement
Fetch a single payout's status and details so a merchant can poll one disbursement. HMAC-signed; GET requests sign an empty body string.
GET/api/v1/channelsChannel catalogue
This merchant's channel catalogue (the example is illustrative; call it with your keys for your real banks, limits and fees). Thai QR (PromptPay) is `channel: "QRIS"`; bank transfer is `VA`. Contents: pay-in channels with the VA banks the routed gateway can actually issue plus the per-channel fee schedule, and the full payout bank/e-wallet list accepted by POST /disbursements' `bank` field. HMAC-signed.
GET/api/v1/eventsEvent feed
Every event sent to your callback endpoints, oldest first: the same { id, event, created_at, data } bodies plus where each delivery stands. After downtime, walk it from your last next_cursor. HMAC-signed.
GET/api/v1/webhook-deliveriesWebhook delivery log
The merchant's own outbound-callback log — every signed webhook we attempted, its delivery status, attempt count, last error, next retry time, and the exact signed payload. HMAC-signed.
POST/api/v1/callbacks/providerProvider webhook (inbound)
INBOUND webhook the payment provider sends to the gateway. Signed with the shared **webhook** secret (not the merchant key) over the same canonical string, with `X-Timestamp` and `X-Signature` headers. The gateway verifies the signature, checks timestamp freshness (±5 min) and de-duplicates on the event `id` (at-most-once processing). Money flow: `payment.paid` credits the merchant's PENDING balance; settlement later moves pending → available; `disbursement.completed` moves reserved → out; `disbursement.failed` releases the reservation back to available.
