{
  "openapi": "3.1.0",
  "info": {
    "title": "FlatCryptoPay API",
    "version": "1.0.0",
    "description": "Non-custodial crypto payment gateway API. Create invoices and payment links; receive signed webhooks. Authenticate with a Bearer API key (fcp_live_... or fcp_test_...).",
    "contact": {
      "url": "https://flatcryptopay.com/contact/"
    },
    "termsOfService": "https://flatcryptopay.com/terms/"
  },
  "servers": [
    {
      "url": "https://flatcryptopay.com/api/v1"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/invoices": {
      "post": {
        "operationId": "createInvoice",
        "summary": "Create an invoice",
        "description": "Creates an invoice and returns its hosted payment page URL. Send an Idempotency-Key header to make retries safe.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "amount"
                ],
                "properties": {
                  "amount": {
                    "type": "string",
                    "example": "49.00"
                  },
                  "currency": {
                    "type": "string",
                    "enum": [
                      "USD",
                      "EUR",
                      "GBP",
                      "CAD",
                      "AUD"
                    ],
                    "default": "USD"
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "order_id": {
                    "type": "string",
                    "maxLength": 128
                  },
                  "customer_email": {
                    "type": "string",
                    "format": "email"
                  },
                  "redirect_url": {
                    "type": "string",
                    "format": "uri",
                    "description": "https only. Customer is sent here after payment."
                  },
                  "cancel_url": {
                    "type": "string",
                    "format": "uri"
                  },
                  "metadata": {
                    "type": "object",
                    "maxProperties": 20,
                    "additionalProperties": {
                      "type": "string",
                      "maxLength": 500
                    }
                  },
                  "expires_in": {
                    "type": "integer",
                    "minimum": 15,
                    "maximum": 10080,
                    "default": 1440,
                    "description": "Minutes until the invoice expires."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Invoice created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Invoice"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "operationId": "listInvoices",
        "summary": "List invoices",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "open",
                "processing",
                "paid",
                "expired",
                "canceled"
              ]
            }
          },
          {
            "name": "starting_after",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Invoice id to paginate after."
          }
        ],
        "responses": {
          "200": {
            "description": "A page of invoices",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "const": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Invoice"
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/invoices/{id}": {
      "get": {
        "operationId": "getInvoice",
        "summary": "Retrieve an invoice",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The invoice",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Invoice"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/invoices/{id}/cancel": {
      "post": {
        "operationId": "cancelInvoice",
        "summary": "Cancel an open invoice",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Canceled invoice",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Invoice"
                }
              }
            }
          },
          "409": {
            "description": "Invoice is not open",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/payment_links": {
      "post": {
        "operationId": "createPaymentLink",
        "summary": "Create a payment link",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "title"
                ],
                "properties": {
                  "title": {
                    "type": "string",
                    "maxLength": 120
                  },
                  "amount": {
                    "type": "string",
                    "description": "Omit to let the customer choose."
                  },
                  "currency": {
                    "type": "string",
                    "default": "USD"
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "redirect_url": {
                    "type": "string",
                    "format": "uri"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentLink"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "operationId": "listPaymentLinks",
        "summary": "List payment links",
        "responses": {
          "200": {
            "description": "Payment links",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PaymentLink"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "webhooks": {
    "invoiceEvent": {
      "post": {
        "summary": "Invoice event (invoice.processing, invoice.paid, invoice.expired, invoice.canceled, test.ping)",
        "description": "Signed with HMAC-SHA256: X-FCP-Signature = hex(HMAC(secret, X-FCP-Timestamp + \".\" + rawBody)). Reject timestamps older than 5 minutes and dedupe on X-FCP-Event-Id. Respond 2xx within 10 s; failures are retried up to 6 attempts.",
        "parameters": [
          {
            "name": "X-FCP-Event",
            "in": "header",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-FCP-Event-Id",
            "in": "header",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-FCP-Timestamp",
            "in": "header",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-FCP-Signature",
            "in": "header",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "type": {
                    "type": "string"
                  },
                  "created": {
                    "type": "integer"
                  },
                  "livemode": {
                    "type": "boolean"
                  },
                  "data": {
                    "type": "object",
                    "properties": {
                      "invoice": {
                        "$ref": "#/components/schemas/Invoice"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledged"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "fcp_live_... or fcp_test_..."
      }
    },
    "schemas": {
      "Invoice": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "inv_8fK2mQ9xLr3TzW1bN0aYc4"
          },
          "object": {
            "type": "string",
            "const": "invoice"
          },
          "livemode": {
            "type": "boolean"
          },
          "status": {
            "type": "string",
            "enum": [
              "open",
              "processing",
              "paid",
              "expired",
              "canceled"
            ]
          },
          "amount": {
            "type": "string",
            "example": "49.00",
            "description": "Decimal string, 2 decimals."
          },
          "currency": {
            "type": "string",
            "enum": [
              "USD",
              "EUR",
              "GBP",
              "CAD",
              "AUD"
            ]
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "order_id": {
            "type": [
              "string",
              "null"
            ],
            "description": "Your reference, max 128 characters."
          },
          "customer_email": {
            "type": [
              "string",
              "null"
            ],
            "format": "email"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "hosted_url": {
            "type": "string",
            "format": "uri",
            "description": "Send the customer here to pay."
          },
          "redirect_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri"
          },
          "cancel_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "paid_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "payment": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "via": {
                "type": "string",
                "enum": [
                  "crypto",
                  "card",
                  "simulated"
                ]
              },
              "method": {
                "type": "string",
                "example": "usdt_tron"
              },
              "amount": {
                "type": "string",
                "example": "49.0037"
              },
              "asset": {
                "type": [
                  "string",
                  "null"
                ],
                "example": "USDT"
              },
              "network": {
                "type": [
                  "string",
                  "null"
                ],
                "example": "tron"
              },
              "tx_hash": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "PaymentLink": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "pl_X2v9..."
          },
          "object": {
            "type": "string",
            "const": "payment_link"
          },
          "livemode": {
            "type": "boolean"
          },
          "active": {
            "type": "boolean"
          },
          "title": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "amount": {
            "type": [
              "string",
              "null"
            ],
            "description": "Null when the customer chooses the amount."
          },
          "currency": {
            "type": "string"
          },
          "redirect_url": {
            "type": [
              "string",
              "null"
            ]
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "invalid_request_error",
                  "authentication_error",
                  "rate_limit_error",
                  "api_error"
                ]
              },
              "code": {
                "type": "string",
                "example": "invalid_amount"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}