{
  "openapi": "3.1.0",
  "info": {
    "title": "SikatPay API",
    "version": "1.0.0",
    "summary": "Accept QR Ph, GCash and Maya with one API call and a signed webhook.",
    "description": "Server-to-server API. Amounts are integer centavos (PHP 150.00 = 15000). Use a test key (mk_test_...) for simulated payments and a live key (mk_...) for real ones. Grant goods only from the payment.paid webhook, never from the return page. Keep prices on your server. Full guide: https://payment.sikatpinoy.net/docs · Plain-text guide for AI assistants: https://payment.sikatpinoy.net/llms.txt",
    "contact": { "name": "SikatPay support", "url": "https://payment.sikatpinoy.net/docs" }
  },
  "servers": [{ "url": "https://payment.sikatpinoy.net/api/v1" }],
  "security": [{ "bearerAuth": [] }],
  "paths": {
    "/payments": {
      "post": {
        "operationId": "createPayment",
        "summary": "Create a payment (idempotent per order_id)",
        "description": "Returns 201 for a new payment. With the same order_id and amount while a payment is still pending, returns 200 with the SAME payment and reused=true. Returns 409 if the order_id is already paid.",
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CreatePayment" } } }
        },
        "responses": {
          "201": { "description": "Created", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Payment" } } } },
          "200": { "description": "Existing pending payment for this order_id (reused: true)", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Payment" } } } },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "409": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/Error" },
          "500": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/payments/{id}": {
      "get": {
        "operationId": "getPayment",
        "summary": "Retrieve a payment",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "pattern": "^[A-Za-z0-9]{20}$" } }],
        "responses": {
          "200": { "description": "The payment", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Payment" } } } },
          "401": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" }
        }
      }
    }
  },
  "webhooks": {
    "payment.paid": {
      "post": {
        "summary": "A payment was paid",
        "description": "Sent to every webhook endpoint whose 'Receives' setting matches (live / test / both). Verify X-Signature with the RAW body: v1 = hex(HMAC_SHA256(endpoint_signing_secret, t + '.' + raw_body)); reject if |now - t| > 300 s. Respond 2xx within 8 s. Retries (same event id): 5s, 10s, 30s, 1m, 5m, 15m, 30m, 1h, 3h, 6h, 12h, 24h. Fulfil once; require data.amount == your order total; ignore livemode=false in production.",
        "parameters": [
          { "name": "X-Signature", "in": "header", "required": true, "schema": { "type": "string", "example": "t=1790000000,v1=5f2c…" } },
          { "name": "X-Event-Id", "in": "header", "required": true, "schema": { "type": "string" } },
          { "name": "User-Agent", "in": "header", "schema": { "type": "string", "example": "PaymentGateway-Webhook/1.0" } }
        ],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Event" } } } },
        "responses": { "200": { "description": "Acknowledged" } }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": { "type": "http", "scheme": "bearer", "description": "Live key mk_<48 hex> or test key mk_test_<48 hex>. Server-side only." }
    },
    "schemas": {
      "CreatePayment": {
        "type": "object",
        "required": ["amount"],
        "properties": {
          "amount": { "type": "integer", "minimum": 2000, "maximum": 5000000, "description": "Centavos. Must come from your server's price list, never from the client." },
          "order_id": { "type": "string", "maxLength": 100, "pattern": "^[\\w\\-.:#/ ]+$", "description": "Your order reference. Makes creation idempotent." },
          "description": { "type": "string", "maxLength": 200 },
          "success_url": { "type": "string", "format": "uri" },
          "cancel_url": { "type": "string", "format": "uri" }
        }
      },
      "Payment": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "livemode": { "type": "boolean" },
          "status": { "type": "string", "enum": ["pending", "paid", "expired", "review"] },
          "amount": { "type": "integer" },
          "currency": { "type": "string", "const": "PHP" },
          "order_id": { "type": ["string", "null"] },
          "description": { "type": "string" },
          "method": { "type": ["string", "null"], "enum": ["qrph", "gcash", "paymaya", null] },
          "platform_fee": { "type": ["integer", "null"] },
          "net_amount": { "type": ["integer", "null"] },
          "checkout_url": { "type": ["string", "null"], "format": "uri" },
          "created_at": { "type": ["string", "null"], "format": "date-time" },
          "paid_at": { "type": ["string", "null"], "format": "date-time" },
          "expires_at": { "type": ["string", "null"], "format": "date-time" },
          "reused": { "type": "boolean", "description": "Only on create: true when an existing pending payment was returned." }
        }
      },
      "Event": {
        "type": "object",
        "required": ["id", "type", "livemode", "created", "data"],
        "properties": {
          "id": { "type": "string", "description": "Same on every retry and endpoint — dedupe on it." },
          "type": { "type": "string", "enum": ["payment.paid", "ping"] },
          "livemode": { "type": "boolean" },
          "created": { "type": "integer", "description": "Unix seconds" },
          "sample": { "type": "boolean", "description": "true for dashboard sample events" },
          "data": { "$ref": "#/components/schemas/Payment" }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": { "type": "string", "enum": ["invalid_amount", "invalid_request", "unauthorized", "merchant_inactive", "policy_violation", "not_found", "order_already_paid", "order_pending_different_amount", "daily_limit", "daily_create_limit", "rate_limited", "server_error"] },
              "message": { "type": "string" }
            }
          }
        }
      }
    },
    "responses": {
      "Error": { "description": "Error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
    }
  }
}
