2C2P Payment Gateway Flow: Hosted Checkout, PromptPay QR, and Direct API
2C2P Payment Gateway (PGW v4.3 / v4.5) uses HS256 JWT request/response signing ({ "payload": "<JWT>" }) for payment initialization and transaction inquiry.
1. Initialize Payment (twoc2p_create_payment_token)
Every payment starts by requesting a paymentToken:
- Pass
invoice_no(unique order/invoice ID, up to 20 alphanumeric chars),amount(number),description, and optionalcurrency_code(e.g.THB,SGD,MYR,PHP,IDR,VND). - Optionally filter channels via
payment_channel(e.g.["CC"]for cards,["QR"]or["PPQR"]for PromptPay / QR,["DPAY"]for digital wallets like TrueMoney / LINE Pay / Alipay,["IMBANK"]for internet/mobile banking,["IPP"]for installment plans). - Returns: -
webPaymentUrl: Hosted checkout page URL where the customer can pay immediately without custom UI. -paymentToken: Token used for Direct API calls (twoc2p_get_payment_options,twoc2p_do_payment,twoc2p_transaction_status).
2. Direct API Execution (twoc2p_do_payment)
When building a custom checkout or generating a QR code / mobile deep link directly:
- Call
twoc2p_get_payment_optionsortwoc2p_get_payment_option_detailswith thepaymentTokento inspect enabledchannelCodeandagentCodevalues. - Call
twoc2p_do_paymentwithpayment_token,channel_code(e.g.CSQR,PPQR,CC,DPAY), optionalagent_code(e.g.SCB,KBANK,TRUEMONEY), and customer details (name,email,mobile_no, orsecure_pay_token/card_token). - Inspect
respCode: -2000: Transaction completed immediately — calltwoc2p_payment_inquiryfor full receipt details. -1005: QR generated —dataholds the QR image URL or payload for the customer to scan. -1000/1001/1002/1004: Redirect URL or mobile app deep link indata(e.g. 3DS ACS challenge or banking app switch). -1003: Counter / payment slip generated (dataURL +extra.qrData/extra.barcodeData).
3. Inquiry & Webhook Verification (twoc2p_payment_inquiry / twoc2p_verify_webhook_payload)
- Always verify final payment state via
twoc2p_payment_inquiryusinginvoice_no(respCode === "0000"indicates a settled/successful payment). - When 2C2P POSTs a
{ "payload": "<JWT>" }notification tobackendReturnUrl, pass that JWT totwoc2p_verify_webhook_payloadto verify the HMAC-SHA256 signature and decode the payment result.