{
  "openapi": "3.1.0",
  "info": {
    "title": "Payrail by LanternPay API",
    "version": "1.0.0",
    "description": "Nigerian B2B payment gateway API for NGN bank transfer collections, hosted checkout, and webhook reconciliation.",
    "contact": {
      "name": "Lantern Digital Solutions LTD",
      "url": "https://payrail.lanternpay.org/support",
      "email": "info@lanternpay.org"
    }
  },
  "servers": [
    {
      "url": "https://gatewayapi.lanternpay.org/v1",
      "description": "Production API"
    }
  ],
  "security": [{ "BearerAuth": [] }],
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Merchant secret key (sk_test_... for test mode, sk_live_... for live mode)"
      }
    }
  },
  "paths": {
    "/transactions/initialize": {
      "post": {
        "operationId": "initializeTransaction",
        "summary": "Initialize a payment session",
        "description": "Creates a hosted checkout URL for NGN bank transfer payments. Amounts are in kobo (min 10000 = NGN 100).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["amount", "email"],
                "properties": {
                  "amount": { "type": "integer", "minimum": 10000, "description": "Amount in kobo (NGN 1 = 100 kobo)" },
                  "email": { "type": "string", "format": "email" },
                  "reference": { "type": "string", "description": "Unique merchant order reference for idempotency" },
                  "callback_url": { "type": "string", "format": "uri" },
                  "bearer": { "type": "string", "enum": ["merchant", "customer"], "description": "Who pays the processing fee" },
                  "currency": { "type": "string", "enum": ["NGN"], "default": "NGN" },
                  "metadata": { "type": "object", "additionalProperties": true }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Payment session initialized with checkout_url" },
          "400": { "description": "Validation error" },
          "401": { "description": "Invalid secret key" },
          "409": { "description": "Duplicate reference with different parameters" }
        }
      }
    },
    "/transactions/{reference}": {
      "get": {
        "operationId": "verifyTransaction",
        "summary": "Verify a transaction",
        "parameters": [
          {
            "name": "reference",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "description": "Payrail reference or merchant_reference"
          }
        ],
        "responses": {
          "200": { "description": "Transaction details and status" },
          "404": { "description": "Transaction not found" }
        }
      }
    },
    "/transactions": {
      "get": {
        "operationId": "listTransactions",
        "summary": "List transactions",
        "parameters": [
          { "name": "page", "in": "query", "schema": { "type": "integer", "default": 1 } },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "default": 20, "maximum": 100 } },
          { "name": "status", "in": "query", "schema": { "type": "string", "enum": ["pending", "success", "failed", "reversed"] } }
        ],
        "responses": {
          "200": { "description": "Paginated list of transactions" }
        }
      }
    }
  }
}
