{
  "openapi": "3.1.0",
  "info": {
    "title": "pi-dal Checkout API",
    "version": "1.0.0",
    "description": "Creates a Creem checkout session for donations and product purchases."
  },
  "servers": [
    {
      "url": "https://pi-dal.com"
    }
  ],
  "paths": {
    "/functions/creem-checkout": {
      "post": {
        "summary": "Create a checkout session",
        "description": "Proxies checkout creation to Creem using the site's configured API key. This endpoint is currently unauthenticated.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateCheckoutRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Checkout created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CheckoutResponse"
                }
              }
            }
          },
          "500": {
            "description": "Server or upstream error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      },
      "options": {
        "summary": "CORS preflight",
        "responses": {
          "200": {
            "description": "Allowed methods and headers"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "CreateCheckoutRequest": {
        "type": "object",
        "properties": {
          "product_id": {
            "type": "string"
          },
          "units": {
            "type": "integer",
            "minimum": 1
          },
          "customer": {
            "type": "object",
            "properties": {
              "email": {
                "type": "string",
                "format": "email"
              }
            },
            "additionalProperties": false
          },
          "success_url": {
            "type": "string",
            "format": "uri"
          },
          "cancel_url": {
            "type": "string",
            "format": "uri"
          },
          "request_id": {
            "type": "string"
          },
          "discount_code": {
            "type": "string"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        },
        "additionalProperties": false
      },
      "CheckoutResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "checkout_url": {
            "type": "string",
            "format": "uri"
          },
          "status": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "checkout_url",
          "status"
        ]
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          },
          "details": {}
        },
        "required": [
          "error"
        ]
      }
    }
  }
}
