← 2C2P integration

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 optional currency_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:

  1. Call twoc2p_get_payment_options or twoc2p_get_payment_option_details with the paymentToken to inspect enabled channelCode and agentCode values.
  2. Call twoc2p_do_payment with payment_token, channel_code (e.g. CSQR, PPQR, CC, DPAY), optional agent_code (e.g. SCB, KBANK, TRUEMONEY), and customer details (name, email, mobile_no, or secure_pay_token / card_token).
  3. Inspect respCode: - 2000: Transaction completed immediately — call twoc2p_payment_inquiry for full receipt details. - 1005: QR generated — data holds the QR image URL or payload for the customer to scan. - 1000 / 1001 / 1002 / 1004: Redirect URL or mobile app deep link in data (e.g. 3DS ACS challenge or banking app switch). - 1003: Counter / payment slip generated (data URL + extra.qrData / extra.barcodeData).

3. Inquiry & Webhook Verification (twoc2p_payment_inquiry / twoc2p_verify_webhook_payload)

  • Always verify final payment state via twoc2p_payment_inquiry using invoice_no (respCode === "0000" indicates a settled/successful payment).
  • When 2C2P POSTs a { "payload": "<JWT>" } notification to backendReturnUrl, pass that JWT to twoc2p_verify_webhook_payload to verify the HMAC-SHA256 signature and decode the payment result.