{
  "openapi": "3.0.3",
  "info": {
    "title": "SiamTechPay REST API",
    "version": "1.0.0",
    "description": "REST API for the SiamTechPay payment gateway. Two integrations: (1) the read/control API — authenticate via `POST /auth/token` with `{ email, password }` for an **opaque** bearer token (not a JWT) sent as `Authorization: Bearer <token>`, RBAC per module, list endpoints return `{ data, meta }` envelopes. (2) the **Live Payments API** — the real money-movement endpoints (payments, refund, cancel, balance, disbursements, provider webhook) authenticated per-request with HMAC request signing (see the `apiKeyHmac` security scheme).\n\n**Outbound webhooks:** SiamTechPay POSTs signed events to the merchant's configured callback URL. The header `X-SiamTechPay-Signature` is lowercase hex `HMAC-SHA256(callbackSecret, {X-SiamTechPay-Timestamp header} + \".\" + {rawBody})`. Use the **header** timestamp, not the body's `created_at`: every attempt (retries included) is stamped and signed at send time, so you can refuse anything older than 5 minutes. Verify over the raw bytes before parsing. During a secret rotation `X-SiamTechPay-Signature-Previous` carries the old secret's signature for 24 h. `X-SiamTechPay-Event` carries the event type, and `X-SiamTechPay-Event` carries the event type. Event types: `payment.paid`, `payment.expired`, `payment.canceled`, `payment.refunded`, `disbursement.awaiting_approval`, `disbursement.completed`, `disbursement.failed`, `settlement.completed`, `withdrawal.held`, `withdrawal.received`, `alt_payout.requested`, `alt_payout.quoted`, `alt_payout.accepted`, `alt_payout.completed`, `alt_payout.rejected`. The body is `{ event, id, created_at, data }`; `data` per event is the `MerchantCallback` schema (`order_id` is your own orderId; `amount` is whole THB, the same unit you sent). Answer 2xx; anything else is retried 13 times over about 3 days. The `WebhookEvent` schema is the provider-to-us webhook, not what you receive."
  },
  "servers": [
    {
      "url": "https://siamtechpay.com/api/v1",
      "description": "Production"
    },
    {
      "url": "/api/v1",
      "description": "Same-origin"
    }
  ],
  "tags": [
    {
      "name": "Auth",
      "description": "Authentication"
    },
    {
      "name": "Account",
      "description": "Current user"
    },
    {
      "name": "Resources",
      "description": "Business resources"
    },
    {
      "name": "Live Payments",
      "description": "HMAC-signed real money-movement API (payments, balance, disbursements, webhook)"
    },
    {
      "name": "Test mode",
      "description": "With your TEST keys: test payments and payouts run on our simulator (no bank, no real money). End each one as a provider would and receive the real signed callback at your endpoint."
    },
    {
      "name": "System",
      "description": "Operational endpoints"
    }
  ],
  "paths": {
    "/auth/token": {
      "post": {
        "tags": [
          "Auth"
        ],
        "summary": "Get a bearer token",
        "description": "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.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email",
                  "password"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email",
                    "example": "you@example.com",
                    "description": "Account email."
                  },
                  "password": {
                    "type": "string",
                    "format": "password",
                    "example": "your-password",
                    "description": "Account password."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Authenticated.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "token": {
                      "type": "string",
                      "description": "Opaque bearer token (not a JWT)."
                    },
                    "token_type": {
                      "type": "string",
                      "example": "Bearer"
                    },
                    "user": {
                      "$ref": "#/components/schemas/User"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidBody"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/me": {
      "get": {
        "tags": [
          "Account"
        ],
        "summary": "Get current user",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "The authenticated user.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/User"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/transactions": {
      "get": {
        "tags": [
          "Resources"
        ],
        "summary": "List transactions",
        "description": "Module: transactions.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1
            },
            "description": "1-based page number (ignored when cursor is sent)."
          },
          {
            "name": "per_page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 25,
              "minimum": 1,
              "maximum": 500
            },
            "description": "Items per page."
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Keyset cursor for deep pagination — pass meta.next_cursor verbatim. O(1) continuation; prefer over large page numbers."
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "success",
                "pending",
                "failed"
              ]
            },
            "description": "Filter by status."
          }
        ],
        "responses": {
          "200": {
            "description": "A paginated list of transactions.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaginatedList"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/settlements": {
      "get": {
        "tags": [
          "Resources"
        ],
        "summary": "List settlements",
        "description": "Module: settlement.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1
            },
            "description": "1-based page number (ignored when cursor is sent)."
          },
          {
            "name": "per_page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 25,
              "minimum": 1,
              "maximum": 500
            },
            "description": "Items per page."
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Keyset cursor for deep pagination — pass meta.next_cursor verbatim. O(1) continuation; prefer over large page numbers."
          }
        ],
        "responses": {
          "200": {
            "description": "A paginated list of settlements.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaginatedList"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/payouts": {
      "get": {
        "tags": [
          "Resources"
        ],
        "summary": "List payouts",
        "description": "Module: payout.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1
            },
            "description": "1-based page number (ignored when cursor is sent)."
          },
          {
            "name": "per_page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 25,
              "minimum": 1,
              "maximum": 500
            },
            "description": "Items per page."
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Keyset cursor for deep pagination — pass meta.next_cursor verbatim. O(1) continuation; prefer over large page numbers."
          }
        ],
        "responses": {
          "200": {
            "description": "A paginated list of payouts.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaginatedList"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/missing-transactions": {
      "get": {
        "tags": [
          "Resources"
        ],
        "summary": "List missing transactions",
        "description": "Module: missing_transactions.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1
            },
            "description": "1-based page number (ignored when cursor is sent)."
          },
          {
            "name": "per_page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 25,
              "minimum": 1,
              "maximum": 500
            },
            "description": "Items per page."
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Keyset cursor for deep pagination — pass meta.next_cursor verbatim. O(1) continuation; prefer over large page numbers."
          }
        ],
        "responses": {
          "200": {
            "description": "A paginated list of missing transactions.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaginatedList"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/alerts": {
      "get": {
        "tags": [
          "Resources"
        ],
        "summary": "List alerts",
        "description": "Module: alerts.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1
            },
            "description": "1-based page number (ignored when cursor is sent)."
          },
          {
            "name": "per_page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 25,
              "minimum": 1,
              "maximum": 500
            },
            "description": "Items per page."
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Keyset cursor for deep pagination — pass meta.next_cursor verbatim. O(1) continuation; prefer over large page numbers."
          }
        ],
        "responses": {
          "200": {
            "description": "A paginated list of alerts.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaginatedList"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "post": {
        "tags": [
          "Resources"
        ],
        "summary": "Update alerts",
        "description": "Mark alerts read. Requires manage access to the alerts module.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "action": {
                    "type": "string",
                    "enum": [
                      "read_all"
                    ],
                    "description": "Mark all alerts read."
                  },
                  "id": {
                    "type": "string",
                    "example": "AL-01",
                    "description": "Mark a single alert read."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidBody"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      }
    },
    "/payments": {
      "get": {
        "tags": [
          "Live Payments"
        ],
        "summary": "List payments",
        "description": "List the merchant's payments, newest first. HMAC-signed; GET requests sign an empty body string. The signed path includes the query string.",
        "security": [
          {
            "apiKeyHmac": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1
            },
            "description": "1-based page number (ignored when cursor is sent)."
          },
          {
            "name": "per_page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 25,
              "minimum": 1,
              "maximum": 500
            },
            "description": "Items per page."
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Keyset cursor for deep pagination — pass meta.next_cursor verbatim. O(1) continuation; prefer over large page numbers."
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "UNPAID",
                "PAID",
                "EXPIRED",
                "CANCELED",
                "REFUNDED",
                "FAILED"
              ]
            },
            "description": "Filter by payment status."
          },
          {
            "name": "order_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Exact match on YOUR reference. Returns the single payment as { data: Payment } (404 when absent) — not a page."
          },
          {
            "name": "channel",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "QRIS",
                "VA",
                "E-Wallet",
                "Retail"
              ]
            },
            "description": "Filter by channel."
          },
          {
            "name": "site_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Filter by attributed website."
          },
          {
            "name": "q",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 3
            },
            "description": "Free-text search over id, order_id, rrn, provider_ref, va_number, settlement_id, player_ref, cms_trans_id (min 3 chars)."
          },
          {
            "name": "created_from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "ISO lower bound on created_at (alias: since)."
          },
          {
            "name": "created_to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "ISO upper bound on created_at (alias: until)."
          }
        ],
        "responses": {
          "200": {
            "description": "A list of payments with pagination meta.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Payment"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/InvalidSignature"
          }
        }
      },
      "post": {
        "tags": [
          "Live Payments"
        ],
        "summary": "Create a payment",
        "description": "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.",
        "security": [
          {
            "apiKeyHmac": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreatePaymentRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Payment created (UNPAID).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Payment"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidBody"
          },
          "401": {
            "$ref": "#/components/responses/InvalidSignature"
          },
          "502": {
            "description": "provider_error: the payment provider refused or failed the request. Safe to retry (same orderId / Idempotency-Key).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "provider_error"
                }
              }
            }
          }
        }
      }
    },
    "/payments/{id}": {
      "get": {
        "tags": [
          "Live Payments"
        ],
        "summary": "Get a payment",
        "description": "Fetch a single payment's status and details. HMAC-signed; GET requests sign an empty body string.",
        "security": [
          {
            "apiKeyHmac": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Payment id (SMP-…)."
          }
        ],
        "responses": {
          "200": {
            "description": "The payment.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Payment"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/InvalidSignature"
          },
          "404": {
            "description": "Payment not found."
          }
        }
      }
    },
    "/payments/{id}/refund": {
      "post": {
        "tags": [
          "Live Payments"
        ],
        "summary": "Refund a payment",
        "description": "Refund a captured (PAID) payment (REAL money). HMAC-signed. Reverses the ledger capture and moves the payment to status REFUNDED.",
        "security": [
          {
            "apiKeyHmac": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Payment id (SMP-…)."
          }
        ],
        "responses": {
          "200": {
            "description": "Payment refunded.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "status": {
                          "type": "string",
                          "example": "REFUNDED"
                        },
                        "refunded": {
                          "type": "number",
                          "multipleOf": 0.01,
                          "example": 2500
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidBody"
          },
          "401": {
            "$ref": "#/components/responses/InvalidSignature"
          },
          "404": {
            "description": "Payment not found."
          }
        }
      }
    },
    "/payments/{id}/cancel": {
      "post": {
        "tags": [
          "Live Payments"
        ],
        "summary": "Cancel a payment",
        "description": "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.",
        "security": [
          {
            "apiKeyHmac": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Payment id (SMP-…)."
          }
        ],
        "responses": {
          "200": {
            "description": "Payment canceled.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "status": {
                          "type": "string",
                          "example": "CANCELED"
                        },
                        "canceled": {
                          "type": "boolean",
                          "example": true
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidBody"
          },
          "401": {
            "$ref": "#/components/responses/InvalidSignature"
          },
          "404": {
            "description": "Payment not found."
          }
        }
      }
    },
    "/payments/{id}/receipt": {
      "post": {
        "tags": [
          "Live Payments"
        ],
        "summary": "Attach a transfer slip to a bank-transfer deposit",
        "description": "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.",
        "security": [
          {
            "apiKeyHmac": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Payment id (SMP-…)."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "image": {
                    "type": "string",
                    "description": "Base64 PNG or JPEG of the transfer slip (a data URI prefix is allowed)."
                  },
                  "refNo": {
                    "type": "string",
                    "example": "KB20261003-123",
                    "description": "Alternative to image: the bank's transfer reference, 3–64 characters."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Sent to the acquirer.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "uploaded": {
                          "type": "string",
                          "enum": [
                            "receipt",
                            "reference"
                          ]
                        },
                        "remaining": {
                          "type": "integer",
                          "example": 4
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "invalid_receipt, invalid_state, receipt_unsupported or receipt_rejected (the acquirer refused it)."
          },
          "401": {
            "$ref": "#/components/responses/InvalidSignature"
          },
          "404": {
            "description": "Payment not found."
          },
          "429": {
            "description": "receipt_limit (5 per payment) or rate_limited."
          }
        }
      }
    },
    "/balance": {
      "get": {
        "tags": [
          "Live Payments"
        ],
        "summary": "Get ledger balance",
        "description": "The merchant's real ledger balance, broken down into available, pending and reserved. HMAC-signed.",
        "security": [
          {
            "apiKeyHmac": []
          }
        ],
        "responses": {
          "200": {
            "description": "Real ledger balance.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Balance"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/InvalidSignature"
          }
        }
      }
    },
    "/disbursements": {
      "get": {
        "tags": [
          "Live Payments"
        ],
        "summary": "List disbursements",
        "description": "List payouts, newest first. HMAC-signed; GET requests sign an empty body string. The signed path includes the query string.",
        "security": [
          {
            "apiKeyHmac": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1
            },
            "description": "1-based page number (ignored when cursor is sent)."
          },
          {
            "name": "per_page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 25,
              "minimum": 1,
              "maximum": 500
            },
            "description": "Items per page."
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Keyset cursor for deep pagination — pass meta.next_cursor verbatim. O(1) continuation; prefer over large page numbers."
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "PENDING",
                "PROCESSING",
                "COMPLETED",
                "FAILED",
                "REVIEW",
                "AWAITING_APPROVAL"
              ]
            },
            "description": "Filter by disbursement status."
          },
          {
            "name": "created_from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "ISO lower bound on created_at (alias: since)."
          },
          {
            "name": "created_to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "ISO upper bound on created_at (alias: until)."
          }
        ],
        "responses": {
          "200": {
            "description": "A list of disbursements with pagination meta.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Disbursement"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/InvalidSignature"
          }
        }
      },
      "post": {
        "tags": [
          "Live Payments"
        ],
        "summary": "Create a disbursement (payout)",
        "description": "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).",
        "security": [
          {
            "apiKeyHmac": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 80
            },
            "description": "Optional idempotency key for safe retries (alternative to the body `idempotency_key` field). Retrying with the same key returns the same payout; reusing a key for a different amount, bank or account is refused with 409 idempotency_mismatch."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateDisbursementRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Disbursement accepted; funds reserved.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Disbursement"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidBody"
          },
          "401": {
            "$ref": "#/components/responses/InvalidSignature"
          },
          "402": {
            "$ref": "#/components/responses/InsufficientFunds"
          },
          "403": {
            "$ref": "#/components/responses/PinRejected"
          },
          "409": {
            "description": "idempotency_mismatch: the Idempotency-Key was already used for a different payout."
          },
          "502": {
            "description": "provider_error: the payment provider refused or failed the request. Safe to retry (same orderId / Idempotency-Key).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "provider_error"
                }
              }
            }
          }
        }
      }
    },
    "/sandbox/payments/{id}/simulate": {
      "post": {
        "tags": [
          "Test mode"
        ],
        "summary": "Simulate how a test payment ends",
        "description": "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.",
        "security": [
          {
            "apiKeyHmac": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Test payment id (SMP-…)."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "outcome"
                ],
                "properties": {
                  "outcome": {
                    "type": "string",
                    "enum": [
                      "paid",
                      "expired"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Ended; the callback result is included.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "status": {
                          "type": "string"
                        },
                        "callback": {
                          "type": "object",
                          "properties": {
                            "url": {
                              "type": "string",
                              "nullable": true
                            },
                            "event": {
                              "type": "string",
                              "nullable": true
                            },
                            "delivered": {
                              "type": "boolean"
                            },
                            "code": {
                              "type": "integer",
                              "nullable": true
                            },
                            "error": {
                              "type": "string",
                              "nullable": true
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "bad_outcome, not_simulated (not a test-mode payment) or invalid_state (already ended)."
          },
          "401": {
            "$ref": "#/components/responses/InvalidSignature"
          },
          "403": {
            "description": "live_account: use your test keys."
          },
          "404": {
            "description": "Payment not found."
          }
        }
      }
    },
    "/sandbox/payouts/{id}/simulate": {
      "post": {
        "tags": [
          "Test mode"
        ],
        "summary": "Simulate how a test payout ends",
        "description": "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.",
        "security": [
          {
            "apiKeyHmac": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Test payout id (SMO-…)."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "outcome"
                ],
                "properties": {
                  "outcome": {
                    "type": "string",
                    "enum": [
                      "completed",
                      "failed"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Ended; the callback result is included.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "status": {
                          "type": "string"
                        },
                        "callback": {
                          "type": "object",
                          "properties": {
                            "url": {
                              "type": "string",
                              "nullable": true
                            },
                            "event": {
                              "type": "string",
                              "nullable": true
                            },
                            "delivered": {
                              "type": "boolean"
                            },
                            "code": {
                              "type": "integer",
                              "nullable": true
                            },
                            "error": {
                              "type": "string",
                              "nullable": true
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "bad_outcome, not_simulated (not a test-mode payout) or invalid_state (already ended)."
          },
          "401": {
            "$ref": "#/components/responses/InvalidSignature"
          },
          "403": {
            "description": "live_account: use your test keys."
          },
          "404": {
            "description": "Payout not found."
          }
        }
      }
    },
    "/disbursements/{id}": {
      "get": {
        "tags": [
          "Live Payments"
        ],
        "summary": "Get a disbursement",
        "description": "Fetch a single payout's status and details so a merchant can poll one disbursement. HMAC-signed; GET requests sign an empty body string.",
        "security": [
          {
            "apiKeyHmac": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Disbursement id (SMO-…)."
          }
        ],
        "responses": {
          "200": {
            "description": "The disbursement.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Disbursement"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/InvalidSignature"
          },
          "404": {
            "description": "Disbursement not found."
          }
        }
      }
    },
    "/channels": {
      "get": {
        "tags": [
          "Live Payments"
        ],
        "summary": "Channel catalogue",
        "description": "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.",
        "security": [
          {
            "apiKeyHmac": []
          }
        ],
        "responses": {
          "200": {
            "description": "Pay-in and payout channels for this merchant.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                },
                "example": {
                  "data": {
                    "payin": [
                      {
                        "channel": "QRIS",
                        "limits": {
                          "min": 3,
                          "max": 1250000
                        },
                        "fee": {
                          "flat": 0,
                          "bps": 150
                        }
                      },
                      {
                        "channel": "VA",
                        "methods": [
                          "KBANK",
                          "SCB",
                          "KTB",
                          "BBL"
                        ],
                        "limits": {
                          "min": 3,
                          "max": 1250000
                        },
                        "fee": {
                          "flat": 0,
                          "bps": 150
                        }
                      }
                    ],
                    "payout": {
                      "banks": [
                        "Kasikornbank (KBANK)",
                        "Siam Commercial Bank (SCB)"
                      ],
                      "ewallets": [],
                      "limits": {
                        "min": 100,
                        "max": 1250000
                      },
                      "fee_mode": "on_top",
                      "fee": {
                        "flat": 10,
                        "bps": 0
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/InvalidSignature"
          }
        }
      }
    },
    "/events": {
      "get": {
        "tags": [
          "Live Payments"
        ],
        "summary": "Event feed",
        "description": "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.",
        "security": [
          {
            "apiKeyHmac": []
          }
        ],
        "parameters": [
          {
            "name": "after",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "next_cursor from the previous page."
          },
          {
            "name": "since",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Start from this ISO time (instead of after)."
          },
          {
            "name": "type",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Only this event type, e.g. payment.paid."
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A page of events.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "allOf": [
                          {
                            "$ref": "#/components/schemas/MerchantCallback"
                          },
                          {
                            "type": "object",
                            "properties": {
                              "delivery": {
                                "type": "object",
                                "properties": {
                                  "id": {
                                    "type": "string"
                                  },
                                  "status": {
                                    "type": "string",
                                    "enum": [
                                      "pending",
                                      "sending",
                                      "delivered",
                                      "failed"
                                    ]
                                  },
                                  "attempts": {
                                    "type": "integer"
                                  },
                                  "last_status_code": {
                                    "type": "integer",
                                    "nullable": true
                                  },
                                  "delivered_at": {
                                    "type": "string",
                                    "nullable": true
                                  }
                                }
                              }
                            }
                          }
                        ]
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "next_cursor": {
                      "type": "string",
                      "nullable": true
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "invalid_cursor or invalid_since.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/InvalidSignature"
          }
        }
      }
    },
    "/webhook-deliveries": {
      "get": {
        "tags": [
          "Live Payments"
        ],
        "summary": "Webhook delivery log",
        "description": "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.",
        "security": [
          {
            "apiKeyHmac": []
          }
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1
            },
            "description": "1-based page number (ignored when cursor is sent)."
          },
          {
            "name": "per_page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 25,
              "minimum": 1,
              "maximum": 500
            },
            "description": "Items per page."
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Keyset cursor for deep pagination — pass meta.next_cursor verbatim. O(1) continuation; prefer over large page numbers."
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "sending",
                "delivered",
                "failed"
              ]
            },
            "description": "Filter by delivery status."
          },
          {
            "name": "event",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Filter by event type (e.g. payment.paid)."
          }
        ],
        "responses": {
          "200": {
            "description": "A list of webhook deliveries with pagination meta.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": true
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/InvalidSignature"
          }
        }
      }
    },
    "/callbacks/provider": {
      "post": {
        "tags": [
          "Live Payments"
        ],
        "summary": "Provider webhook (inbound)",
        "description": "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.",
        "security": [
          {
            "apiKeyHmac": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEvent"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Accepted (or de-duplicated).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/InvalidSignature"
          }
        }
      }
    },
    "/health": {
      "get": {
        "tags": [
          "System"
        ],
        "summary": "Liveness probe",
        "description": "No auth required. Served at the root `/api/health`, not under `/api/v1`.",
        "servers": [
          {
            "url": "/api",
            "description": "Root"
          }
        ],
        "responses": {
          "200": {
            "description": "Service healthy.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "ok"
                    },
                    "db": {
                      "type": "string",
                      "example": "up"
                    },
                    "time": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "Service degraded or down."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "opaque"
      },
      "apiKeyHmac": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "HMAC request signing for the Live Payments API (separate from the bearer-token read/control API). Every request MUST send three headers: `X-API-Key` (merchant public key, e.g. `pk_live_your_api_key`), `X-Timestamp` (ISO-8601, must be within ±5 minutes of server time — replay protection), and `X-Signature` = HMAC-SHA256(secret, canonicalString) as lowercase hex. The canonical string is `\"{METHOD}:{path+query}:{timestamp}:{sha256hex(body)}\"` where `path+query` includes the `/api/v1` prefix and the full query string, and GET requests use the sha256 of an empty body string. The secret is your API secret: an Admin reveals it once on the merchant portal's Developers page (and rotates it there). The inbound provider webhook uses the same scheme but is signed with the shared webhook secret and omits `X-API-Key`. Errors: 401 `invalid_signature` (bad/missing signature) or `stale_request` (timestamp outside the window); 409 `replay_detected` (a signature may be used only once)."
      }
    },
    "schemas": {
      "Meta": {
        "type": "object",
        "properties": {
          "page": {
            "type": "integer",
            "example": 1
          },
          "per_page": {
            "type": "integer",
            "example": 25
          },
          "total": {
            "type": "integer",
            "example": 128
          },
          "total_pages": {
            "type": "integer",
            "example": 6
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ],
            "example": "2026-09-08T10:00:00.000Z|SMP-abc123",
            "description": "Pass as `cursor` to fetch the next page; null on the last page."
          }
        }
      },
      "PaginatedList": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "meta": {
            "$ref": "#/components/schemas/Meta"
          }
        }
      },
      "User": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "STF-01"
          },
          "name": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "role": {
            "type": "string",
            "example": "owner"
          },
          "roleLabel": {
            "type": "string",
            "example": "Owner"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        }
      },
      "CreatePaymentRequest": {
        "type": "object",
        "required": [
          "amount",
          "channel"
        ],
        "properties": {
          "amount": {
            "type": "number",
            "multipleOf": 0.01,
            "example": 2500,
            "description": "Amount in THB, up to 2 decimals (3–1,250,000)."
          },
          "channel": {
            "type": "string",
            "enum": [
              "QRIS",
              "VA",
              "E-Wallet",
              "Retail"
            ],
            "example": "QRIS"
          },
          "method": {
            "type": "string",
            "example": "SCB",
            "description": "Channel-specific method / bank. REQUIRED when channel=VA — see GET /channels for the entitled list."
          },
          "orderId": {
            "type": "string",
            "example": "ORD-123",
            "description": "Merchant order id. Idempotency key on (merchant, orderId)."
          },
          "siteId": {
            "type": "string",
            "example": "SITE-a1b2c3d4",
            "description": "Optional: attribute this payment to one of your registered websites (create them on the merchant portal's Sub-merchants page). Purely for reporting — a missing, foreign, or archived id is ignored, never rejected."
          },
          "player": {
            "type": "object",
            "description": "The player paying in. Required when the routed acquirer checks the payer's name against their bank account (APC Pay): the deposit is refused with payer_name_mismatch, payer_account_invalid, payer_account_blocked or payer_check_pending if the bank disagrees, or payer_required if missing.",
            "properties": {
              "id": {
                "type": "string",
                "example": "player-123",
                "description": "Your player id. Send the same id for the same player every time — the acquirer keys its name check on it."
              },
              "name": {
                "type": "string",
                "example": "Somchai Jaidee",
                "description": "Full name as on the player's bank account (English)."
              },
              "nameTh": {
                "type": "string",
                "example": "สมชาย ใจดี",
                "description": "Optional: full name in Thai."
              },
              "bankAccount": {
                "type": "string",
                "example": "1234567890",
                "description": "The bank account the player pays from."
              },
              "bankCode": {
                "type": "string",
                "example": "KBANK",
                "description": "Bank code of that account (see GET /api/v1/channels)."
              }
            }
          }
        }
      },
      "Payment": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "SMP-abc123"
          },
          "order_id": {
            "type": "string",
            "example": "ORD-123"
          },
          "status": {
            "type": "string",
            "enum": [
              "UNPAID",
              "PAID",
              "EXPIRED",
              "CANCELED",
              "REFUNDED",
              "FAILED"
            ],
            "example": "UNPAID"
          },
          "amount": {
            "type": "number",
            "multipleOf": 0.01,
            "example": 2500
          },
          "fee": {
            "type": "number",
            "multipleOf": 0.01,
            "example": 18
          },
          "net": {
            "type": "number",
            "multipleOf": 0.01,
            "example": 2483
          },
          "channel": {
            "type": "string",
            "example": "QRIS"
          },
          "provider": {
            "type": "string",
            "nullable": true,
            "example": "SiamTech 1",
            "description": "The SiamTechPay rail that issued the payment instrument."
          },
          "qr_content": {
            "type": "string",
            "nullable": true,
            "description": "QRIS payload (QRIS channel)."
          },
          "qr_image": {
            "type": "string",
            "nullable": true,
            "description": "Ready-to-display PNG rendering of qr_content as a data URI (data:image/png;base64,...). Present whenever qr_content is. Rendered on the fly, not stored — use it directly in an <img> tag or open it in a browser, no QR library needed."
          },
          "va_number": {
            "type": "string",
            "nullable": true,
            "description": "Virtual account number (VA channel)."
          },
          "payment_url": {
            "type": "string",
            "nullable": true,
            "description": "Payment page link. Set instead of qr_content / va_number when your account is routed to an acquirer that collects on its own page: send the player to this URL to pay. Null otherwise."
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "site_id": {
            "type": "string",
            "nullable": true,
            "description": "The registered website this payment was attributed to, if any."
          },
          "method": {
            "type": "string",
            "nullable": true,
            "description": "The method / bank you sent (VA)."
          },
          "provider_ref": {
            "type": "string",
            "nullable": true,
            "description": "The rail's own reference for this payment."
          },
          "rrn": {
            "type": "string",
            "nullable": true,
            "description": "Bank reference, once paid."
          },
          "checkout_url": {
            "type": "string",
            "description": "Our hosted payment page for this payment. Redirect the player here instead of drawing the QR yourself."
          },
          "player_ref": {
            "type": "string",
            "nullable": true,
            "description": "The player id you sent (player.id)."
          },
          "cms_trans_id": {
            "type": "string",
            "nullable": true
          },
          "settlement_id": {
            "type": "string",
            "nullable": true,
            "description": "Set once the payment is settled to your available balance."
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "paid_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "requested_amount": {
            "type": "number",
            "nullable": true,
            "description": "Set when the player paid LESS than the order and the provider settled it for what arrived: what the order asked. amount / fee / net are then what actually arrived. Credit the player `amount`."
          },
          "adjustment_type": {
            "type": "string",
            "nullable": true,
            "enum": [
              "SHORTFALL",
              "EXPIRED",
              "UNMATCHED",
              null
            ],
            "description": "Set on a make-up deposit: money that arrived with no order to settle. SHORTFALL = the player paid more than the order (this is the difference), EXPIRED = paid after the order ended, UNMATCHED = paid with no order (assigned by our team)."
          },
          "origin_payment_id": {
            "type": "string",
            "nullable": true,
            "description": "On a make-up deposit: our id of the payment it belongs to (null for UNMATCHED)."
          }
        }
      },
      "Balance": {
        "type": "object",
        "properties": {
          "currency": {
            "type": "string",
            "example": "THB"
          },
          "available": {
            "type": "number",
            "multipleOf": 0.01,
            "example": 12500,
            "description": "Withdrawable funds."
          },
          "pending": {
            "type": "number",
            "multipleOf": 0.01,
            "example": 2500,
            "description": "Paid but not yet settled."
          },
          "reserved": {
            "type": "number",
            "multipleOf": 0.01,
            "example": 1250,
            "description": "Held for in-flight disbursements."
          },
          "total": {
            "type": "number",
            "multipleOf": 0.01,
            "example": 16250
          }
        }
      },
      "CreateDisbursementRequest": {
        "type": "object",
        "required": [
          "amount",
          "bank",
          "account"
        ],
        "properties": {
          "amount": {
            "type": "number",
            "multipleOf": 0.01,
            "example": 1250
          },
          "bank": {
            "type": "string",
            "example": "Bangkok Bank (BBL)"
          },
          "account": {
            "type": "string",
            "example": "1234567890"
          },
          "idempotency_key": {
            "type": "string",
            "nullable": true,
            "maxLength": 80,
            "description": "Optional idempotency key for safe retries (alternative to the `Idempotency-Key` header)."
          },
          "accountName": {
            "type": "string",
            "example": "Somchai Jaidee",
            "description": "Recipient's full name as on the bank account (English). Required when the routed acquirer checks it (APC Pay) — payee_required if missing; payee_name_mismatch / payee_account_invalid / payee_account_blocked if the bank disagrees (funds are returned to available)."
          },
          "accountNameTh": {
            "type": "string",
            "example": "สมชาย ใจดี",
            "description": "Optional: recipient's full name in Thai."
          },
          "playerId": {
            "type": "string",
            "example": "player-123",
            "description": "Your player id for a player withdrawal. Required when the routed acquirer checks names (APC Pay); use the same id as on that player's deposits."
          }
        }
      },
      "Disbursement": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "SMO-a1b2c3d4e5f6",
            "description": "Disbursement id (SMO-…)."
          },
          "ref_id": {
            "type": "string",
            "example": "SMR-abc123-4821",
            "description": "Our reference for this payout (SMR-…), not yours: yours is idempotency_key."
          },
          "purpose": {
            "type": "string",
            "enum": [
              "player",
              "settlement"
            ],
            "example": "player"
          },
          "status": {
            "type": "string",
            "enum": [
              "PENDING",
              "PROCESSING",
              "COMPLETED",
              "FAILED",
              "REVIEW",
              "AWAITING_APPROVAL"
            ],
            "example": "PROCESSING",
            "description": "PENDING / PROCESSING / REVIEW are in flight; AWAITING_APPROVAL is held for approval (funds reserved, nothing sent); COMPLETED and FAILED are final (FAILED returns the total to your available balance)."
          },
          "amount": {
            "type": "number",
            "multipleOf": 0.01,
            "example": 1250
          },
          "fee": {
            "type": "number",
            "multipleOf": 0.01,
            "example": 7
          },
          "total": {
            "type": "number",
            "multipleOf": 0.01,
            "example": 1257,
            "description": "amount + fee reserved from available balance."
          },
          "account_name": {
            "type": "string",
            "example": "JOHN DOE"
          },
          "idempotency_key": {
            "type": "string",
            "nullable": true,
            "description": "Echoes the idempotency key used to create the payout, if any."
          },
          "bank": {
            "type": "string",
            "example": "Bangkok Bank (BBL)"
          },
          "account_number": {
            "type": "string",
            "example": "1234567890"
          },
          "provider": {
            "type": "string",
            "nullable": true
          },
          "provider_ref": {
            "type": "string",
            "nullable": true,
            "description": "The rail's own reference."
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "completed_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "approval": {
            "type": "object",
            "nullable": true,
            "description": "Set only while AWAITING_APPROVAL.",
            "properties": {
              "pending": {
                "type": "boolean"
              },
              "reason": {
                "type": "string",
                "enum": [
                  "above_threshold",
                  "over_daily_cap"
                ]
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      },
      "MerchantCallback": {
        "type": "object",
        "description": "What we POST to your callback URL. `event` names the type; `data` depends on it. Amounts are in the currency's major units with up to 2 decimals (฿7.21), the same unit as the request.",
        "required": [
          "event",
          "id",
          "created_at",
          "data"
        ],
        "properties": {
          "event": {
            "type": "string",
            "enum": [
              "payment.paid",
              "payment.expired",
              "payment.canceled",
              "payment.refunded",
              "disbursement.awaiting_approval",
              "disbursement.completed",
              "disbursement.failed"
            ],
            "example": "payment.paid"
          },
          "id": {
            "type": "string",
            "example": "sme_3f9c2a7b1d4e5f60",
            "description": "Event id; the same event retried keeps it, so dedupe on it."
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "When the event happened. NOT the signed timestamp (that is the header)."
          },
          "data": {
            "oneOf": [
              {
                "title": "payment.paid",
                "type": "object",
                "description": "Credit the player `amount`. When the player paid less, `requested_amount` is what the order asked. A make-up deposit (money with no order to settle) carries `adjustment_type`, `origin_payment_id` and `origin_order_id` (your orderId of the original) and its own payment_id; order_id is null unless our team set one.",
                "properties": {
                  "requested_amount": {
                    "type": "number",
                    "nullable": true
                  },
                  "adjustment_type": {
                    "type": "string",
                    "nullable": true,
                    "enum": [
                      "SHORTFALL",
                      "EXPIRED",
                      "UNMATCHED",
                      null
                    ]
                  },
                  "origin_payment_id": {
                    "type": "string",
                    "nullable": true
                  },
                  "origin_order_id": {
                    "type": "string",
                    "nullable": true
                  },
                  "payment_id": {
                    "type": "string"
                  },
                  "order_id": {
                    "type": "string",
                    "nullable": true,
                    "description": "Your orderId."
                  },
                  "amount": {
                    "type": "number",
                    "multipleOf": 0.01,
                    "description": "Amount paid."
                  },
                  "fee": {
                    "type": "number",
                    "multipleOf": 0.01
                  },
                  "net": {
                    "type": "number",
                    "multipleOf": 0.01,
                    "description": "amount - fee, credited to your balance."
                  },
                  "channel": {
                    "type": "string",
                    "example": "QRIS"
                  },
                  "status": {
                    "type": "string",
                    "example": "PAID"
                  },
                  "rrn": {
                    "type": "string",
                    "nullable": true
                  }
                }
              },
              {
                "title": "payment.expired",
                "type": "object",
                "properties": {
                  "payment_id": {
                    "type": "string"
                  },
                  "order_id": {
                    "type": "string",
                    "nullable": true
                  },
                  "amount": {
                    "type": "number",
                    "multipleOf": 0.01
                  },
                  "channel": {
                    "type": "string"
                  },
                  "status": {
                    "type": "string",
                    "example": "EXPIRED"
                  }
                }
              },
              {
                "title": "disbursement.completed",
                "type": "object",
                "properties": {
                  "disbursement_id": {
                    "type": "string"
                  },
                  "ref_id": {
                    "type": "string",
                    "description": "Our payout reference."
                  },
                  "idempotency_key": {
                    "type": "string",
                    "nullable": true,
                    "description": "Your Idempotency-Key from the create call: match the callback to your withdrawal with it (or with disbursement_id)."
                  },
                  "amount": {
                    "type": "number",
                    "multipleOf": 0.01
                  },
                  "fee": {
                    "type": "number",
                    "multipleOf": 0.01
                  },
                  "total": {
                    "type": "number",
                    "multipleOf": 0.01
                  },
                  "status": {
                    "type": "string",
                    "example": "COMPLETED"
                  }
                }
              },
              {
                "title": "disbursement.failed",
                "type": "object",
                "properties": {
                  "disbursement_id": {
                    "type": "string"
                  },
                  "ref_id": {
                    "type": "string"
                  },
                  "idempotency_key": {
                    "type": "string",
                    "nullable": true
                  },
                  "amount": {
                    "type": "number",
                    "multipleOf": 0.01
                  },
                  "total": {
                    "type": "number",
                    "multipleOf": 0.01,
                    "description": "Returned to your available balance."
                  },
                  "status": {
                    "type": "string",
                    "example": "FAILED"
                  }
                }
              },
              {
                "title": "disbursement.awaiting_approval",
                "type": "object",
                "properties": {
                  "disbursement_id": {
                    "type": "string"
                  },
                  "ref_id": {
                    "type": "string"
                  },
                  "idempotency_key": {
                    "type": "string",
                    "nullable": true
                  },
                  "amount": {
                    "type": "number",
                    "multipleOf": 0.01
                  },
                  "fee": {
                    "type": "number",
                    "multipleOf": 0.01
                  },
                  "total": {
                    "type": "number",
                    "multipleOf": 0.01
                  },
                  "status": {
                    "type": "string",
                    "example": "AWAITING_APPROVAL"
                  },
                  "approval_reason": {
                    "type": "string",
                    "enum": [
                      "above_threshold",
                      "over_daily_cap"
                    ]
                  }
                }
              },
              {
                "title": "payment.canceled / payment.refunded",
                "type": "object",
                "properties": {
                  "payment_id": {
                    "type": "string"
                  },
                  "order_id": {
                    "type": "string",
                    "nullable": true
                  },
                  "amount": {
                    "type": "number",
                    "multipleOf": 0.01
                  },
                  "channel": {
                    "type": "string",
                    "description": "canceled only"
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "CANCELED",
                      "REFUNDED"
                    ]
                  }
                }
              }
            ]
          }
        },
        "example": {
          "event": "payment.paid",
          "id": "sme_3f9c2a7b1d4e5f60",
          "created_at": "2026-10-29T08:15:02.114Z",
          "data": {
            "payment_id": "SMP-0b82898c-166",
            "order_id": "ORDER-1002",
            "amount": 250,
            "fee": 4,
            "net": 246,
            "channel": "QRIS",
            "status": "PAID",
            "rrn": "014299812345"
          }
        }
      },
      "WebhookEvent": {
        "description": "Provider-to-gateway webhook (internal). Merchants receive MerchantCallback instead.",
        "type": "object",
        "required": [
          "id",
          "type"
        ],
        "properties": {
          "id": {
            "type": "string",
            "example": "sme_demo_001",
            "description": "Event id — used for at-most-once idempotency."
          },
          "type": {
            "type": "string",
            "enum": [
              "payment.paid",
              "disbursement.completed",
              "disbursement.failed"
            ],
            "example": "payment.paid"
          },
          "paymentId": {
            "type": "string",
            "nullable": true,
            "description": "Present for payment.* events."
          },
          "disbursementId": {
            "type": "string",
            "nullable": true,
            "description": "Present for disbursement.* events."
          },
          "rrn": {
            "type": "string",
            "nullable": true,
            "description": "Provider reference / retrieval number."
          }
        }
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Missing or invalid credentials.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "unauthenticated"
            }
          }
        }
      },
      "Forbidden": {
        "description": "The role lacks access to this module.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "forbidden"
            }
          }
        }
      },
      "RateLimited": {
        "description": "Too many requests (10/min/IP on auth).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "rate_limited"
            }
          }
        }
      },
      "InvalidBody": {
        "description": "The request body failed validation.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "invalid_body"
            }
          }
        }
      },
      "InvalidSignature": {
        "description": "HMAC signature verification failed, or the request timestamp is outside the ±5 minute window.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "invalid_signature",
              "message": "signature mismatch (or stale_request if the timestamp is expired)"
            }
          }
        }
      },
      "InsufficientFunds": {
        "description": "The disbursement amount exceeds the available ledger balance.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "insufficient_funds"
            }
          }
        }
      },
      "PinRejected": {
        "description": "Payouts are refused for this merchant: the daily payout cap is reached, or payouts are disabled.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "daily_cap_exceeded"
            }
          }
        }
      }
    }
  },
  "security": [
    {
      "bearerAuth": []
    }
  ]
}