{
  "openapi": "3.0.3",
  "info": {
    "title": "Blockcade Payment Gateway API",
    "description": "Accept crypto and card payments, manage payment links, products, invoices, refunds, subscriptions, and settlements. Authenticate with a Bearer token (`Authorization: Bearer bck_live_...`). Idempotent POSTs accept an `Idempotency-Key` header.",
    "version": "1.0.0",
    "contact": {
      "name": "Blockcade support",
      "email": "support@blockcade.app"
    }
  },
  "servers": [
    {
      "url": "https://blockcade.app/gateway/api/v1",
      "description": "Production"
    },
    {
      "url": "https://blockcade.app/gateway/api",
      "description": "Legacy (unversioned \u2014 same code)"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Sessions",
      "description": "Hosted-checkout payment sessions"
    },
    {
      "name": "Payment Links",
      "description": "Reusable payment links"
    },
    {
      "name": "Products",
      "description": "Sellable products with public pages"
    },
    {
      "name": "Invoices",
      "description": "Single-use invoices"
    },
    {
      "name": "Refunds",
      "description": "Refunds against paid sessions"
    },
    {
      "name": "Customers",
      "description": "Merchant's customer directory (derived)"
    },
    {
      "name": "Settlements",
      "description": "Batched payouts"
    },
    {
      "name": "Analytics",
      "description": "Merchant analytics summaries"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API key"
      }
    },
    "parameters": {
      "cursor": {
        "name": "cursor",
        "in": "query",
        "schema": {
          "type": "string"
        },
        "description": "ISO datetime of last item from previous page."
      },
      "limit": {
        "name": "limit",
        "in": "query",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100
        },
        "description": "Items per page (default 25)."
      },
      "idempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "schema": {
          "type": "string",
          "maxLength": 120
        },
        "description": "Client-supplied key. Same key within 24h returns the same response."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "example": "invalid_request"
          },
          "message": {
            "type": "string",
            "example": "amount must be positive"
          },
          "status": {
            "type": "integer",
            "example": 400
          }
        }
      },
      "Money": {
        "type": "object",
        "required": [
          "amount",
          "currency"
        ],
        "properties": {
          "amount": {
            "type": "string",
            "example": "49.99"
          },
          "currency": {
            "type": "string",
            "example": "USD"
          }
        }
      },
      "Session": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "object": {
            "type": "string",
            "example": "session"
          },
          "reference": {
            "type": "string",
            "example": "ref_ABC123XYZ"
          },
          "amount": {
            "type": "string",
            "example": "49.99"
          },
          "currency": {
            "type": "string",
            "example": "USD"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "paid",
              "expired",
              "cancelled",
              "failed"
            ]
          },
          "customer_email": {
            "type": "string",
            "format": "email"
          },
          "hosted_url": {
            "type": "string",
            "format": "uri"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "paid_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "PaymentLink": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "object": {
            "type": "string",
            "example": "payment_link"
          },
          "slug": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "amount": {
            "type": "string"
          },
          "currency": {
            "type": "string"
          },
          "is_active": {
            "type": "boolean"
          },
          "url": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "Product": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "object": {
            "type": "string",
            "example": "product"
          },
          "slug": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "price": {
            "type": "string"
          },
          "currency": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "Invoice": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "object": {
            "type": "string",
            "example": "invoice"
          },
          "amount": {
            "type": "string"
          },
          "currency": {
            "type": "string"
          },
          "customer_email": {
            "type": "string"
          },
          "hosted_url": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "Refund": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "object": {
            "type": "string",
            "example": "refund"
          },
          "session_ref": {
            "type": "string"
          },
          "amount": {
            "type": "string"
          },
          "currency": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "List": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "example": "list"
          },
          "data": {
            "type": "array",
            "items": {}
          },
          "has_more": {
            "type": "boolean"
          },
          "next_cursor": {
            "type": "string",
            "nullable": true
          }
        }
      }
    }
  },
  "paths": {
    "/sessions/": {
      "post": {
        "tags": [
          "Sessions"
        ],
        "summary": "Create a session",
        "description": "Create a hosted-checkout session. Returns a `hosted_url` you can redirect the customer to.",
        "parameters": [
          {
            "$ref": "#/components/parameters/idempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "amount",
                  "currency"
                ],
                "properties": {
                  "amount": {
                    "type": "string",
                    "example": "49.99"
                  },
                  "currency": {
                    "type": "string",
                    "example": "USD"
                  },
                  "customer_email": {
                    "type": "string",
                    "format": "email"
                  },
                  "customer_name": {
                    "type": "string"
                  },
                  "accepted_currencies": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "example": [
                      "USDC",
                      "BTC"
                    ]
                  },
                  "success_url": {
                    "type": "string",
                    "format": "uri"
                  },
                  "cancel_url": {
                    "type": "string",
                    "format": "uri"
                  },
                  "metadata": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Session"
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          }
        }
      },
      "get": {
        "tags": [
          "Sessions"
        ],
        "summary": "List sessions",
        "parameters": [
          {
            "$ref": "#/components/parameters/cursor"
          },
          {
            "$ref": "#/components/parameters/limit"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/List"
                }
              }
            }
          }
        }
      }
    },
    "/sessions/{reference}/": {
      "get": {
        "tags": [
          "Sessions"
        ],
        "summary": "Retrieve a session",
        "parameters": [
          {
            "name": "reference",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Session"
                }
              }
            }
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/links/": {
      "post": {
        "tags": [
          "Payment Links"
        ],
        "summary": "Create a payment link",
        "parameters": [
          {
            "$ref": "#/components/parameters/idempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "title",
                  "amount",
                  "currency"
                ],
                "properties": {
                  "title": {
                    "type": "string"
                  },
                  "amount": {
                    "type": "string"
                  },
                  "currency": {
                    "type": "string"
                  },
                  "single_use": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentLink"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "Payment Links"
        ],
        "summary": "List payment links",
        "parameters": [
          {
            "$ref": "#/components/parameters/cursor"
          },
          {
            "$ref": "#/components/parameters/limit"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/List"
                }
              }
            }
          }
        }
      }
    },
    "/links/{slug}/": {
      "get": {
        "tags": [
          "Payment Links"
        ],
        "summary": "Retrieve a link",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentLink"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Payment Links"
        ],
        "summary": "Update a link",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "delete": {
        "tags": [
          "Payment Links"
        ],
        "summary": "Delete a link",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          }
        }
      }
    },
    "/products/": {
      "post": {
        "tags": [
          "Products"
        ],
        "summary": "Create a product",
        "parameters": [
          {
            "$ref": "#/components/parameters/idempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "title",
                  "price",
                  "currency"
                ],
                "properties": {
                  "title": {
                    "type": "string"
                  },
                  "price": {
                    "type": "string"
                  },
                  "currency": {
                    "type": "string"
                  },
                  "description": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Product"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "Products"
        ],
        "summary": "List products",
        "parameters": [
          {
            "$ref": "#/components/parameters/cursor"
          },
          {
            "$ref": "#/components/parameters/limit"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/List"
                }
              }
            }
          }
        }
      }
    },
    "/invoices/": {
      "post": {
        "tags": [
          "Invoices"
        ],
        "summary": "Create an invoice",
        "parameters": [
          {
            "$ref": "#/components/parameters/idempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "amount",
                  "currency",
                  "customer_email"
                ],
                "properties": {
                  "amount": {
                    "type": "string"
                  },
                  "currency": {
                    "type": "string"
                  },
                  "customer_email": {
                    "type": "string",
                    "format": "email"
                  },
                  "due_date": {
                    "type": "string",
                    "format": "date"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Invoice"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "Invoices"
        ],
        "summary": "List invoices",
        "parameters": [
          {
            "$ref": "#/components/parameters/cursor"
          },
          {
            "$ref": "#/components/parameters/limit"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/List"
                }
              }
            }
          }
        }
      }
    },
    "/refunds/": {
      "post": {
        "tags": [
          "Refunds"
        ],
        "summary": "Issue a refund",
        "parameters": [
          {
            "$ref": "#/components/parameters/idempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "session_ref"
                ],
                "properties": {
                  "session_ref": {
                    "type": "string"
                  },
                  "amount": {
                    "type": "string",
                    "description": "Partial refund amount. Omit for full refund."
                  },
                  "reason": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Refund created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Refund"
                }
              }
            }
          },
          "200": {
            "description": "Idempotent replay"
          }
        }
      },
      "get": {
        "tags": [
          "Refunds"
        ],
        "summary": "List refunds",
        "parameters": [
          {
            "$ref": "#/components/parameters/cursor"
          },
          {
            "$ref": "#/components/parameters/limit"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/List"
                }
              }
            }
          }
        }
      }
    },
    "/customers/": {
      "get": {
        "tags": [
          "Customers"
        ],
        "summary": "List customers",
        "description": "Derived from paid sessions grouped by customer_email.",
        "parameters": [
          {
            "$ref": "#/components/parameters/cursor"
          },
          {
            "$ref": "#/components/parameters/limit"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/settlements/": {
      "get": {
        "tags": [
          "Settlements"
        ],
        "summary": "List settlements",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/analytics/summary/": {
      "get": {
        "tags": [
          "Analytics"
        ],
        "summary": "Analytics summary",
        "parameters": [
          {
            "name": "days",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 30
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "sessions_created": {
                      "type": "integer"
                    },
                    "sessions_paid": {
                      "type": "integer"
                    },
                    "conversion": {
                      "type": "number"
                    },
                    "revenue_by_currency": {
                      "type": "object"
                    },
                    "revenue_by_method": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}