{
  "openapi": "3.1.0",
  "info": {
    "title": "AspiPay Public API",
    "version": "1.0.0",
    "description": "Public REST API for AspiPay. All endpoints require a Bearer API key issued to your merchant account. Amounts are in minor units (e.g. cents). All timestamps are ISO 8601 in UTC.",
    "contact": {
      "name": "AspiPay Support",
      "url": "https://aspipay.com"
    }
  },
  "servers": [
    {
      "url": "https://aspipay.com",
      "description": "Production"
    },
    {
      "url": "https://project--9b224e89-14be-4883-bb2e-071b952cc7db.lovable.app",
      "description": "Preview"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "sk_live_… / sk_test_…"
      }
    },
    "schemas": {
      "Money": {
        "type": "integer",
        "format": "int64",
        "description": "Amount in minor units (cents)",
        "example": 4999
      },
      "Currency": {
        "type": "string",
        "minLength": 3,
        "maxLength": 4,
        "example": "USD"
      },
      "Timestamp": {
        "type": "string",
        "format": "date-time",
        "example": "2026-07-12T17:00:00Z"
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string",
            "example": "invalid_amount"
          },
          "message": {
            "type": "string",
            "example": "Amount must be a positive integer"
          }
        }
      },
      "PaymentSession": {
        "type": "object",
        "required": [
          "id",
          "amount_minor",
          "currency",
          "status",
          "checkout_url",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "amount_minor": {
            "$ref": "#/components/schemas/Money"
          },
          "currency": {
            "$ref": "#/components/schemas/Currency"
          },
          "status": {
            "type": "string",
            "enum": [
              "created",
              "pending",
              "succeeded",
              "failed",
              "expired"
            ]
          },
          "checkout_url": {
            "type": "string",
            "format": "uri"
          },
          "success_url": {
            "type": "string",
            "format": "uri",
            "nullable": true
          },
          "cancel_url": {
            "type": "string",
            "format": "uri",
            "nullable": true
          },
          "customer_email": {
            "type": "string",
            "format": "email",
            "nullable": true
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true,
            "nullable": true
          },
          "created_at": {
            "$ref": "#/components/schemas/Timestamp"
          },
          "expires_at": {
            "$ref": "#/components/schemas/Timestamp"
          }
        }
      },
      "CreatePaymentSessionRequest": {
        "type": "object",
        "required": [
          "amount_minor",
          "currency"
        ],
        "properties": {
          "amount_minor": {
            "$ref": "#/components/schemas/Money"
          },
          "currency": {
            "$ref": "#/components/schemas/Currency"
          },
          "success_url": {
            "type": "string",
            "format": "uri"
          },
          "cancel_url": {
            "type": "string",
            "format": "uri"
          },
          "customer_email": {
            "type": "string",
            "format": "email"
          },
          "description": {
            "type": "string"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "Transaction": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "authorized",
              "succeeded",
              "failed",
              "refunded",
              "partially_refunded"
            ]
          },
          "amount_minor": {
            "$ref": "#/components/schemas/Money"
          },
          "currency": {
            "$ref": "#/components/schemas/Currency"
          },
          "refunded_amount_minor": {
            "$ref": "#/components/schemas/Money"
          },
          "payment_method_key": {
            "type": "string"
          },
          "country_code": {
            "type": "string"
          },
          "customer_email": {
            "type": "string",
            "format": "email",
            "nullable": true
          },
          "created_at": {
            "$ref": "#/components/schemas/Timestamp"
          }
        }
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Missing or invalid API key",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "Resource not found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "ValidationError": {
        "description": "Invalid request payload",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "Payment sessions",
      "description": "Create and retrieve hosted payment sessions."
    },
    {
      "name": "Transactions",
      "description": "Read completed payments."
    }
  ],
  "paths": {
    "/api/public/v1/payment_sessions": {
      "post": {
        "operationId": "createPaymentSession",
        "tags": [
          "Payment sessions"
        ],
        "summary": "Create a payment session",
        "description": "Creates a hosted payment session and returns a checkout URL. Redirect the customer to `checkout_url` to complete payment.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreatePaymentSessionRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Session created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentSession"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/api/public/v1/payment_sessions/{id}": {
      "get": {
        "operationId": "getPaymentSession",
        "tags": [
          "Payment sessions"
        ],
        "summary": "Retrieve a payment session",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Session details",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentSession"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/public/v1/transactions/{id}": {
      "get": {
        "operationId": "getTransaction",
        "tags": [
          "Transactions"
        ],
        "summary": "Retrieve a transaction",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Transaction details",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Transaction"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    }
  }
}