{
  "openapi": "3.1.0",
  "info": {
    "title": "Syndicate Payments API",
    "version": "2026-09-01",
    "description": "Server-to-server hosted payment collection. Use a project API key for this deployment’s test or live environment. Amounts are integer minor units of the payment currency: satang for THB, cents for USD, pence for GBP (100 minor units = 1 major unit). THB is the default; USD and GBP are available for card payments only. JSON request bodies are limited to 32 KB. Rate limit: 120 requests per minute per project; after HTTP 429 wait one minute. No Retry-After header is supplied. Creation returns HTTP 200, including idempotent retries. Never fulfill an order from a browser redirect; verify signed webhooks."
  },
  "servers": [
    {
      "url": "/",
      "description": "The deployment serving this specification"
    }
  ],
  "security": [
    {
      "ProjectApiKey": []
    }
  ],
  "paths": {
    "/api/v1/checkouts": {
      "post": {
        "operationId": "createCheckout",
        "summary": "Create an order-specific hosted checkout",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            "description": "Unique within project, environment and operation. Retry identical requests with the same key."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateCheckout"
              },
              "example": {
                "amount_minor": 49000,
                "description": "Pro plan",
                "external_order_id": "order-1042"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Checkout"
                },
                "example": {
                  "id": "11111111-1111-4111-8111-111111111111",
                  "status": "created",
                  "payment_method": null,
                  "provider": null,
                  "version": 1,
                  "amount_minor": 49000,
                  "currency": "THB",
                  "capture_mode": "automatic",
                  "external_order_id": "order-1042",
                  "external_customer_id": null,
                  "metadata": {},
                  "hosted_url": "https://payments.example.com/checkout/example-token",
                  "expires_at": null,
                  "paid_at": null,
                  "refunded_minor": 0
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "413": {
            "$ref": "#/components/responses/BodyTooLarge"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        },
        "description": "Creates an unselected checkout. Redirect the customer to hosted_url; no charge or QR exists until customer selection. Idempotency is scoped to project, environment and operation and compares validated parameters. A retry returns the current resource. Conflicts include idempotency_conflict, order_exists, project_unavailable, uat_required and manual_capture_uat. Manual capture is test-only and requires staff capture.",
        "tags": ["Checkouts"]
      }
    },
    "/api/v1/checkouts/{id}": {
      "get": {
        "operationId": "getCheckout",
        "summary": "Retrieve a checkout owned by the authenticated project",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Checkout"
                },
                "example": {
                  "id": "11111111-1111-4111-8111-111111111111",
                  "status": "created",
                  "payment_method": null,
                  "provider": null,
                  "version": 1,
                  "amount_minor": 49000,
                  "currency": "THB",
                  "capture_mode": "automatic",
                  "external_order_id": "order-1042",
                  "external_customer_id": null,
                  "metadata": {},
                  "hosted_url": "https://payments.example.com/checkout/example-token",
                  "expires_at": null,
                  "paid_at": null,
                  "refunded_minor": 0
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        },
        "tags": ["Checkouts"],
        "description": "Returns the latest checkout snapshot for this project and environment. A successful payment has status paid."
      }
    },
    "/api/v1/checkouts/{id}/cancel": {
      "post": {
        "operationId": "cancelCheckout",
        "summary": "Cancel an unpaid checkout; uncertain creation must first reconcile",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Checkout"
                },
                "example": {
                  "id": "11111111-1111-4111-8111-111111111111",
                  "status": "canceled",
                  "payment_method": null,
                  "provider": null,
                  "version": 2,
                  "amount_minor": 49000,
                  "currency": "THB",
                  "capture_mode": "automatic",
                  "external_order_id": "order-1042",
                  "external_customer_id": null,
                  "metadata": {},
                  "hosted_url": "https://payments.example.com/checkout/example-token",
                  "expires_at": null,
                  "paid_at": null,
                  "refunded_minor": 0
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        },
        "tags": ["Checkouts"],
        "description": "Cancels an unpaid checkout after open attempts are confirmed closed. Conflicts include already_paid, payment_in_progress and outcome_unknown. Repeating cancellation of an already canceled checkout returns it. No idempotency header is required."
      }
    },
    "/api/v1/payment-links": {
      "post": {
        "operationId": "createPaymentLink",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            "description": "Unique within project, environment and operation. Retry identical requests with the same key."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreatePaymentLink"
              },
              "example": {
                "amount_minor": 49000,
                "description": "Pro plan",
                "usage": "reusable"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentLink"
                },
                "example": {
                  "id": "11111111-1111-4111-8111-111111111111",
                  "amount_minor": 49000,
                  "currency": "THB",
                  "description": "Pro plan",
                  "usage": "reusable",
                  "active": true,
                  "locale": "en",
                  "expires_at": null,
                  "url": "https://payments.example.com/pay/example-token"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "413": {
            "$ref": "#/components/responses/BodyTooLarge"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        },
        "tags": ["Payment links"],
        "description": "Creates a single_use or reusable hosted payment link. Idempotency is scoped to project, environment and operation; reuse the same key and validated parameters on retries. Conflicts include idempotency_conflict, project_unavailable and uat_required. expires_at must be in the future. A single-use link retains one checkout permanently, even after refund.",
        "summary": "Create a hosted payment link"
      }
    },
    "/api/v1/payment-links/{id}": {
      "get": {
        "operationId": "getPaymentLink",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentLink"
                },
                "example": {
                  "id": "11111111-1111-4111-8111-111111111111",
                  "amount_minor": 49000,
                  "currency": "THB",
                  "description": "Pro plan",
                  "usage": "reusable",
                  "active": true,
                  "locale": "en",
                  "expires_at": null,
                  "url": "https://payments.example.com/pay/example-token"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        },
        "tags": ["Payment links"],
        "description": "Retrieves a payment link belonging to this project and environment.",
        "summary": "Retrieve a payment link"
      },
      "patch": {
        "operationId": "updatePaymentLink",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["active"],
                "additionalProperties": false,
                "properties": {
                  "active": {
                    "type": "boolean"
                  }
                }
              },
              "example": {
                "active": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentLink"
                },
                "example": {
                  "id": "11111111-1111-4111-8111-111111111111",
                  "amount_minor": 49000,
                  "currency": "THB",
                  "description": "Pro plan",
                  "usage": "reusable",
                  "active": true,
                  "locale": "en",
                  "expires_at": null,
                  "url": "https://payments.example.com/pay/example-token"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "413": {
            "$ref": "#/components/responses/BodyTooLarge"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        },
        "tags": ["Payment links"],
        "description": "Sets active to true or false. Does not cancel previously created checkouts. No idempotency header is required.",
        "summary": "Activate or deactivate a payment link"
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ProjectApiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "sp_test_… or sp_live_…"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "object",
            "required": ["code", "message"],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "fields": {
                "type": "object",
                "description": "For invalid_request, a message for each invalid field, keyed by its path.",
                "additionalProperties": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "CreateCheckout": {
        "type": "object",
        "required": ["amount_minor", "description"],
        "properties": {
          "amount_minor": {
            "type": "integer",
            "minimum": 1,
            "maximum": 999999999
          },
          "currency": {
            "type": "string",
            "enum": ["THB", "USD", "GBP"],
            "default": "THB",
            "description": "THB, USD or GBP. USD and GBP checkouts accept card payments only. amount_minor is in the currency's minor unit (satang, cents or pence)."
          },
          "description": {
            "type": "string",
            "minLength": 1,
            "description": "Trimmed before validation; must contain 1–256 characters after trimming.",
            "pattern": "^\\s*\\S(?:[\\s\\S]{0,254}\\S)?\\s*$"
          },
          "external_order_id": {
            "type": "string",
            "maxLength": 200,
            "minLength": 1
          },
          "external_customer_id": {
            "type": "string",
            "maxLength": 200
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true,
            "default": {}
          },
          "locale": {
            "type": "string",
            "enum": ["en", "th"],
            "default": "en"
          },
          "return_url": {
            "type": "string",
            "format": "uri",
            "description": "Must exactly match a configured project return URL."
          },
          "qr_expire_time": {
            "type": "integer",
            "minimum": 60,
            "maximum": 86400,
            "default": 600,
            "description": "QR lifetime in seconds after payment selection; does not set the checkout retry window."
          },
          "capture_mode": {
            "type": "string",
            "enum": ["automatic", "manual"],
            "description": "Defaults to automatic. Manual capture is test-only pending KPN UAT, offers cards only, and requires staff capture after authorization. The effective default is automatic."
          }
        },
        "additionalProperties": false,
        "examples": [
          {
            "amount_minor": 49000,
            "description": "Pro plan",
            "external_order_id": "order-1042"
          }
        ]
      },
      "CreatePaymentLink": {
        "type": "object",
        "required": ["amount_minor", "description", "usage"],
        "properties": {
          "amount_minor": {
            "type": "integer",
            "minimum": 1,
            "maximum": 999999999
          },
          "currency": {
            "type": "string",
            "enum": ["THB", "USD", "GBP"],
            "default": "THB",
            "description": "THB, USD or GBP. USD and GBP checkouts accept card payments only. amount_minor is in the currency's minor unit (satang, cents or pence)."
          },
          "description": {
            "type": "string",
            "minLength": 1,
            "description": "Trimmed before validation; must contain 1–256 characters after trimming.",
            "pattern": "^\\s*\\S(?:[\\s\\S]{0,254}\\S)?\\s*$"
          },
          "locale": {
            "type": "string",
            "enum": ["en", "th"],
            "default": "en"
          },
          "return_url": {
            "type": "string",
            "format": "uri",
            "description": "Must exactly match a configured project return URL."
          },
          "usage": {
            "type": "string",
            "enum": ["single_use", "reusable"]
          },
          "expires_at": {
            "type": "string",
            "format": "date-time",
            "description": "ISO 8601 timestamp with timezone; must be in the future."
          }
        },
        "additionalProperties": false,
        "examples": [
          {
            "amount_minor": 49000,
            "description": "Pro plan",
            "usage": "reusable"
          }
        ]
      },
      "Checkout": {
        "type": "object",
        "required": [
          "id",
          "status",
          "version",
          "amount_minor",
          "currency",
          "hosted_url",
          "expires_at",
          "paid_at",
          "external_order_id",
          "external_customer_id",
          "metadata",
          "refunded_minor",
          "payment_method",
          "provider",
          "capture_mode"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "created",
              "pending",
              "paid",
              "failed",
              "expired",
              "canceled"
            ]
          },
          "version": {
            "type": "integer"
          },
          "amount_minor": {
            "type": "integer"
          },
          "currency": {
            "type": "string",
            "enum": ["THB", "USD", "GBP"]
          },
          "hosted_url": {
            "type": "string",
            "format": "uri"
          },
          "expires_at": {
            "type": ["string", "null"],
            "format": "date-time"
          },
          "paid_at": {
            "type": ["string", "null"],
            "format": "date-time"
          },
          "external_order_id": {
            "type": ["string", "null"]
          },
          "external_customer_id": {
            "type": ["string", "null"]
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          },
          "refunded_minor": {
            "type": "integer"
          },
          "payment_method": {
            "type": ["string", "null"],
            "enum": [
              "promptpay",
              "truemoney_jumpapp",
              "shopeepay_jumpapp",
              "rabbit_linepay",
              "wechat_pay",
              "credit_card",
              "kplus",
              "bay",
              "ktb",
              "scb",
              null
            ]
          },
          "provider": {
            "type": ["string", "null"],
            "enum": ["pgw", "kpn", null]
          },
          "capture_mode": {
            "type": "string",
            "enum": ["automatic", "manual"]
          }
        },
        "examples": [
          {
            "id": "11111111-1111-4111-8111-111111111111",
            "status": "created",
            "payment_method": null,
            "provider": null,
            "version": 1,
            "amount_minor": 49000,
            "currency": "THB",
            "capture_mode": "automatic",
            "external_order_id": "order-1042",
            "external_customer_id": null,
            "metadata": {},
            "hosted_url": "https://payments.example.com/checkout/example-token",
            "expires_at": null,
            "paid_at": null,
            "refunded_minor": 0
          }
        ]
      },
      "PaymentLink": {
        "type": "object",
        "required": [
          "id",
          "url",
          "amount_minor",
          "currency",
          "description",
          "usage",
          "active",
          "locale",
          "expires_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "amount_minor": {
            "type": "integer"
          },
          "currency": {
            "type": "string",
            "enum": ["THB", "USD", "GBP"]
          },
          "description": {
            "type": "string"
          },
          "usage": {
            "type": "string",
            "enum": ["single_use", "reusable"]
          },
          "active": {
            "type": "boolean"
          },
          "locale": {
            "type": "string",
            "enum": ["en", "th"]
          },
          "expires_at": {
            "type": ["string", "null"],
            "format": "date-time"
          }
        },
        "examples": [
          {
            "id": "11111111-1111-4111-8111-111111111111",
            "amount_minor": 49000,
            "currency": "THB",
            "description": "Pro plan",
            "usage": "reusable",
            "active": true,
            "locale": "en",
            "expires_at": null,
            "url": "https://payments.example.com/pay/example-token"
          }
        ]
      },
      "Event": {
        "oneOf": [
          {
            "$ref": "#/components/schemas/PaymentEvent"
          },
          {
            "$ref": "#/components/schemas/RefundEvent"
          }
        ],
        "discriminator": {
          "propertyName": "type",
          "mapping": {
            "payment.succeeded": "#/components/schemas/PaymentEvent",
            "payment.failed": "#/components/schemas/PaymentEvent",
            "payment.expired": "#/components/schemas/PaymentEvent",
            "payment.canceled": "#/components/schemas/PaymentEvent",
            "refund.pending": "#/components/schemas/RefundEvent",
            "refund.succeeded": "#/components/schemas/RefundEvent",
            "refund.failed": "#/components/schemas/RefundEvent"
          }
        }
      },
      "PaymentEvent": {
        "type": "object",
        "required": [
          "id",
          "type",
          "api_version",
          "created_at",
          "environment",
          "project_id",
          "merchant_id",
          "data"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "type": {
            "type": "string",
            "enum": [
              "payment.succeeded",
              "payment.failed",
              "payment.expired",
              "payment.canceled"
            ]
          },
          "api_version": {
            "const": "2026-09-01"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "environment": {
            "enum": ["test", "live"],
            "type": "string"
          },
          "project_id": {
            "type": "string",
            "format": "uuid"
          },
          "merchant_id": {
            "type": "string",
            "format": "uuid"
          },
          "data": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "checkout_id": {
                "type": "string",
                "format": "uuid"
              },
              "version": {
                "type": "integer"
              },
              "status": {
                "type": "string",
                "enum": [
                  "created",
                  "pending",
                  "paid",
                  "failed",
                  "expired",
                  "canceled"
                ]
              },
              "amount_minor": {
                "type": "integer"
              },
              "currency": {
                "const": "THB"
              },
              "external_order_id": {
                "type": ["string", "null"]
              },
              "external_customer_id": {
                "type": ["string", "null"]
              },
              "metadata": {
                "type": "object",
                "additionalProperties": true
              },
              "payment_method": {
                "type": ["string", "null"],
                "enum": [
                  "promptpay",
                  "truemoney_jumpapp",
                  "shopeepay_jumpapp",
                  "rabbit_linepay",
                  "wechat_pay",
                  "credit_card",
                  "kplus",
                  "bay",
                  "ktb",
                  "scb",
                  null
                ]
              },
              "provider": {
                "type": ["string", "null"],
                "enum": ["pgw", "kpn", null]
              },
              "attempt_id": {
                "type": ["string", "null"],
                "format": "uuid"
              }
            },
            "required": [
              "id",
              "checkout_id",
              "version",
              "status",
              "amount_minor",
              "currency",
              "external_order_id",
              "external_customer_id",
              "metadata",
              "payment_method",
              "provider",
              "attempt_id"
            ]
          }
        },
        "description": "data.id is the checkout ID; amount_minor is the checkout amount. payment.succeeded reports status paid.",
        "examples": [
          {
            "id": "11111111-1111-4111-8111-111111111111",
            "type": "payment.succeeded",
            "api_version": "2026-09-01",
            "created_at": "2026-09-10T00:00:00Z",
            "environment": "test",
            "project_id": "11111111-1111-4111-8111-111111111111",
            "merchant_id": "11111111-1111-4111-8111-111111111111",
            "data": {
              "id": "11111111-1111-4111-8111-111111111111",
              "checkout_id": "11111111-1111-4111-8111-111111111111",
              "version": 2,
              "status": "paid",
              "attempt_id": "11111111-1111-4111-8111-111111111111",
              "payment_method": "kplus",
              "provider": "pgw",
              "amount_minor": 49000,
              "currency": "THB",
              "external_order_id": "order-1042",
              "external_customer_id": null,
              "metadata": {}
            }
          }
        ]
      },
      "RefundEvent": {
        "type": "object",
        "required": [
          "id",
          "type",
          "api_version",
          "created_at",
          "environment",
          "project_id",
          "merchant_id",
          "data"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "type": {
            "type": "string",
            "enum": ["refund.pending", "refund.succeeded", "refund.failed"]
          },
          "api_version": {
            "const": "2026-09-01"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "environment": {
            "enum": ["test", "live"],
            "type": "string"
          },
          "project_id": {
            "type": "string",
            "format": "uuid"
          },
          "merchant_id": {
            "type": "string",
            "format": "uuid"
          },
          "data": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "checkout_id": {
                "type": "string",
                "format": "uuid"
              },
              "version": {
                "type": "integer"
              },
              "status": {
                "type": "string",
                "enum": ["created", "pending", "uncertain", "success", "failed"]
              },
              "amount_minor": {
                "type": "integer"
              },
              "currency": {
                "const": "THB"
              },
              "external_order_id": {
                "type": ["string", "null"]
              },
              "external_customer_id": {
                "type": ["string", "null"]
              },
              "metadata": {
                "type": "object",
                "additionalProperties": true
              },
              "payment_method": {
                "type": ["string", "null"],
                "enum": [
                  "promptpay",
                  "truemoney_jumpapp",
                  "shopeepay_jumpapp",
                  "rabbit_linepay",
                  "wechat_pay",
                  "credit_card",
                  "kplus",
                  "bay",
                  "ktb",
                  "scb",
                  null
                ]
              },
              "provider": {
                "type": ["string", "null"],
                "enum": ["pgw", "kpn", null]
              },
              "attempt_id": {
                "type": ["string", "null"],
                "format": "uuid"
              }
            },
            "required": [
              "id",
              "checkout_id",
              "version",
              "status",
              "amount_minor",
              "currency",
              "external_order_id",
              "external_customer_id",
              "metadata",
              "payment_method",
              "provider",
              "attempt_id"
            ]
          }
        },
        "description": "data.id is the refund ID; checkout_id links to the original checkout. amount_minor is the refund amount and version belongs to the refund. refund.succeeded reports status success.",
        "examples": [
          {
            "id": "11111111-1111-4111-8111-111111111111",
            "type": "refund.succeeded",
            "api_version": "2026-09-01",
            "created_at": "2026-09-10T00:00:00Z",
            "environment": "test",
            "project_id": "11111111-1111-4111-8111-111111111111",
            "merchant_id": "11111111-1111-4111-8111-111111111111",
            "data": {
              "id": "11111111-1111-4111-8111-111111111111",
              "checkout_id": "11111111-1111-4111-8111-111111111111",
              "version": 2,
              "status": "success",
              "attempt_id": "11111111-1111-4111-8111-111111111111",
              "payment_method": "credit_card",
              "provider": "kpn",
              "amount_minor": 49000,
              "currency": "THB",
              "external_order_id": "order-1042",
              "external_customer_id": null,
              "metadata": {}
            }
          }
        ]
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Invalid JSON, invalid_request, missing idempotency key, unapproved return URL, or invalid link expiry.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "invalid_request",
                "message": "Invalid JSON, invalid_request, missing idempotency key, unapproved return URL, or invalid link expiry."
              }
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing, inactive, invalid, or wrong-environment project API key.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "invalid_api_key",
                "message": "Missing, inactive, invalid, or wrong-environment project API key."
              }
            }
          }
        }
      },
      "NotFound": {
        "description": "Resource not found in the authenticated project and environment.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "not_found",
                "message": "Resource not found in the authenticated project and environment."
              }
            }
          }
        }
      },
      "Conflict": {
        "description": "Resource or payment state conflicts with this operation. See operation description.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "resource_conflict",
                "message": "Resource or payment state conflicts with this operation. See operation description."
              }
            }
          }
        }
      },
      "BodyTooLarge": {
        "description": "JSON request body exceeds 32 KB.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "body_too_large",
                "message": "JSON request body exceeds 32 KB."
              }
            }
          }
        }
      },
      "RateLimited": {
        "description": "Project exceeded 120 requests per minute. Wait one minute before retrying.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "rate_limit",
                "message": "Project exceeded 120 requests per minute. Wait one minute before retrying."
              }
            }
          }
        }
      },
      "InternalError": {
        "description": "Unexpected failure. Retry transient failures with backoff; for creation reuse the original idempotency key and body.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "internal_error",
                "message": "Unexpected failure. Retry transient failures with backoff; for creation reuse the original idempotency key and body."
              }
            }
          }
        }
      },
      "Unavailable": {
        "description": "Unsafe deployment environment or new payments disabled.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "unsafe_environment",
                "message": "Unsafe deployment environment or new payments disabled."
              }
            }
          }
        }
      }
    }
  },
  "webhooks": {
    "paymentEvent": {
      "post": {
        "summary": "Signed payment and refund event",
        "security": [],
        "parameters": [
          {
            "in": "header",
            "name": "x-syndicate-timestamp",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "x-syndicate-signature",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "x-syndicate-event-id",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Event"
              },
              "examples": {
                "PaymentEvent": {
                  "value": {
                    "id": "11111111-1111-4111-8111-111111111111",
                    "type": "payment.succeeded",
                    "api_version": "2026-09-01",
                    "created_at": "2026-09-10T00:00:00Z",
                    "environment": "test",
                    "project_id": "11111111-1111-4111-8111-111111111111",
                    "merchant_id": "11111111-1111-4111-8111-111111111111",
                    "data": {
                      "id": "11111111-1111-4111-8111-111111111111",
                      "checkout_id": "11111111-1111-4111-8111-111111111111",
                      "version": 2,
                      "status": "paid",
                      "attempt_id": "11111111-1111-4111-8111-111111111111",
                      "payment_method": "kplus",
                      "provider": "pgw",
                      "amount_minor": 49000,
                      "currency": "THB",
                      "external_order_id": "order-1042",
                      "external_customer_id": null,
                      "metadata": {}
                    }
                  }
                },
                "RefundEvent": {
                  "value": {
                    "id": "11111111-1111-4111-8111-111111111111",
                    "type": "refund.succeeded",
                    "api_version": "2026-09-01",
                    "created_at": "2026-09-10T00:00:00Z",
                    "environment": "test",
                    "project_id": "11111111-1111-4111-8111-111111111111",
                    "merchant_id": "11111111-1111-4111-8111-111111111111",
                    "data": {
                      "id": "11111111-1111-4111-8111-111111111111",
                      "checkout_id": "11111111-1111-4111-8111-111111111111",
                      "version": 2,
                      "status": "success",
                      "attempt_id": "11111111-1111-4111-8111-111111111111",
                      "payment_method": "credit_card",
                      "provider": "kpn",
                      "amount_minor": 49000,
                      "currency": "THB",
                      "external_order_id": "order-1042",
                      "external_customer_id": null,
                      "metadata": {}
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Event durably processed, or duplicate acknowledged without repeating fulfillment."
          },
          "default": {
            "description": "Delivery failed; the payment service retries non-2xx responses."
          }
        },
        "operationId": "receivePaymentEvent",
        "description": "Outgoing HTTPS POST to the endpoint configured in Developers. Verify HMAC-SHA256(secret, timestamp + \".\" + exact raw body) using a constant-time comparison. Reject timestamps outside ±300 seconds. Deduplicate event IDs and fulfill once per checkout in a durable transaction. Events may arrive out of order; refund versions are independent. A late payment.succeeded remains authoritative after expiry. Acknowledge with any 2xx only after commit. Failed deliveries retry for up to 72 hours; staff can replay deliveries."
      }
    }
  },
  "externalDocs": {
    "url": "/docs/integration",
    "description": "Integration guide and examples"
  },
  "tags": [
    {
      "name": "Checkouts",
      "description": "Create an order and send customers to hosted_url."
    },
    {
      "name": "Payment links",
      "description": "Create shareable single-use or reusable payment links."
    }
  ]
}
