สารบัญหน้านี้ (22)
- ภาพรวม
- Workflow: ลูกค้าจ่าย PromptPay QR ที่โต๊ะ
- Workflow: PAYGATE B ล่มช่วงมื้อเย็น → สำรองอัตโนมัติ → กระทบยอดเช้า
- The Charge object
- The RoutingRule object
- The Reconciliation object
- Endpoints (10)
- POSTสร้างรายการรับชำระ
- GETดูรายการรับชำระ
- GETรายการรับชำระ
- POSTคืนเงิน
- GETผู้ให้บริการรับชำระ
- GETดูกฎ routing
- PUTแทนที่กฎ routing
- GETผลกระทบยอดรายวัน
- POSTจัดการรายการไม่ตรง
- GETรอบโอนเงินเข้าบัญชี
- Webhooks (6)
- Errors (19)
- Rate limit
- เวอร์ชัน + Changelog
- เครื่องมือ: ตัวจำลองกฎ routing
- CHUAMTHANG Hub
- Docs
- Integration API
- Payment Gateway
Payment Gateway · /v1/pg
Payment Gateway API
POS ทุกสาขาเรียก API เดียวเพื่อรับ PromptPay QR และบัตร VISA / Mastercard — Hub เลือกผู้ให้บริการที่ค่าธรรมเนียมเหมาะที่สุด สลับไปตัวสำรองเมื่อล่ม และกระทบยอดกับ POS ทุกเช้า
- 10endpoint
- 2workflow
- 3object
- 6webhook event
- 21รหัส error

โมดูลนี้ทำอะไร
- สร้างรายการรับชำระ QR / บัตร โดยไม่ผูกกับผู้ให้บริการรายใด (charge id ของ Hub)
- กฎ routing ตามช่องทาง ยอด สาขา + ผู้ให้บริการสำรองเมื่อตัวหลักล่ม
- คืนเงินเต็ม/บางส่วน · ค่าธรรมเนียมต่อรายการ · รอบโอนเงิน (T+1 / T+2)
- กระทบยอด POS กับไฟล์ของผู้ให้บริการทุกวัน + จัดการรายการไม่ตรง
ใช้เมื่อไร / ใครเรียก
- POS ตอนลูกค้าชำระเงิน
- ฝ่ายการเงินตอนเช้า (กระทบยอด/รอบโอน)
- ผู้ดูแลระบบปรับกฎ routing เมื่อเจรจาค่าธรรมเนียมใหม่
Base path/v1/pgBase URLhttps://api.chuamthang.exampleSandboxhttps://sandbox.api.chuamthang.example
การยืนยันตัวตนและสิทธิ์ (scope)
ทุกคำขอส่ง API key ในหัว Authorization: Bearer … — คีย์ sandbox ขึ้นต้น ct_test_ คีย์ production ขึ้นต้น ct_live_ · คีย์ของ POS สาขาถูกจำกัดให้เห็นเฉพาะสาขาตัวเอง (branch_not_allowed) · ส่ง Chuamthang-Version เพื่อตรึงเวอร์ชัน · คีย์แต่ละตัวมี scope ตามตารางนี้ (ขอเพิ่มได้ใน Developer Console)
GET https://sandbox.api.chuamthang.example/v1/pg/charges/pgc_8Xr4Tq HTTP/1.1
Authorization: Bearer ct_test_4Lm9QxB27dWk
Chuamthang-Version: 2026-08-01
Accept: application/json| scope | ให้ทำอะไร | ระบบที่มักใช้ |
|---|---|---|
pg.charges:write | สร้างรายการรับชำระ | POS |
pg.charges:read | ดูรายการรับชำระ | POS · การเงิน |
pg.refunds:write | คืนเงิน | POS (ผู้จัดการ) · การเงิน |
pg.config:read | ดูผู้ให้บริการและกฎ routing | การเงิน · ผู้ดูแลระบบ |
pg.config:write | แก้กฎ routing | ผู้ดูแลระบบ (2 คนอนุมัติ) |
pg.reconciliation:read | ดูผลกระทบยอดและรอบโอน | การเงิน · ERP |
pg.reconciliation:write | แก้รายการไม่ตรง | การเงิน |
Object หลัก
Chargeรายการรับชำระ 1 รายการ (ตัวอย่าง: บิลกลางวันของคุณวราภรณ์)23 ฟิลด์RoutingRuleกฎเลือกผู้ให้บริการ 1 ข้อ (ประเมินตาม priority จนเจอกฎแรกที่ตรง)12 ฟิลด์Reconciliationผลกระทบยอด 1 สาขา 1 วัน11 ฟิลด์
ความสัมพันธ์กับโมดูลอื่น
- Third-Party ServicePAYGATE A / B เป็น connector — สถานะ down จากแผงสุขภาพทำให้ routing สลับตัวสำรอง
- Webhookผู้ให้บริการแจ้งผลผ่าน webhook ขาเข้าที่ Hub ตรวจลายเซ็นและแปลงเป็นรูปแบบมาตรฐาน
- CRMรับชำระสำเร็จ → ให้แต้ม · คืนเงิน → หักแต้มคืน
- ERPยอดรอบโอนใช้ปิดลูกหนี้ผู้ให้บริการ (บัญชี 1113) ในใบสำคัญยอดขาย
- เงินเป็นสตางค์ · ค่าธรรมเนียม = round(amount × rate) ต่อรายการ · VISA / Mastercard / PromptPay เท่านั้น
- ผลการชำระมาทาง webhook เสมอ — ห้ามสรุปจากหน้าจอฝั่งลูกค้า
- Hub ไม่เก็บเลขบัตรเต็ม (เห็นแค่ยี่ห้อ + 4 หลักท้าย) — ข้อมูลบัตรอยู่ที่ผู้ให้บริการ
- บัตรทดสอบ sandbox: 4000 0000 0000 0002 (สำเร็จ) · 4000 0000 0000 9995 (ยอดไม่พอ) — เลขทดสอบ ไม่ใช่บัตรจริง
Workflow — ลำดับการทำงานจริง (2 เรื่อง)
แต่ละเรื่องดูได้ 2 แบบ: Infographic อธิบายภาษาคนทั่วไป และ Sequence ทีละขั้น กดเล่นแล้วดูคำขอ/ผลลัพธ์ของทุกขั้น (ลูกศรประ = ไม่รอผล เช่น webhook หรือคิว)
ลูกค้าจ่าย PromptPay QR ที่โต๊ะ
บิล bill_041_0187 ยอด ฿405.65 — Hub เลือก PAYGATE B ตามกฎ rr_02 เพราะค่าธรรมเนียม QR ต่ำกว่า
- ลูกค้าแอปธนาคาร
- POS สาขา
- CHUAMTHANG Hubrouting
- PAYGATE Bผู้ให้บริการสมมติ
- CRMแต้มสมาชิก
- 1
POS สาขา → CHUAMTHANG Hub
แคชเชียร์กด "จ่าย QR"
POST /v1/pg/charges - 2
CHUAMTHANG Hub → CHUAMTHANG Hub
กฎ rr_01 ไม่ตรง (ไม่ใช่บัตร) · rr_02 ตรง → PAYGATE B
- 3
CHUAMTHANG Hub → PAYGATE B
Hub ขอ QR จาก PAYGATE B พร้อมเลขอ้างอิงของ Hub
- 4
CHUAMTHANG Hub → POS สาขา
POS วาด QR บนจอลูกค้า (หมดอายุ 10 นาที)
- 5
ลูกค้า → PAYGATE B
ลูกค้าสแกนจ่าย
- 6
PAYGATE B → CHUAMTHANG Hub
PAYGATE B แจ้งว่าเงินเข้า — Hub ตรวจลายเซ็นก่อน (ดูหน้า Webhook)
ไม่รอผล (async) - 7
CHUAMTHANG Hub → POS สาขา
POS ปิดบิลและพิมพ์ใบเสร็จ
ไม่รอผล (async) - 8
POS สาขา → CRM
บิลนี้ได้แต้มต่อทันที
จ่ายสำเร็จใน 25 วินาที · ค่าธรรมเนียม ฿2.23 แทน ฿3.25 · POS ไม่ต้องรู้ว่าใช้ผู้ให้บริการรายไหน
กด เล่น หรือคลิกลูกศรในแผนภาพ เพื่อดูคำขอและผลลัพธ์ของแต่ละขั้น
1 POS สาขา CHUAMTHANG Hub
POST /v1/pg/charges
แคชเชียร์กด "จ่าย QR"
POST /v1/pg/charges HTTP/1.1
Authorization: Bearer ct_test_4Lm9QxB27dWk
Idempotency-Key: c41e7a90-2f6d-4b18-a3c5-9e0d1b7f2a63
{
"bill_id": "bill_041_0187",
"branch_id": "brn_041",
"terminal_id": "pos_041_01",
"amount": 40565,
"method": "promptpay_qr",
"metadata": {
"table": "B07"
}
}2 CHUAMTHANG Hub CHUAMTHANG Hub
ประเมินกฎ → rr_02
กฎ rr_01 ไม่ตรง (ไม่ใช่บัตร) · rr_02 ตรง → PAYGATE B
3 CHUAMTHANG Hub PAYGATE B
create QR
Hub ขอ QR จาก PAYGATE B พร้อมเลขอ้างอิงของ Hub
4 CHUAMTHANG Hub POS สาขา
201 + qr.payload
POS วาด QR บนจอลูกค้า (หมดอายุ 10 นาที)
HTTP/1.1 201 Created
{
"id": "pgc_8Xr4Tq",
"status": "pending",
"provider": "pvd_paygate_b",
"qr": {
"payload": "00020101021229370016A000000677010111021301055690004185303764540540565802TH6304C1D2",
"expires_at": "2026-10-11T12:43:41+07:00"
}
}5 ลูกค้า PAYGATE B
สแกน + ยืนยันในแอปธนาคาร
ลูกค้าสแกนจ่าย
6 PAYGATE B CHUAMTHANG Hubasync
webhook ขาเข้า (ลงลายเซ็น)
PAYGATE B แจ้งว่าเงินเข้า — Hub ตรวจลายเซ็นก่อน (ดูหน้า Webhook)
7 CHUAMTHANG Hub POS สาขาasync
webhook pg.charge.succeeded
POS ปิดบิลและพิมพ์ใบเสร็จ
HTTP/1.1 200 OK
{
"type": "pg.charge.succeeded",
"data": {
"id": "pgc_8Xr4Tq",
"amount": 40565,
"fee": 223
}
}8 POS สาขา CRM
ให้แต้ม (ดูหน้า CRM)
บิลนี้ได้แต้มต่อทันที
จ่ายสำเร็จใน 25 วินาที · ค่าธรรมเนียม ฿2.23 แทน ฿3.25 · POS ไม่ต้องรู้ว่าใช้ผู้ให้บริการรายไหน
PAYGATE B ล่มช่วงมื้อเย็น → สำรองอัตโนมัติ → กระทบยอดเช้า
PAYGATE B ตอบช้าเกินจนแผงสุขภาพเป็น down — รายการบัตรยอดสูงที่ควรไป B ถูกส่งไป A แทน และเช้าวันถัดไปฝ่ายการเงินแก้ 2 รายการที่ไม่ตรง
- POS สาขา
- CHUAMTHANG Hub
- PAYGATE B
- PAYGATE A
- ฝ่ายการเงินสำนักงานใหญ่
- 1
CHUAMTHANG Hub → PAYGATE B
PAYGATE B ไม่ตอบหลายครั้งติด อัตราสำเร็จตกต่ำกว่า 95%
- 2
CHUAMTHANG Hub → CHUAMTHANG Hub
Hub ตั้งสถานะผู้ให้บริการ B เป็น down และส่ง connector.health_changed
- 3
POS สาขา → CHUAMTHANG Hub
บิลบัตรยอดสูงเข้ามา
POST /v1/pg/charges - 4
CHUAMTHANG Hub → PAYGATE A
กฎ rr_03 (บัตร ≥ ฿1,500) ตรง แต่ B ล่ม → ใช้ fallback_to = PAYGATE A
- 5
CHUAMTHANG Hub → POS สาขา
POS สั่งเครื่องรูดบัตรได้ตามปกติ
- 6
POS สาขา → POS สาขา
อินเทอร์เน็ตสาขาหลุด 7 นาที — ลูกค้า 1 โต๊ะจ่าย QR ไปแล้วแต่ POS บันทึกบิลทีหลังโดยไม่มีเลขอ้างอิง
- 7
CHUAMTHANG Hub → CHUAMTHANG Hub
เทียบ POS ฿35,292.84 กับผู้ให้บริการ ฿35,448.84 พบข้อยกเว้น 2 รายการ
ไม่รอผล (async) - 8
ฝ่ายการเงิน → CHUAMTHANG Hub
ฝ่ายการเงินเปิดผลตอนเช้า
GET /v1/pg/reconciliation?date=2026-10-11&branch_id=brn_041 - 9
ฝ่ายการเงิน → CHUAMTHANG Hub
ลองผูกบิลกับรายการที่ยอดไม่ตรง — ระบบไม่ยอม
POST /v1/pg/reconciliation/rcn_041_20261011/resolve - 10
ฝ่ายการเงิน → CHUAMTHANG Hub
ผูกบิลที่บันทึกตอนออฟไลน์ และแก้ยอดบิลใน POS ให้ตรงกับที่ลูกค้าจ่ายจริง
POST /v1/pg/reconciliation/rcn_041_20261011/resolve - 11
CHUAMTHANG Hub → ฝ่ายการเงิน
ยอดกระทบตรงแล้ว ERP ใช้ยอดนี้ตั้งลูกหนี้ผู้ให้บริการ
ไม่รอผล (async)
ไม่มีบิลค้างจ่ายระหว่างผู้ให้บริการล่ม · กระทบยอด 240/242 รายการตรงอัตโนมัติ · ข้อยกเว้น 2 รายการแก้เสร็จก่อน 09:10
กด เล่น หรือคลิกลูกศรในแผนภาพ เพื่อดูคำขอและผลลัพธ์ของแต่ละขั้น
1 CHUAMTHANG Hub PAYGATE B
สร้างรายการ → timeout 8 วิ (3 ครั้ง/นาที)
PAYGATE B ไม่ตอบหลายครั้งติด อัตราสำเร็จตกต่ำกว่า 95%
2 CHUAMTHANG Hub CHUAMTHANG Hub
สุขภาพ con_pgb = down
Hub ตั้งสถานะผู้ให้บริการ B เป็น down และส่ง connector.health_changed
3 POS สาขา CHUAMTHANG Hub
POST /v1/pg/charges (บัตร ฿1,860)
บิลบัตรยอดสูงเข้ามา
POST /v1/pg/charges HTTP/1.1
Authorization: Bearer ct_test_4Lm9QxB27dWk
{
"bill_id": "bill_041_0351",
"branch_id": "brn_041",
"amount": 186000,
"method": "card"
}4 CHUAMTHANG Hub PAYGATE A
กฎ rr_03 → สำรอง A
กฎ rr_03 (บัตร ≥ ฿1,500) ตรง แต่ B ล่ม → ใช้ fallback_to = PAYGATE A
5 CHUAMTHANG Hub POS สาขา
201 (failover: true)
POS สั่งเครื่องรูดบัตรได้ตามปกติ
HTTP/1.1 201 Created
{
"id": "pgc_5Kc2Rw",
"status": "requires_action",
"provider": "pvd_paygate_a",
"routing": {
"rule_id": "rr_03",
"failover": true
}
}6 POS สาขา POS สาขา
POS ออฟไลน์ 21:57–22:04
อินเทอร์เน็ตสาขาหลุด 7 นาที — ลูกค้า 1 โต๊ะจ่าย QR ไปแล้วแต่ POS บันทึกบิลทีหลังโดยไม่มีเลขอ้างอิง
7 CHUAMTHANG Hub CHUAMTHANG Hubasync
กระทบยอด 04:00
เทียบ POS ฿35,292.84 กับผู้ให้บริการ ฿35,448.84 พบข้อยกเว้น 2 รายการ
8 ฝ่ายการเงิน CHUAMTHANG Hub
GET /v1/pg/reconciliation?date=2026-10-11
ฝ่ายการเงินเปิดผลตอนเช้า
GET /v1/pg/reconciliation?date=2026-10-11&branch_id=brn_041 HTTP/1.1
Authorization: Bearer ct_test_4Lm9QxB27dWkHTTP/1.1 200 OK
{
"id": "rcn_041_20261011",
"difference": 15600,
"matched": 240,
"exceptions": [
{
"id": "rex_01",
"type": "missing_in_pos",
"pg_amount": 12900,
"suggested": "link_bill"
},
{
"id": "rex_02",
"type": "amount_mismatch",
"pg_amount": 28500,
"suggested": "adjust_pos"
}
]
}9 ฝ่ายการเงิน CHUAMTHANG Hub
resolve rex_02 (ส่ง bill_id ผิด)
ลองผูกบิลกับรายการที่ยอดไม่ตรง — ระบบไม่ยอม
POST /v1/pg/reconciliation/rcn_041_20261011/resolve HTTP/1.1
Authorization: Bearer ct_test_4Lm9QxB27dWk
{
"exception_id": "rex_02",
"action": "link_bill",
"bill_id": "bill_041_0233"
}HTTP/1.1 422 Unprocessable Entity
{
"error": {
"code": "validation_failed",
"message": "link_bill ใช้กับ missing_in_pos เท่านั้น — รายการนี้ยอดไม่ตรง ใช้ adjust_pos หรือ refund_difference"
}
}10 ฝ่ายการเงิน CHUAMTHANG Hub
resolve rex_01 link_bill · rex_02 adjust_pos
ผูกบิลที่บันทึกตอนออฟไลน์ และแก้ยอดบิลใน POS ให้ตรงกับที่ลูกค้าจ่ายจริง
POST /v1/pg/reconciliation/rcn_041_20261011/resolve HTTP/1.1
Authorization: Bearer ct_test_4Lm9QxB27dWk
{
"exception_id": "rex_01",
"action": "link_bill",
"bill_id": "bill_041_0379",
"resolved_by": "emp_ho_fin_04"
}HTTP/1.1 200 OK
{
"id": "rcn_041_20261011",
"status": "resolved"
}11 CHUAMTHANG Hub ฝ่ายการเงินasync
webhook pg.reconciliation.resolved
ยอดกระทบตรงแล้ว ERP ใช้ยอดนี้ตั้งลูกหนี้ผู้ให้บริการ
ไม่มีบิลค้างจ่ายระหว่างผู้ให้บริการล่ม · กระทบยอด 240/242 รายการตรงอัตโนมัติ · ข้อยกเว้น 2 รายการแก้เสร็จก่อน 09:10
Objects
The Charge object
รายการรับชำระ 1 รายการ (ตัวอย่าง: บิลกลางวันของคุณวราภรณ์)
idstringไม่บังคับอ่านอย่างเดียวรหัสรายการรับชำระใน Hub (ใช้แทนเลขของผู้ให้บริการ — เปลี่ยนผู้ให้บริการได้โดย POS ไม่ต้องแก้)
objectstringไม่บังคับอ่านอย่างเดียวชนิด object
bill_idstringจำเป็นบิล POS ที่ชำระ (1 บิลมีได้หลาย charge เมื่อแบ่งจ่าย)
branch_idstringจำเป็นสาขา
terminal_idstringไม่บังคับเครื่อง POS
amountintegerจำเป็นยอด (สตางค์) ต่ำสุด 100 สูงสุด 5,000,000
currencystringไม่บังคับสกุลเงิน
methodstringจำเป็นช่องทาง
statusstringไม่บังคับอ่านอย่างเดียวสถานะ
providerstringไม่บังคับอ่านอย่างเดียวผู้ให้บริการที่ routing เลือก
provider_refstringไม่บังคับอ่านอย่างเดียวเลขอ้างอิงฝั่งผู้ให้บริการ (ใช้ตอนติดต่อผู้ให้บริการ)
routingobjectไม่บังคับอ่านอย่างเดียวเหตุผลที่เลือกผู้ให้บริการ
ฟิลด์ย่อยของ
routing(2)rule_idstringไม่บังคับกฎที่ตรง
failoverbooleanไม่บังคับtrue = ผู้ให้บริการหลักของกฎล่ม ใช้ตัวสำรอง
feeintegerไม่บังคับอ่านอย่างเดียวค่าธรรมเนียม (สตางค์) = round(amount × fee_rate)
fee_ratenumberไม่บังคับอ่านอย่างเดียวอัตราค่าธรรมเนียมที่ใช้
netintegerไม่บังคับอ่านอย่างเดียวยอดที่จะได้รับโอน = amount − fee
qrobjectไม่บังคับอ่านอย่างเดียวเมื่อ method = promptpay_qr
ฟิลด์ย่อยของ
qr(2)payloadstringไม่บังคับข้อความ PromptPay QR (POS วาดเป็น QR เอง)
expires_atstring · date-timeไม่บังคับQR หมดอายุ (10 นาที)
cardobjectไม่บังคับอ่านอย่างเดียวเมื่อ method = card (ไม่เก็บเลขบัตรเต็ม)
ฟิลด์ย่อยของ
card(3)brandstringไม่บังคับยี่ห้อ
last4stringไม่บังคับ4 หลักท้าย
entrystringไม่บังคับวิธีอ่านบัตร
refundedintegerไม่บังคับอ่านอย่างเดียวคืนเงินแล้วรวม
refundable_amountintegerไม่บังคับอ่านอย่างเดียวคืนได้อีก = amount − refunded
failureobjectไม่บังคับอ่านอย่างเดียวเมื่อ failed
ฟิลด์ย่อยของ
failure(2)codestringไม่บังคับรหัส
decline_codestringไม่บังคับเหตุผลจากผู้ออกบัตร
created_atstring · date-timeไม่บังคับอ่านอย่างเดียวสร้างเมื่อ
succeeded_atstring · date-timeไม่บังคับอ่านอย่างเดียวชำระสำเร็จเมื่อ
metadataobjectไม่บังคับข้อมูลเพิ่มเติม (เช่น หมายเลขโต๊ะ)
{
"id": "pgc_8Xr4Tq",
"object": "pg_charge",
"bill_id": "bill_041_0187",
"branch_id": "brn_041",
"terminal_id": "pos_041_01",
"amount": 40565,
"currency": "THB",
"method": "promptpay_qr",
"status": "succeeded",
"provider": "pvd_paygate_b",
"provider_ref": "PGB-20261011-7741902",
"routing": {
"rule_id": "rr_02",
"failover": false
},
"fee": 223,
"fee_rate": 0.0055,
"net": 40342,
"qr": {
"payload": "00020101021229370016A000000677010111021301055690004185303764540540565802TH6304C1D2",
"expires_at": "2026-10-11T12:43:41+07:00"
},
"card": null,
"refunded": 0,
"refundable_amount": 40565,
"failure": null,
"created_at": "2026-10-11T12:33:41+07:00",
"succeeded_at": "2026-10-11T12:34:06+07:00",
"metadata": {
"table": "B07"
}
}
The RoutingRule object
กฎเลือกผู้ให้บริการ 1 ข้อ (ประเมินตาม priority จนเจอกฎแรกที่ตรง)
idstringจำเป็นรหัสกฎ
priorityintegerจำเป็นลำดับประเมิน (น้อยก่อน ห้ามซ้ำ)
namestringจำเป็นชื่อกฎ
whenobjectไม่บังคับเงื่อนไข (ทุกข้อต้องจริง · ไม่ใส่ = ไม่จำกัด)
ฟิลด์ย่อยของ
when(4)methodstringไม่บังคับช่องทาง
min_amountintegerไม่บังคับยอดขั้นต่ำ (สตางค์)
max_amountintegerไม่บังคับยอดสูงสุด (สตางค์)
branchesarray<string>ไม่บังคับเฉพาะสาขา
route_tostringจำเป็นผู้ให้บริการหลัก
fallback_tostringจำเป็นผู้ให้บริการสำรองเมื่อหลักล่ม (สุขภาพ connector = down)
enabledbooleanไม่บังคับเปิดใช้กฎนี้ (ปิดชั่วคราวได้โดยไม่ลบ)
descriptionstringไม่บังคับเหตุผลทางธุรกิจของกฎ (แสดงในล็อกการตัดสินใจ)
effective_fromstring · date-timeไม่บังคับเริ่มมีผลเมื่อ (ตั้งล่วงหน้าตามวันเริ่มสัญญาได้)
statsobjectไม่บังคับอ่านอย่างเดียวสถิติ 24 ชม. ของกฎ
ฟิลด์ย่อยของ
stats(2)matched_24hintegerไม่บังคับจำนวนรายการที่ตรงกฎนี้
failover_24hintegerไม่บังคับจำนวนที่ใช้ตัวสำรอง
updated_atstring · date-timeไม่บังคับอ่านอย่างเดียวแก้ล่าสุด
updated_bystringไม่บังคับอ่านอย่างเดียวผู้แก้ (ต้องมีผู้อนุมัติคนที่สอง)
{
"id": "rr_03",
"priority": 30,
"name": "บัตรยอดตั้งแต่ ฿1,500 ใช้อัตราลด",
"when": {
"method": "card",
"min_amount": 150000
},
"route_to": "pvd_paygate_b",
"fallback_to": "pvd_paygate_a",
"enabled": true,
"description": "สัญญา PAYGATE B ให้อัตรา 1.95% เมื่อยอดตั้งแต่ ฿1,500",
"effective_from": "2026-08-01T00:00:00+07:00",
"stats": {
"matched_24h": 412,
"failover_24h": 37
},
"updated_at": "2026-09-28T16:40:00+07:00",
"updated_by": "emp_ho_fin_04"
}
The Reconciliation object
ผลกระทบยอด 1 สาขา 1 วัน
idstringไม่บังคับอ่านอย่างเดียวรหัสการกระทบยอด (สาขา + วัน)
objectstringไม่บังคับอ่านอย่างเดียวชนิด object
datestring · dateไม่บังคับอ่านอย่างเดียววันทำการ
branch_idstringไม่บังคับอ่านอย่างเดียวสาขา
statusstringไม่บังคับอ่านอย่างเดียวสถานะ
posobjectไม่บังคับอ่านอย่างเดียวยอด QR + บัตรตาม POS
ฟิลด์ย่อยของ
pos(2)countintegerไม่บังคับจำนวนรายการ
amountintegerไม่บังคับยอดรวม (สตางค์)
providersobjectไม่บังคับอ่านอย่างเดียวยอดตามไฟล์ของผู้ให้บริการ
ฟิลด์ย่อยของ
providers(2)countintegerไม่บังคับจำนวนรายการ
amountintegerไม่บังคับยอดรวม (สตางค์)
differenceintegerไม่บังคับอ่านอย่างเดียวproviders.amount − pos.amount
matchedintegerไม่บังคับอ่านอย่างเดียวจำนวนรายการที่จับคู่ได้ตรง
exceptionsarray<object>ไม่บังคับอ่านอย่างเดียวรายการที่ไม่ตรง
ฟิลด์ย่อยของ
exceptions(8)idstringไม่บังคับรหัสข้อยกเว้น
typestringไม่บังคับชนิด
charge_idstringไม่บังคับรายการรับชำระ
bill_idstringไม่บังคับบิล POS (ถ้ามี)
pos_amountintegerไม่บังคับยอดตาม POS
pg_amountintegerไม่บังคับยอดตามผู้ให้บริการ
suggestedstringไม่บังคับการแก้ที่ระบบแนะนำ
statusstringไม่บังคับสถานะ
completed_atstring · date-timeไม่บังคับอ่านอย่างเดียวเวลากระทบยอดเสร็จ
{
"id": "rcn_041_20261011",
"object": "pg_reconciliation",
"date": "2026-10-11",
"branch_id": "brn_041",
"status": "exceptions_found",
"pos": {
"count": 241,
"amount": 3529284
},
"providers": {
"count": 242,
"amount": 3544884
},
"difference": 15600,
"matched": 240,
"exceptions": [
{
"id": "rex_01",
"type": "missing_in_pos",
"charge_id": "pgc_9Lm2Vb",
"bill_id": null,
"pos_amount": 0,
"pg_amount": 12900,
"note": "POS ออฟไลน์ 21:57–22:04 บิลถูกบันทึกภายหลังโดยไม่มีเลขอ้างอิงการชำระ",
"suggested": "link_bill",
"candidate_bill": "bill_041_0379",
"status": "open",
"resolution": null
},
{
"id": "rex_02",
"type": "amount_mismatch",
"charge_id": "pgc_4Qa8Ne",
"bill_id": "bill_041_0233",
"pos_amount": 25800,
"pg_amount": 28500,
"note": "แก้รายการในบิลหลังรับชำระด้วยบัตร (ลบชาไทย 1 แก้ว — ฿27.00 ไม่ตรงราคา)",
"suggested": "adjust_pos",
"candidate_bill": null,
"status": "open",
"resolution": null
}
],
"completed_at": "2026-10-12T04:12:30+07:00"
}Endpoints (10)
| Method | Path | ทำอะไร | scope |
|---|---|---|---|
| POST | /v1/pg/charges | สร้างรายการรับชำระidempotent | pg.charges:write |
| GET | /v1/pg/charges/{charge_id} | ดูรายการรับชำระ | pg.charges:read |
| GET | /v1/pg/charges | รายการรับชำระ | pg.charges:read |
| POST | /v1/pg/refunds | คืนเงินidempotent | pg.refunds:write |
| GET | /v1/pg/providers | ผู้ให้บริการรับชำระ | pg.config:read |
| GET | /v1/pg/routing-rules | ดูกฎ routing | pg.config:read |
| PUT | /v1/pg/routing-rules | แทนที่กฎ routing | pg.config:write |
| GET | /v1/pg/reconciliation | ผลกระทบยอดรายวัน | pg.reconciliation:read |
| POST | /v1/pg/reconciliation/{reconciliation_id}/resolve | จัดการรายการไม่ตรงidempotent | pg.reconciliation:write |
| GET | /v1/pg/settlements | รอบโอนเงินเข้าบัญชี | pg.reconciliation:read |
สร้างรายการรับชำระ
POS ขอรับชำระบิล — Hub เลือกผู้ให้บริการตามกฎ routing (และสำรองถ้าล่ม) แล้วคืน QR payload หรือคำสั่งให้เครื่องรูดบัตร · ผลสุดท้ายมาทาง webhook
Headersheader
Idempotency-Keystring · uuidไม่บังคับกันรายการซ้ำเมื่อส่งซ้ำ (เก็บ 24 ชม.) — แนะนำ UUID v4 ต่อ 1 รายการ
X-Branch-Idstringไม่บังคับสาขาที่ทำรายการ (บังคับสำหรับคีย์ระดับสำนักงานใหญ่ที่ทำแทนสาขา)
Request bodyapplication/json
bill_idstringจำเป็นบิล POS
branch_idstringจำเป็นสาขา
terminal_idstringไม่บังคับเครื่อง POS
amountintegerจำเป็นยอด (สตางค์)
methodstringจำเป็นช่องทาง
providerstringไม่บังคับบังคับผู้ให้บริการ (ข้ามกฎ — ใช้ทดสอบเท่านั้น)
metadataobjectไม่บังคับข้อมูลเพิ่มเติม
ผลลัพธ์
- 201สร้างแล้ว — กฎ rr_02 เลือก PAYGATE B (status = pending รอสแกน)
- 503ผู้ให้บริการหลักและสำรองล่มทั้งคู่
- 400
invalid_requestคำขอไม่ถูกต้อง - 422
amount_too_smallยอดต่ำกว่าขั้นต่ำ - 422
amount_too_largeยอดเกินเพดาน - 422
no_routeไม่มีกฎ routing ที่ตรง - 503
all_providers_unavailableผู้ให้บริการรับชำระล่มทั้งหมด - 403
branch_not_allowedคีย์นี้เข้าถึงสาขานี้ไม่ได้ - 409
idempotency_conflictIdempotency-Key ซ้ำแต่เนื้อหาต่าง - 429
rate_limitedเรียกเกินโควตา
- ค่าธรรมเนียมตัวอย่าง: QR ฿405.65 ผ่าน PAYGATE B 0.55% = ฿2.23 (PAYGATE A 0.80% = ฿3.25)
- QR หมดอายุ 10 นาที — หมดแล้วได้ webhook pg.charge.expired ให้ POS สร้างใหม่
- อย่าตัดสินว่าจ่ายแล้วจากการสแกนฝั่งลูกค้า ให้รอ pg.charge.succeeded หรือ GET สถานะ
curl -X POST "https://sandbox.api.chuamthang.example/v1/pg/charges" \
-H "Authorization: Bearer ct_test_4Lm9QxB27dWk" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f" \
-H "Chuamthang-Version: 2026-08-01" \
-d '{
"bill_id": "bill_041_0187",
"branch_id": "brn_041",
"terminal_id": "pos_041_01",
"amount": 40565,
"method": "promptpay_qr",
"metadata": {
"table": "B07"
}
}'const API_KEY = process.env.API_KEY; // ct_test_4Lm9QxB27dWk
const res = await fetch('https://sandbox.api.chuamthang.example/v1/pg/charges', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': '7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f',
'Chuamthang-Version': '2026-08-01',
},
body: JSON.stringify({
"bill_id": "bill_041_0187",
"branch_id": "brn_041",
"terminal_id": "pos_041_01",
"amount": 40565,
"method": "promptpay_qr",
"metadata": {
"table": "B07"
}
}),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # ct_test_4Lm9QxB27dWk
res = requests.post(
"https://sandbox.api.chuamthang.example/v1/pg/charges",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Idempotency-Key": "7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f",
"Chuamthang-Version": "2026-08-01",
},
json={
"bill_id": "bill_041_0187",
"branch_id": "brn_041",
"terminal_id": "pos_041_01",
"amount": 40565,
"method": "promptpay_qr",
"metadata": {
"table": "B07"
}
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "pgc_8Xr4Tq",
"object": "pg_charge",
"bill_id": "bill_041_0187",
"branch_id": "brn_041",
"terminal_id": "pos_041_01",
"amount": 40565,
"currency": "THB",
"method": "promptpay_qr",
"status": "pending",
"provider": "pvd_paygate_b",
"provider_ref": null,
"routing": {
"rule_id": "rr_02",
"failover": false
},
"fee": null,
"fee_rate": 0.0055,
"net": null,
"qr": {
"payload": "00020101021229370016A000000677010111021301055690004185303764540540565802TH6304C1D2",
"expires_at": "2026-10-11T12:43:41+07:00"
},
"card": null,
"refunded": 0,
"refundable_amount": 40565,
"failure": null,
"created_at": "2026-10-11T12:33:41+07:00",
"succeeded_at": null,
"metadata": {
"table": "B07"
}
}{
"error": {
"code": "all_providers_unavailable",
"message": "PAYGATE B และ PAYGATE A ไม่พร้อมใช้งาน — รับเงินสดแทน",
"request_id": "req_0Zt5Kc9M"
}
}{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#invalid_request"
}
}{
"error": {
"code": "amount_too_small",
"message": "ยอดต่ำกว่าขั้นต่ำ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#amount_too_small"
}
}{
"error": {
"code": "amount_too_large",
"message": "ยอดเกินเพดาน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#amount_too_large"
}
}{
"error": {
"code": "no_route",
"message": "ไม่มีกฎ routing ที่ตรง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#no_route"
}
}{
"error": {
"code": "all_providers_unavailable",
"message": "ผู้ให้บริการรับชำระล่มทั้งหมด",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#all_providers_unavailable"
}
}{
"error": {
"code": "branch_not_allowed",
"message": "คีย์นี้เข้าถึงสาขานี้ไม่ได้",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#branch_not_allowed"
}
}{
"error": {
"code": "idempotency_conflict",
"message": "Idempotency-Key ซ้ำแต่เนื้อหาต่าง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#idempotency_conflict"
}
}{
"error": {
"code": "rate_limited",
"message": "เรียกเกินโควตา",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#rate_limited"
}
}ดูรายการรับชำระ
สถานะล่าสุด ค่าธรรมเนียม ยอดคืนได้ — POS ใช้ถามซ้ำเมื่อไม่ได้รับ webhook ภายใน 30 วินาที
Path parameterspath
charge_idstringจำเป็นรหัส pgc_…
ผลลัพธ์
- 200รายการ (สำเร็จแล้ว)
- 404
charge_not_foundไม่พบรายการรับชำระ - 403
branch_not_allowedคีย์นี้เข้าถึงสาขานี้ไม่ได้
curl -X GET "https://sandbox.api.chuamthang.example/v1/pg/charges/pgc_8Xr4Tq" \
-H "Authorization: Bearer ct_test_4Lm9QxB27dWk" \
-H "Chuamthang-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // ct_test_4Lm9QxB27dWk
const res = await fetch('https://sandbox.api.chuamthang.example/v1/pg/charges/pgc_8Xr4Tq', {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Chuamthang-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # ct_test_4Lm9QxB27dWk
res = requests.get(
"https://sandbox.api.chuamthang.example/v1/pg/charges/pgc_8Xr4Tq",
headers={
"Authorization": f"Bearer {API_KEY}",
"Chuamthang-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "pgc_8Xr4Tq",
"object": "pg_charge",
"bill_id": "bill_041_0187",
"branch_id": "brn_041",
"terminal_id": "pos_041_01",
"amount": 40565,
"currency": "THB",
"method": "promptpay_qr",
"status": "succeeded",
"provider": "pvd_paygate_b",
"provider_ref": "PGB-20261011-7741902",
"routing": {
"rule_id": "rr_02",
"failover": false
},
"fee": 223,
"fee_rate": 0.0055,
"net": 40342,
"qr": {
"payload": "00020101021229370016A000000677010111021301055690004185303764540540565802TH6304C1D2",
"expires_at": "2026-10-11T12:43:41+07:00"
},
"card": null,
"refunded": 0,
"refundable_amount": 40565,
"failure": null,
"created_at": "2026-10-11T12:33:41+07:00",
"succeeded_at": "2026-10-11T12:34:06+07:00",
"metadata": {
"table": "B07"
}
}{
"error": {
"code": "charge_not_found",
"message": "ไม่พบรายการรับชำระ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#charge_not_found"
}
}{
"error": {
"code": "branch_not_allowed",
"message": "คีย์นี้เข้าถึงสาขานี้ไม่ได้",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#branch_not_allowed"
}
}รายการรับชำระ
ค้นตามสาขา บิล สถานะ ช่องทาง ผู้ให้บริการ ช่วงเวลา
Query parametersquery
branch_idstringไม่บังคับสาขา
bill_idstringไม่บังคับบิล
statusstringไม่บังคับสถานะ
methodstringไม่บังคับช่องทาง
providerstringไม่บังคับผู้ให้บริการ
created_fromstring · date-timeไม่บังคับตั้งแต่
created_tostring · date-timeไม่บังคับถึง
sortstringไม่บังคับเรียงลำดับ — ใส่ - นำหน้าเพื่อเรียงจากมากไปน้อย
limitintegerไม่บังคับจำนวนรายการต่อหน้า
starting_afterstringไม่บังคับcursor — รหัสของรายการสุดท้ายในหน้าก่อน (ใช้ค่า next_cursor ที่ได้)
ending_beforestringไม่บังคับcursor ย้อนกลับ — รหัสของรายการแรกในหน้าปัจจุบัน
ผลลัพธ์
- 200รายการ
- 400
invalid_requestคำขอไม่ถูกต้อง - 403
branch_not_allowedคีย์นี้เข้าถึงสาขานี้ไม่ได้
curl -X GET "https://sandbox.api.chuamthang.example/v1/pg/charges?branch_id=brn_041&status=succeeded&limit=20" \
-H "Authorization: Bearer ct_test_4Lm9QxB27dWk" \
-H "Chuamthang-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // ct_test_4Lm9QxB27dWk
const res = await fetch('https://sandbox.api.chuamthang.example/v1/pg/charges?branch_id=brn_041&status=succeeded&limit=20', {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Chuamthang-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # ct_test_4Lm9QxB27dWk
res = requests.get(
"https://sandbox.api.chuamthang.example/v1/pg/charges?branch_id=brn_041&status=succeeded&limit=20",
headers={
"Authorization": f"Bearer {API_KEY}",
"Chuamthang-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"object": "list",
"data": [
{
"id": "pgc_8Xr4Tq",
"bill_id": "bill_041_0187",
"amount": 40565,
"method": "promptpay_qr",
"provider": "pvd_paygate_b",
"status": "succeeded",
"created_at": "2026-10-11T12:33:41+07:00"
},
{
"id": "pgc_7Fh1Ka",
"bill_id": "bill_041_0161",
"amount": 32800,
"method": "card",
"provider": "pvd_paygate_a",
"status": "succeeded",
"created_at": "2026-10-11T12:05:10+07:00"
}
],
"has_more": true,
"next_cursor": "pgc_7Fh1Ka"
}{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#invalid_request"
}
}{
"error": {
"code": "branch_not_allowed",
"message": "คีย์นี้เข้าถึงสาขานี้ไม่ได้",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#branch_not_allowed"
}
}คืนเงิน
คืนเต็มหรือบางส่วน (หลายครั้งได้ไม่เกินยอดที่รับ) ผ่านผู้ให้บริการเดิมของรายการ · QR คืนโดยโอนกลับบัญชีต้นทาง
Headersheader
Idempotency-Keystring · uuidไม่บังคับกันรายการซ้ำเมื่อส่งซ้ำ (เก็บ 24 ชม.) — แนะนำ UUID v4 ต่อ 1 รายการ
Request bodyapplication/json
charge_idstringจำเป็นรายการที่คืน
amountintegerไม่บังคับยอดคืน (ไม่ระบุ = คืนเต็มที่เหลือ)
reasonstringจำเป็นเหตุผล
approved_bystringไม่บังคับผู้จัดการสาขาที่อนุมัติ (บังคับเมื่อยอด > ฿500)
ผลลัพธ์
- 201สร้างการคืนเงิน (บัตร 7–14 วัน · QR 1–2 วันทำการ)
- 404
charge_not_foundไม่พบรายการรับชำระ - 422
refund_exceeds_chargeคืนเงินเกินยอดที่รับ - 422
validation_failedข้อมูลไม่ผ่านกฎธุรกิจ - 409
idempotency_conflictIdempotency-Key ซ้ำแต่เนื้อหาต่าง - 502
upstream_errorระบบปลายทางตอบผิดพลาด
- ตัวอย่าง: คืนค่าชาไทยที่หมด ฿45.00 จากรายการบัตร ฿328.00 → คืนได้อีก ฿283.00
- คืนเงินแล้ว CRM ได้ event และหักแต้มของบิลตามสัดส่วนให้อัตโนมัติ
curl -X POST "https://sandbox.api.chuamthang.example/v1/pg/refunds" \
-H "Authorization: Bearer ct_test_4Lm9QxB27dWk" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f" \
-H "Chuamthang-Version: 2026-08-01" \
-d '{
"charge_id": "pgc_7Fh1Ka",
"amount": 4500,
"reason": "item_unavailable",
"approved_by": "emp_041_001"
}'const API_KEY = process.env.API_KEY; // ct_test_4Lm9QxB27dWk
const res = await fetch('https://sandbox.api.chuamthang.example/v1/pg/refunds', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': '7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f',
'Chuamthang-Version': '2026-08-01',
},
body: JSON.stringify({
"charge_id": "pgc_7Fh1Ka",
"amount": 4500,
"reason": "item_unavailable",
"approved_by": "emp_041_001"
}),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # ct_test_4Lm9QxB27dWk
res = requests.post(
"https://sandbox.api.chuamthang.example/v1/pg/refunds",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Idempotency-Key": "7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f",
"Chuamthang-Version": "2026-08-01",
},
json={
"charge_id": "pgc_7Fh1Ka",
"amount": 4500,
"reason": "item_unavailable",
"approved_by": "emp_041_001"
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "pgr_2Wd7",
"object": "pg_refund",
"charge_id": "pgc_7Fh1Ka",
"amount": 4500,
"reason": "item_unavailable",
"status": "pending",
"provider": "pvd_paygate_a",
"created_at": "2026-10-11T12:15:02+07:00"
}{
"error": {
"code": "charge_not_found",
"message": "ไม่พบรายการรับชำระ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#charge_not_found"
}
}{
"error": {
"code": "refund_exceeds_charge",
"message": "คืนเงินเกินยอดที่รับ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#refund_exceeds_charge"
}
}{
"error": {
"code": "validation_failed",
"message": "ข้อมูลไม่ผ่านกฎธุรกิจ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#validation_failed"
}
}{
"error": {
"code": "idempotency_conflict",
"message": "Idempotency-Key ซ้ำแต่เนื้อหาต่าง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#idempotency_conflict"
}
}{
"error": {
"code": "upstream_error",
"message": "ระบบปลายทางตอบผิดพลาด",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#upstream_error"
}
}ผู้ให้บริการรับชำระ
ผู้ให้บริการที่เชื่อมไว้ อัตราค่าธรรมเนียม รอบโอนเงิน และสถานะปัจจุบัน (จากแผงสุขภาพ connector)
ผลลัพธ์
- 200ผู้ให้บริการ
- 401
unauthorizedไม่ได้ยืนยันตัวตน - 403
insufficient_scopeสิทธิ์ของคีย์ไม่พอ
curl -X GET "https://sandbox.api.chuamthang.example/v1/pg/providers" \
-H "Authorization: Bearer ct_test_4Lm9QxB27dWk" \
-H "Chuamthang-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // ct_test_4Lm9QxB27dWk
const res = await fetch('https://sandbox.api.chuamthang.example/v1/pg/providers', {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Chuamthang-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # ct_test_4Lm9QxB27dWk
res = requests.get(
"https://sandbox.api.chuamthang.example/v1/pg/providers",
headers={
"Authorization": f"Bearer {API_KEY}",
"Chuamthang-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"object": "list",
"data": [
{
"id": "pvd_paygate_a",
"name": "PAYGATE A",
"methods": [
"promptpay_qr",
"card"
],
"fee": {
"promptpay_qr": 0.008,
"card": 0.022,
"card_large": 0.022
},
"card_large_threshold": 150000,
"settlement": "T+2",
"status": "operational",
"uptime_30d": 0.9991
},
{
"id": "pvd_paygate_b",
"name": "PAYGATE B",
"methods": [
"promptpay_qr",
"card"
],
"fee": {
"promptpay_qr": 0.0055,
"card": 0.024,
"card_large": 0.0195
},
"card_large_threshold": 150000,
"settlement": "T+1",
"status": "operational",
"uptime_30d": 0.9978
}
],
"has_more": false,
"next_cursor": null
}{
"error": {
"code": "unauthorized",
"message": "ไม่ได้ยืนยันตัวตน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#unauthorized"
}
}{
"error": {
"code": "insufficient_scope",
"message": "สิทธิ์ของคีย์ไม่พอ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#insufficient_scope"
}
}ดูกฎ routing
ชุดกฎปัจจุบัน (เรียงตาม priority) พร้อม ETag สำหรับแก้ไข
ผลลัพธ์
- 200ชุดกฎ
- 403
insufficient_scopeสิทธิ์ของคีย์ไม่พอ
curl -X GET "https://sandbox.api.chuamthang.example/v1/pg/routing-rules" \
-H "Authorization: Bearer ct_test_4Lm9QxB27dWk" \
-H "Chuamthang-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // ct_test_4Lm9QxB27dWk
const res = await fetch('https://sandbox.api.chuamthang.example/v1/pg/routing-rules', {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Chuamthang-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # ct_test_4Lm9QxB27dWk
res = requests.get(
"https://sandbox.api.chuamthang.example/v1/pg/routing-rules",
headers={
"Authorization": f"Bearer {API_KEY}",
"Chuamthang-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"object": "pg_routing_rules",
"version": 12,
"rules": [
{
"id": "rr_01",
"priority": 10,
"name": "สาขานำร่องบัตรทุกยอดไป PAYGATE B",
"when": {
"method": "card",
"branches": [
"brn_012",
"brn_058"
]
},
"route_to": "pvd_paygate_b",
"fallback_to": "pvd_paygate_a"
},
{
"id": "rr_02",
"priority": 20,
"name": "PromptPay QR ใช้ผู้ให้บริการที่ค่าธรรมเนียมต่ำกว่า",
"when": {
"method": "promptpay_qr"
},
"route_to": "pvd_paygate_b",
"fallback_to": "pvd_paygate_a"
},
{
"id": "rr_03",
"priority": 30,
"name": "บัตรยอดตั้งแต่ ฿1,500 ใช้อัตราลด",
"when": {
"method": "card",
"min_amount": 150000
},
"route_to": "pvd_paygate_b",
"fallback_to": "pvd_paygate_a"
},
{
"id": "rr_04",
"priority": 40,
"name": "บัตรยอดทั่วไป",
"when": {
"method": "card"
},
"route_to": "pvd_paygate_a",
"fallback_to": "pvd_paygate_b"
}
],
"updated_at": "2026-09-28T16:40:00+07:00",
"updated_by": "emp_ho_fin_04"
}{
"error": {
"code": "insufficient_scope",
"message": "สิทธิ์ของคีย์ไม่พอ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#insufficient_scope"
}
}แทนที่กฎ routing
แทนที่ทั้งชุด (atomic) — ระบบตรวจ priority ไม่ซ้ำ ผู้ให้บริการรองรับช่องทาง และต้องมีกฎที่ครอบคลุมทุกช่องทาง · มีผลกับรายการใหม่ทันที
Headersheader
If-Matchstringไม่บังคับETag ของข้อมูลที่อ่านล่าสุด — กันเขียนทับการแก้ของคนอื่น (ได้ 412 ถ้าไม่ตรง)
Request bodyapplication/json
rulesarray<object>จำเป็นชุดกฎ (1–50)
ฟิลด์ย่อยของ
rules(12)idstringจำเป็นรหัสกฎ
priorityintegerจำเป็นลำดับประเมิน (น้อยก่อน ห้ามซ้ำ)
namestringจำเป็นชื่อกฎ
whenobjectไม่บังคับเงื่อนไข (ทุกข้อต้องจริง · ไม่ใส่ = ไม่จำกัด)
ฟิลด์ย่อยของ
when(4)methodstringไม่บังคับช่องทาง
min_amountintegerไม่บังคับยอดขั้นต่ำ (สตางค์)
max_amountintegerไม่บังคับยอดสูงสุด (สตางค์)
branchesarray<string>ไม่บังคับเฉพาะสาขา
route_tostringจำเป็นผู้ให้บริการหลัก
fallback_tostringจำเป็นผู้ให้บริการสำรองเมื่อหลักล่ม (สุขภาพ connector = down)
enabledbooleanไม่บังคับเปิดใช้กฎนี้ (ปิดชั่วคราวได้โดยไม่ลบ)
descriptionstringไม่บังคับเหตุผลทางธุรกิจของกฎ (แสดงในล็อกการตัดสินใจ)
effective_fromstring · date-timeไม่บังคับเริ่มมีผลเมื่อ (ตั้งล่วงหน้าตามวันเริ่มสัญญาได้)
statsobjectไม่บังคับอ่านอย่างเดียวสถิติ 24 ชม. ของกฎ
ฟิลด์ย่อยของ
stats(2)matched_24hintegerไม่บังคับจำนวนรายการที่ตรงกฎนี้
failover_24hintegerไม่บังคับจำนวนที่ใช้ตัวสำรอง
updated_atstring · date-timeไม่บังคับอ่านอย่างเดียวแก้ล่าสุด
updated_bystringไม่บังคับอ่านอย่างเดียวผู้แก้ (ต้องมีผู้อนุมัติคนที่สอง)
dry_runbooleanไม่บังคับตรวจอย่างเดียวไม่บันทึก
ผลลัพธ์
- 200บันทึกแล้ว (version ใหม่)
- 422ชุดกฎผิด
- 422
routing_rules_invalidชุดกฎ routing ไม่ถูกต้อง - 412
precondition_failedข้อมูลถูกแก้ไปก่อนแล้ว - 403
insufficient_scopeสิทธิ์ของคีย์ไม่พอ - 400
invalid_requestคำขอไม่ถูกต้อง
- แนะนำให้กฎสุดท้ายของแต่ละช่องทางไม่มีเงื่อนไขยอด/สาขา ไม่งั้นบางรายการจะได้ no_route
- ทดลองกฎด้วยเครื่องมือจำลองท้ายหน้านี้ก่อนบันทึก
curl -X PUT "https://sandbox.api.chuamthang.example/v1/pg/routing-rules" \
-H "Authorization: Bearer ct_test_4Lm9QxB27dWk" \
-H "Content-Type: application/json" \
-H "Chuamthang-Version: 2026-08-01" \
-d '{
"rules": [
{
"id": "rr_01",
"priority": 10,
"name": "สาขานำร่องบัตรทุกยอดไป PAYGATE B",
"when": {
"method": "card",
"branches": [
"brn_012",
"brn_058"
]
},
"route_to": "pvd_paygate_b",
"fallback_to": "pvd_paygate_a"
},
{
"id": "rr_02",
"priority": 20,
"name": "PromptPay QR ใช้ผู้ให้บริการที่ค่าธรรมเนียมต่ำกว่า",
"when": {
"method": "promptpay_qr"
},
"route_to": "pvd_paygate_b",
"fallback_to": "pvd_paygate_a"
},
{
"id": "rr_03",
"priority": 30,
"name": "บัตรยอดตั้งแต่ ฿1,500 ใช้อัตราลด",
"when": {
"method": "card",
"min_amount": 150000
},
"route_to": "pvd_paygate_b",
"fallback_to": "pvd_paygate_a"
},
{
"id": "rr_04",
"priority": 40,
"name": "บัตรยอดทั่วไป",
"when": {
"method": "card"
},
"route_to": "pvd_paygate_a",
"fallback_to": "pvd_paygate_b"
}
]
}'const API_KEY = process.env.API_KEY; // ct_test_4Lm9QxB27dWk
const res = await fetch('https://sandbox.api.chuamthang.example/v1/pg/routing-rules', {
method: 'PUT',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'Chuamthang-Version': '2026-08-01',
},
body: JSON.stringify({
"rules": [
{
"id": "rr_01",
"priority": 10,
"name": "สาขานำร่องบัตรทุกยอดไป PAYGATE B",
"when": {
"method": "card",
"branches": [
"brn_012",
"brn_058"
]
},
"route_to": "pvd_paygate_b",
"fallback_to": "pvd_paygate_a"
},
{
"id": "rr_02",
"priority": 20,
"name": "PromptPay QR ใช้ผู้ให้บริการที่ค่าธรรมเนียมต่ำกว่า",
"when": {
"method": "promptpay_qr"
},
"route_to": "pvd_paygate_b",
"fallback_to": "pvd_paygate_a"
},
{
"id": "rr_03",
"priority": 30,
"name": "บัตรยอดตั้งแต่ ฿1,500 ใช้อัตราลด",
"when": {
"method": "card",
"min_amount": 150000
},
"route_to": "pvd_paygate_b",
"fallback_to": "pvd_paygate_a"
},
{
"id": "rr_04",
"priority": 40,
"name": "บัตรยอดทั่วไป",
"when": {
"method": "card"
},
"route_to": "pvd_paygate_a",
"fallback_to": "pvd_paygate_b"
}
]
}),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # ct_test_4Lm9QxB27dWk
res = requests.put(
"https://sandbox.api.chuamthang.example/v1/pg/routing-rules",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Chuamthang-Version": "2026-08-01",
},
json={
"rules": [
{
"id": "rr_01",
"priority": 10,
"name": "สาขานำร่องบัตรทุกยอดไป PAYGATE B",
"when": {
"method": "card",
"branches": [
"brn_012",
"brn_058"
]
},
"route_to": "pvd_paygate_b",
"fallback_to": "pvd_paygate_a"
},
{
"id": "rr_02",
"priority": 20,
"name": "PromptPay QR ใช้ผู้ให้บริการที่ค่าธรรมเนียมต่ำกว่า",
"when": {
"method": "promptpay_qr"
},
"route_to": "pvd_paygate_b",
"fallback_to": "pvd_paygate_a"
},
{
"id": "rr_03",
"priority": 30,
"name": "บัตรยอดตั้งแต่ ฿1,500 ใช้อัตราลด",
"when": {
"method": "card",
"min_amount": 150000
},
"route_to": "pvd_paygate_b",
"fallback_to": "pvd_paygate_a"
},
{
"id": "rr_04",
"priority": 40,
"name": "บัตรยอดทั่วไป",
"when": {
"method": "card"
},
"route_to": "pvd_paygate_a",
"fallback_to": "pvd_paygate_b"
}
]
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"object": "pg_routing_rules",
"version": 13,
"rules": [
{
"id": "rr_01",
"priority": 10,
"name": "สาขานำร่องบัตรทุกยอดไป PAYGATE B",
"when": {
"method": "card",
"branches": [
"brn_012",
"brn_058"
]
},
"route_to": "pvd_paygate_b",
"fallback_to": "pvd_paygate_a"
},
{
"id": "rr_02",
"priority": 20,
"name": "PromptPay QR ใช้ผู้ให้บริการที่ค่าธรรมเนียมต่ำกว่า",
"when": {
"method": "promptpay_qr"
},
"route_to": "pvd_paygate_b",
"fallback_to": "pvd_paygate_a"
},
{
"id": "rr_03",
"priority": 30,
"name": "บัตรยอดตั้งแต่ ฿1,500 ใช้อัตราลด",
"when": {
"method": "card",
"min_amount": 150000
},
"route_to": "pvd_paygate_b",
"fallback_to": "pvd_paygate_a"
},
{
"id": "rr_04",
"priority": 40,
"name": "บัตรยอดทั่วไป",
"when": {
"method": "card"
},
"route_to": "pvd_paygate_a",
"fallback_to": "pvd_paygate_b"
}
],
"updated_at": "2026-10-12T10:00:00+07:00"
}{
"error": {
"code": "routing_rules_invalid",
"message": "priority 20 ซ้ำกัน 2 กฎ",
"details": [
{
"path": "rules[2].priority",
"message": "ซ้ำกับ rules[1]"
}
]
}
}{
"error": {
"code": "routing_rules_invalid",
"message": "ชุดกฎ routing ไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#routing_rules_invalid"
}
}{
"error": {
"code": "precondition_failed",
"message": "ข้อมูลถูกแก้ไปก่อนแล้ว",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#precondition_failed"
}
}{
"error": {
"code": "insufficient_scope",
"message": "สิทธิ์ของคีย์ไม่พอ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#insufficient_scope"
}
}{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#invalid_request"
}
}ผลกระทบยอดรายวัน
เทียบรายการ QR/บัตรของ POS กับไฟล์ของผู้ให้บริการ (พร้อมหลัง 04:00) — คืนยอดรวม จำนวนที่ตรง และรายการไม่ตรงพร้อมคำแนะนำ
Query parametersquery
datestring · dateจำเป็นวันทำการ
branch_idstringไม่บังคับสาขา (ไม่ระบุ = ทุกสาขาที่คีย์เข้าถึง)
statusstringไม่บังคับกรอง
ผลลัพธ์
- 200ตัวอย่าง: ต่างกัน ฿156.00 จาก 2 รายการ
- 409
reconciliation_not_readyยังกระทบยอดไม่ได้ - 400
invalid_requestคำขอไม่ถูกต้อง - 403
branch_not_allowedคีย์นี้เข้าถึงสาขานี้ไม่ได้
curl -X GET "https://sandbox.api.chuamthang.example/v1/pg/reconciliation?date=2026-10-11&branch_id=brn_041" \
-H "Authorization: Bearer ct_test_4Lm9QxB27dWk" \
-H "Chuamthang-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // ct_test_4Lm9QxB27dWk
const res = await fetch('https://sandbox.api.chuamthang.example/v1/pg/reconciliation?date=2026-10-11&branch_id=brn_041', {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Chuamthang-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # ct_test_4Lm9QxB27dWk
res = requests.get(
"https://sandbox.api.chuamthang.example/v1/pg/reconciliation?date=2026-10-11&branch_id=brn_041",
headers={
"Authorization": f"Bearer {API_KEY}",
"Chuamthang-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "rcn_041_20261011",
"object": "pg_reconciliation",
"date": "2026-10-11",
"branch_id": "brn_041",
"status": "exceptions_found",
"pos": {
"count": 241,
"amount": 3529284
},
"providers": {
"count": 242,
"amount": 3544884
},
"difference": 15600,
"matched": 240,
"exceptions": [
{
"id": "rex_01",
"type": "missing_in_pos",
"charge_id": "pgc_9Lm2Vb",
"bill_id": null,
"pos_amount": 0,
"pg_amount": 12900,
"note": "POS ออฟไลน์ 21:57–22:04 บิลถูกบันทึกภายหลังโดยไม่มีเลขอ้างอิงการชำระ",
"suggested": "link_bill",
"candidate_bill": "bill_041_0379",
"status": "open",
"resolution": null
},
{
"id": "rex_02",
"type": "amount_mismatch",
"charge_id": "pgc_4Qa8Ne",
"bill_id": "bill_041_0233",
"pos_amount": 25800,
"pg_amount": 28500,
"note": "แก้รายการในบิลหลังรับชำระด้วยบัตร (ลบชาไทย 1 แก้ว — ฿27.00 ไม่ตรงราคา)",
"suggested": "adjust_pos",
"candidate_bill": null,
"status": "open",
"resolution": null
}
],
"completed_at": "2026-10-12T04:12:30+07:00"
}{
"error": {
"code": "reconciliation_not_ready",
"message": "ยังกระทบยอดไม่ได้",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#reconciliation_not_ready"
}
}{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#invalid_request"
}
}{
"error": {
"code": "branch_not_allowed",
"message": "คีย์นี้เข้าถึงสาขานี้ไม่ได้",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#branch_not_allowed"
}
}จัดการรายการไม่ตรง
POST/v1/pg/reconciliation/{reconciliation_id}/resolve
บันทึกการแก้ข้อยกเว้นทีละรายการ: ผูกบิล (link_bill) · แก้ยอดใน POS (adjust_pos) · คืนส่วนต่าง (refund_difference) · ตัดเป็นค่าใช้จ่าย (write_off)
Path parameterspath
reconciliation_idstringจำเป็นรหัส rcn_…
Headersheader
Idempotency-Keystring · uuidไม่บังคับกันรายการซ้ำเมื่อส่งซ้ำ (เก็บ 24 ชม.) — แนะนำ UUID v4 ต่อ 1 รายการ
Request bodyapplication/json
exception_idstringจำเป็นข้อยกเว้น
actionstringจำเป็นวิธีแก้
bill_idstringไม่บังคับบิลที่ผูก (action = link_bill)
notestringไม่บังคับบันทึก
resolved_bystringจำเป็นผู้แก้
ผลลัพธ์
- 200ผลกระทบยอดหลังแก้ (เหลือข้อยกเว้น 1)
- 404
resource_not_foundไม่พบข้อมูล - 409
exception_already_resolvedข้อยกเว้นนี้จัดการแล้ว - 422
validation_failedข้อมูลไม่ผ่านกฎธุรกิจ - 409
idempotency_conflictIdempotency-Key ซ้ำแต่เนื้อหาต่าง
curl -X POST "https://sandbox.api.chuamthang.example/v1/pg/reconciliation/rcn_041_20261011/resolve" \
-H "Authorization: Bearer ct_test_4Lm9QxB27dWk" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f" \
-H "Chuamthang-Version: 2026-08-01" \
-d '{
"exception_id": "rex_01",
"action": "link_bill",
"bill_id": "bill_041_0379",
"note": "บิลบันทึกหลัง POS กลับมาออนไลน์ 22:03",
"resolved_by": "emp_ho_fin_04"
}'const API_KEY = process.env.API_KEY; // ct_test_4Lm9QxB27dWk
const res = await fetch('https://sandbox.api.chuamthang.example/v1/pg/reconciliation/rcn_041_20261011/resolve', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': '7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f',
'Chuamthang-Version': '2026-08-01',
},
body: JSON.stringify({
"exception_id": "rex_01",
"action": "link_bill",
"bill_id": "bill_041_0379",
"note": "บิลบันทึกหลัง POS กลับมาออนไลน์ 22:03",
"resolved_by": "emp_ho_fin_04"
}),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # ct_test_4Lm9QxB27dWk
res = requests.post(
"https://sandbox.api.chuamthang.example/v1/pg/reconciliation/rcn_041_20261011/resolve",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Idempotency-Key": "7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f",
"Chuamthang-Version": "2026-08-01",
},
json={
"exception_id": "rex_01",
"action": "link_bill",
"bill_id": "bill_041_0379",
"note": "บิลบันทึกหลัง POS กลับมาออนไลน์ 22:03",
"resolved_by": "emp_ho_fin_04"
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "rcn_041_20261011",
"object": "pg_reconciliation",
"date": "2026-10-11",
"branch_id": "brn_041",
"status": "exceptions_found",
"pos": {
"count": 241,
"amount": 3529284
},
"providers": {
"count": 242,
"amount": 3544884
},
"difference": 15600,
"matched": 240,
"exceptions": [
{
"id": "rex_01",
"type": "missing_in_pos",
"charge_id": "pgc_9Lm2Vb",
"bill_id": "bill_041_0379",
"pos_amount": 0,
"pg_amount": 12900,
"note": "POS ออฟไลน์ 21:57–22:04 บิลถูกบันทึกภายหลังโดยไม่มีเลขอ้างอิงการชำระ",
"suggested": "link_bill",
"candidate_bill": "bill_041_0379",
"status": "resolved",
"resolution": {
"action": "link_bill",
"by": "emp_ho_fin_04",
"at": "2026-10-12T09:05:00+07:00"
}
},
{
"id": "rex_02",
"type": "amount_mismatch",
"charge_id": "pgc_4Qa8Ne",
"bill_id": "bill_041_0233",
"pos_amount": 25800,
"pg_amount": 28500,
"note": "แก้รายการในบิลหลังรับชำระด้วยบัตร (ลบชาไทย 1 แก้ว — ฿27.00 ไม่ตรงราคา)",
"suggested": "adjust_pos",
"candidate_bill": null,
"status": "open",
"resolution": null
}
],
"completed_at": "2026-10-12T04:12:30+07:00"
}{
"error": {
"code": "resource_not_found",
"message": "ไม่พบข้อมูล",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#resource_not_found"
}
}{
"error": {
"code": "exception_already_resolved",
"message": "ข้อยกเว้นนี้จัดการแล้ว",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#exception_already_resolved"
}
}{
"error": {
"code": "validation_failed",
"message": "ข้อมูลไม่ผ่านกฎธุรกิจ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#validation_failed"
}
}{
"error": {
"code": "idempotency_conflict",
"message": "Idempotency-Key ซ้ำแต่เนื้อหาต่าง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#idempotency_conflict"
}
}รอบโอนเงินเข้าบัญชี
ยอดที่ผู้ให้บริการโอนให้ BAANKHAO ต่อรอบ (ยอดรับ − ค่าธรรมเนียม − คืนเงิน) — ใช้กับบัญชีลูกหนี้ 1113 ใน ERP
Query parametersquery
providerstringไม่บังคับผู้ให้บริการ
pay_date_fromstring · dateไม่บังคับวันโอนตั้งแต่
statusstringไม่บังคับสถานะ
limitintegerไม่บังคับจำนวนรายการต่อหน้า
starting_afterstringไม่บังคับcursor — รหัสของรายการสุดท้ายในหน้าก่อน (ใช้ค่า next_cursor ที่ได้)
ผลลัพธ์
- 200รอบของวันที่ 2026-10-11 สาขา 041
- 400
invalid_requestคำขอไม่ถูกต้อง - 403
insufficient_scopeสิทธิ์ของคีย์ไม่พอ
- PAYGATE B: ฿29,116.59 − ฿206.70 = ฿28,909.89 (T+1)
- PAYGATE A: ฿6,176.25 − ฿135.88 − คืนเงิน ฿45.00 = ฿5,995.37 (T+2)
curl -X GET "https://sandbox.api.chuamthang.example/v1/pg/settlements?pay_date_from=2026-10-12&limit=20" \
-H "Authorization: Bearer ct_test_4Lm9QxB27dWk" \
-H "Chuamthang-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // ct_test_4Lm9QxB27dWk
const res = await fetch('https://sandbox.api.chuamthang.example/v1/pg/settlements?pay_date_from=2026-10-12&limit=20', {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Chuamthang-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # ct_test_4Lm9QxB27dWk
res = requests.get(
"https://sandbox.api.chuamthang.example/v1/pg/settlements?pay_date_from=2026-10-12&limit=20",
headers={
"Authorization": f"Bearer {API_KEY}",
"Chuamthang-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"object": "list",
"data": [
{
"object": "pg_settlement",
"branch_id": "brn_041",
"id": "stl_pgb_20261012",
"provider": "pvd_paygate_b",
"for_date": "2026-10-11",
"pay_date": "2026-10-12",
"gross": 2911659,
"fee": 20670,
"refunds": 0,
"net": 2890989,
"status": "paid"
},
{
"object": "pg_settlement",
"branch_id": "brn_041",
"id": "stl_pga_20261013",
"provider": "pvd_paygate_a",
"for_date": "2026-10-11",
"pay_date": "2026-10-13",
"gross": 617625,
"fee": 13588,
"refunds": 4500,
"net": 599537,
"status": "scheduled"
}
],
"has_more": false,
"next_cursor": null
}{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#invalid_request"
}
}{
"error": {
"code": "insufficient_scope",
"message": "สิทธิ์ของคีย์ไม่พอ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#insufficient_scope"
}
}Webhooks — แจ้งเหตุการณ์ไปที่ระบบของคุณ
ลงทะเบียน URL ปลายทาง แล้วระบบจะส่ง POST พร้อม JSON ทุกครั้งที่เกิดเหตุการณ์ด้านล่าง · ตอบกลับ 2xx ภายใน 10 วินาที ไม่งั้นจะส่งซ้ำตามตาราง · ทุกคำขอมีหัว Chuamthang-Signature ให้ตรวจว่ามาจากเราจริง · event อาจมาซ้ำหรือสลับลำดับ ให้ใช้ id กันประมวลผลซ้ำ
pg.charge.succeededรับชำระสำเร็จ
ส่งเมื่อ: ผู้ให้บริการยืนยันเงินเข้า
{
"id": "evt_01JB7Q00",
"type": "pg.charge.succeeded",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"id": "pgc_8Xr4Tq",
"bill_id": "bill_041_0187",
"branch_id": "brn_041",
"amount": 40565,
"method": "promptpay_qr",
"provider": "pvd_paygate_b",
"fee": 223,
"succeeded_at": "2026-10-11T12:34:06+07:00"
}
}pg.charge.failedรับชำระไม่สำเร็จ
ส่งเมื่อ: บัตรถูกปฏิเสธ / ผู้ให้บริการแจ้งล้มเหลว
{
"id": "evt_01JB7Q01",
"type": "pg.charge.failed",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"id": "pgc_2Vb7Hs",
"bill_id": "bill_041_0298",
"amount": 54000,
"method": "card",
"failure": {
"code": "charge_declined",
"decline_code": "insufficient_funds"
}
}
}pg.charge.expiredQR หมดอายุ
ส่งเมื่อ: ครบ 10 นาทีแล้วยังไม่จ่าย
{
"id": "evt_01JB7Q02",
"type": "pg.charge.expired",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"id": "pgc_6Ty1Pd",
"bill_id": "bill_041_0204",
"amount": 21800,
"method": "promptpay_qr",
"expired_at": "2026-10-11T13:20:00+07:00"
}
}pg.refund.succeededคืนเงินสำเร็จ
ส่งเมื่อ: ผู้ให้บริการยืนยันการคืน
{
"id": "evt_01JB7Q03",
"type": "pg.refund.succeeded",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"id": "pgr_2Wd7",
"charge_id": "pgc_7Fh1Ka",
"amount": 4500,
"reason": "item_unavailable"
}
}pg.routing.failoverใช้ผู้ให้บริการสำรอง
ส่งเมื่อ: กฎตรงแต่ผู้ให้บริการหลักล่ม (แจ้งครั้งแรกของแต่ละชั่วโมง)
{
"id": "evt_01JB7Q04",
"type": "pg.routing.failover",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"rule_id": "rr_03",
"primary": "pvd_paygate_b",
"used": "pvd_paygate_a",
"charges_in_hour": 37
}
}pg.reconciliation.completedกระทบยอดรายวันเสร็จ
ส่งเมื่อ: 04:00–04:30 ทุกวัน
{
"id": "evt_01JB7Q05",
"type": "pg.reconciliation.completed",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"id": "rcn_041_20261011",
"date": "2026-10-11",
"branch_id": "brn_041",
"status": "exceptions_found",
"difference": 15600,
"exceptions": 2
}
}ส่งซ้ำเมื่อปลายทางไม่ตอบ
- 1ทันที
- 21 นาที
- 35 นาที
- 430 นาที
- 52 ชั่วโมง
- 66 ชั่วโมง
- 724 ชั่วโมง (ครั้งสุดท้าย)
ครบทุกครั้งแล้วยังล้มเหลว → ปิด endpoint อัตโนมัติและส่งอีเมลแจ้งผู้ดูแล · ดูประวัติการส่งและกดส่งซ้ำได้ในแดชบอร์ด
ตรวจลายเซ็น
# ลายเซ็นอยู่ในหัว Chuamthang-Signature: t=<unix>,v1=<hex>
# คำนวณ HMAC-SHA256(secret, "<t>.<raw body>") แล้วเทียบกับ v1
printf '%s' "$T.$BODY" | openssl dgst -sha256 -hmac "$WEBHOOK_SECRET"import crypto from 'node:crypto';
// ใช้ raw body (ยังไม่ parse JSON) เท่านั้น
export function verify(rawBody, sigHeader, secret) {
const parts = Object.fromEntries(sigHeader.split(',').map((p) => p.split('=')));
const age = Math.abs(Date.now() / 1000 - Number(parts.t));
if (age > 300) return false; // เก่ากว่า 5 นาที = ปฏิเสธ (กัน replay)
const expected = crypto.createHmac('sha256', secret).update(parts.t + '.' + rawBody).digest('hex');
return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1));
}import hmac, hashlib, time
def verify(raw_body: bytes, sig_header: str, secret: str) -> bool:
parts = dict(p.split("=", 1) for p in sig_header.split(","))
if abs(time.time() - int(parts["t"])) > 300:
return False # เก่ากว่า 5 นาที = ปฏิเสธ (กัน replay)
msg = parts["t"].encode() + b"." + raw_body
expected = hmac.new(secret.encode(), msg, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, parts["v1"])Errors — รหัสข้อผิดพลาด
ทุก error ตอบกลับเป็น JSON รูปแบบเดียวกัน พร้อม request_id สำหรับแจ้งทีมสนับสนุน · รหัส HTTP บอกกลุ่มของปัญหา ส่วน error.code บอกสาเหตุที่แน่นอน (ใช้เขียนเงื่อนไขในโค้ดได้ เพราะไม่เปลี่ยนตามภาษา)
- 4xx คำขอไม่ถูกต้อง — แก้ที่ฝั่งผู้เรียก ส่งซ้ำแบบเดิมจะได้ผลเดิม
- 5xx ปัญหาฝั่งระบบ — ลองใหม่แบบเว้นระยะ (exponential backoff) พร้อม Idempotency-Key
{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"param": "items[0].quantity",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#invalid_request"
}
}| HTTP | code | ความหมาย | วิธีแก้ |
|---|---|---|---|
| 400 | invalid_request | คำขอไม่ถูกต้อง ขาดฟิลด์ที่จำเป็น หรือชนิดข้อมูลผิด — ดู error.param ว่าฟิลด์ไหน | ตรวจ body ตาม schema ของ endpoint · เงินต้องเป็นจำนวนเต็มสตางค์ · เวลาเป็น ISO 8601 |
| 401 | unauthorized | ไม่ได้ยืนยันตัวตน ไม่มีหัว Authorization หรือ API key ไม่ถูกต้อง/ถูกเพิกถอน | ส่ง Authorization: Bearer ct_test_… (sandbox) หรือ ct_live_… (production) · ตรวจว่าใช้คีย์ให้ตรงสภาพแวดล้อม |
| 403 | insufficient_scope | สิทธิ์ของคีย์ไม่พอ API key นี้ไม่มี scope ที่ endpoint ต้องการ | ขอ scope เพิ่มในหน้า Developer Console (ผู้ดูแลระบบของ BAANKHAO อนุมัติ) |
| 403 | branch_not_allowed | คีย์นี้เข้าถึงสาขานี้ไม่ได้ คีย์ของ POS สาขาถูกจำกัดให้ใช้กับสาขาตัวเองเท่านั้น | ใช้คีย์ของสาขานั้น หรือคีย์ระดับสำนักงานใหญ่ที่มีสิทธิ์ทุกสาขา |
| 404 | charge_not_found | ไม่พบรายการรับชำระ charge_id ไม่มีอยู่ หรือเป็นของสาขาที่คีย์นี้เข้าถึงไม่ได้ | ตรวจรหัส pgc_… และสภาพแวดล้อม |
| 402 | charge_declined | การชำระถูกปฏิเสธ ผู้ให้บริการรับชำระหรือผู้ออกบัตรปฏิเสธรายการ (ดู decline_code) | ให้ลูกค้าเลือกวิธีชำระอื่น · ห้ามลองซ้ำอัตโนมัติเกิน 1 ครั้ง |
| 422 | amount_too_small | ยอดต่ำกว่าขั้นต่ำ ยอดรับชำระต้องไม่ต่ำกว่า ฿1.00 (100 สตางค์) | รวมยอดกับรายการอื่น หรือรับเป็นเงินสด |
| 422 | amount_too_large | ยอดเกินเพดาน ยอดต่อรายการต้องไม่เกิน ฿50,000 (5,000,000 สตางค์) | แบ่งชำระ หรือใช้การโอนเงินสำหรับงานจัดเลี้ยง |
| 422 | refund_exceeds_charge | คืนเงินเกินยอดที่รับ ยอดคืนรวมทุกครั้งเกินยอดที่รับชำระสำเร็จ | ตรวจ refundable_amount ใน GET /v1/pg/charges/{id} |
| 422 | no_route | ไม่มีกฎ routing ที่ตรง ไม่มีกฎใดตรงกับช่องทาง/ยอด/สาขาของรายการนี้ | เพิ่มกฎสุดท้ายแบบไม่มีเงื่อนไข (catch-all) ใน PUT /v1/pg/routing-rules |
| 503 | all_providers_unavailable | ผู้ให้บริการรับชำระล่มทั้งหมด ทั้งผู้ให้บริการหลักและสำรองของกฎที่ตรงไม่พร้อมใช้งาน | แจ้งแคชเชียร์รับเงินสด · Hub แจ้งเตือนทีมปฏิบัติการอัตโนมัติ |
| 422 | routing_rules_invalid | ชุดกฎ routing ไม่ถูกต้อง priority ซ้ำ ผู้ให้บริการไม่รองรับช่องทาง หรือไม่มีกฎ catch-all | แก้ตาม error.details[] — ระบบไม่บันทึกชุดกฎที่ผิดบางส่วน |
| 409 | reconciliation_not_ready | ยังกระทบยอดไม่ได้ ผู้ให้บริการยังส่งไฟล์รายการของวันนั้นไม่ครบ (ปกติพร้อม 04:00 วันถัดไป) | เรียกใหม่หลัง 04:00 หรือรอ webhook reconciliation.completed |
| 409 | exception_already_resolved | ข้อยกเว้นนี้จัดการแล้ว รายการไม่ตรงนี้ถูก resolve ไปแล้ว | ดูผลเดิมใน resolution ของข้อยกเว้น |
| 412 | precondition_failed | ข้อมูลถูกแก้ไปก่อนแล้ว ค่า If-Match (ETag) ไม่ตรงกับเวอร์ชันปัจจุบันของข้อมูล | ดึงข้อมูลล่าสุดใหม่ (GET) แล้วส่งการแก้ไขพร้อม ETag ใหม่ |
| 409 | idempotency_conflict | Idempotency-Key ซ้ำแต่เนื้อหาต่าง เคยใช้ Idempotency-Key นี้กับคำขอที่ body ต่างกันภายใน 24 ชั่วโมง | สร้างคีย์ใหม่ (UUID v4) ต่อ 1 รายการ · ส่งคีย์เดิมซ้ำได้เฉพาะเมื่อ body เหมือนเดิม |
| 429 | rate_limited | เรียกเกินโควตา เกินโควตาของคีย์หรือของ endpoint ในช่วงเวลา | รอตามหัว Retry-After แล้วลองใหม่แบบเว้นระยะเพิ่มขึ้น + jitter |
| 502 | upstream_error | ระบบปลายทางตอบผิดพลาด ระบบที่ Hub เชื่อมอยู่ (ERP CRM ผู้ให้บริการรับชำระ แอปภายนอก) ตอบ 5xx หรือรูปแบบที่อ่านไม่ได้ | ลองใหม่ภายหลัง · ดู error.upstream ว่าระบบไหน · ตรวจสุขภาพที่ GET /v1/connectors/{id}/health |
| 504 | upstream_timeout | ระบบปลายทางตอบช้าเกิน ระบบปลายทางไม่ตอบภายในเวลาที่กำหนด (ค่าเริ่มต้น 8 วินาที) | ลองใหม่พร้อม Idempotency-Key เดิม — Hub กันรายการซ้ำให้ · ตรวจสถานะด้วย GET ก่อนสร้างใหม่ |
| 422 | validation_failed | ข้อมูลไม่ผ่านกฎธุรกิจ รูปแบบถูกแต่ขัดกับกฎ เช่น วันที่ในอนาคต หรือจำนวนติดลบ — ดู error.details[] | แก้ตามรายการใน details แล้วส่งใหม่ |
| 404 | resource_not_found | ไม่พบข้อมูล รหัสใน path ไม่มีอยู่ หรืออยู่คนละสภาพแวดล้อม (sandbox/production) | ตรวจรหัสและสภาพแวดล้อม · ข้อมูล sandbox ถูกล้างทุกวันอาทิตย์ 03:00 |
ไม่พบรหัสที่ค้นหา
Rate limit — โควตาการเรียก
| ขอบเขต | โควตา | Burst | หมายเหตุ |
|---|---|---|---|
| สร้างรายการรับชำระ (ต่อสาขา) | 120 ครั้ง/นาที | 40 | ช่วงเที่ยงสาขาใหญ่ใช้ ~35/นาที |
| ดูสถานะรายการ (ต่อคีย์) | 600 ครั้ง/นาที | 100 | ใช้ webhook แทนการถามวน |
| คืนเงิน (ต่อสาขา) | 30 ครั้ง/นาที | — | |
| แก้กฎ routing (ต่อคีย์) | 10 ครั้ง/นาที | — | ทุกครั้งบันทึกผู้แก้และเวอร์ชัน |
RateLimit-Limitโควตาของช่วงเวลาRateLimit-Remainingครั้งที่เหลือRateLimit-Resetวินาทีจนโควตาเริ่มใหม่- เกินโควตา → 429 พร้อม
Retry-After· แนะนำลองใหม่แบบเว้นระยะเพิ่มขึ้น + สุ่มเล็กน้อย (jitter)
HTTP/1.1 429 Too Many Requests
RateLimit-Limit: 100
RateLimit-Remaining: 0
RateLimit-Reset: 23
Retry-After: 23
{
"error": {
"code": "rate_limited",
"message": "เรียกเกินโควตา ลองใหม่ใน 23 วินาที",
"request_id": "req_2Kd9QwZ1"
}
}เวอร์ชันและ Changelog
เลือกเวอร์ชันด้วยหัว Chuamthang-Version (ไม่ส่ง = เวอร์ชันที่ผูกกับ API key) · การเปลี่ยนที่ไม่ทำให้โค้ดเดิมพัง (เพิ่มฟิลด์/endpoint) ออกในเวอร์ชันเดิมได้ · การเปลี่ยนที่ทำให้พังออกเป็นเวอร์ชันใหม่เสมอ และแจ้งล่วงหน้าอย่างน้อย 6 เดือนก่อนปิดเวอร์ชันเก่า
| เวอร์ชัน | สถานะ | รองรับถึง |
|---|---|---|
2026-08-01 ล่าสุด | ปัจจุบัน | — |
2025-11-15 | ยังรองรับ | 30 ก.ย. 2570 |
2024-06-01 | เลิกใช้แล้ว | 31 ธ.ค. 2569 |
- เพิ่ม
2026-08-01เพิ่มเงื่อนไข min_amount ในกฎ routing และอัตราลดบัตรตั้งแต่ ฿1,500.00 ของ PAYGATE B
- เปลี่ยน
2026-08-01routing.failover ย้ายเข้า object routing (เดิมเป็นฟิลด์ระดับบน failover_used)
- เพิ่ม
2025-11-15เพิ่ม action write_off ใน /resolve สำหรับส่วนต่างไม่เกิน ฿5
- แก้ไข
2025-11-15webhook pg.charge.succeeded บางครั้งมาก่อนคำตอบ 201 — เพิ่มคำแนะนำให้ POS รองรับลำดับสลับ
- เพิ่ม
2025-11-15เพิ่มผู้ให้บริการ PAYGATE B และกฎ rr_02 (QR)
- ความปลอดภัย
2025-11-15ตรวจ IP allowlist + ลายเซ็นของ webhook ผู้ให้บริการทุกราย
- เลิกใช้
2025-11-15เลิกใช้ POST /v1/payments (รูปแบบเดิมผูกผู้ให้บริการเดียว) — ใช้ /v1/pg/charges
- เปลี่ยน
2025-11-15QR หมดอายุจาก 15 เป็น 10 นาที (ลดบิลค้าง)
- เพิ่ม
2024-06-01เพิ่ม GET /v1/pg/reconciliation (เดิมฝ่ายการเงินเทียบไฟล์เอง)
ตัวจำลองกฎ routing
เลือกช่องทาง ยอด สาขา และผู้ให้บริการที่ล่ม → เห็นผู้ให้บริการที่ถูกเลือก กฎที่ตรง ลำดับการประเมิน และค่าธรรมเนียมเปรียบเทียบ · คำนวณในเบราว์เซอร์ทั้งหมด ไม่ได้เรียก API จริง