{
  "openapi": "3.0.3",
  "info": {
    "title": "openbcp Sandbox API",
    "version": "1.0.0",
    "description": "Free test environment for the openbcp USDT (BEP-20) payment API. Simulated payments confirm after ~3 seconds; no real funds. Identical contract to live; change only the server URL and API key. Data is deleted after 24 hours."
  },
  "servers": [
    {
      "url": "https://sandbox.openbcp.com",
      "description": "Sandbox"
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-openbcp-Api-Key",
        "description": "Sandbox key, starts with test_"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "example": "error"
          },
          "message": {
            "type": "string"
          }
        }
      },
      "Transaction": {
        "type": "object",
        "properties": {
          "txid": {
            "type": "string"
          },
          "amount_usdt": {
            "type": "string"
          },
          "confirmations": {
            "type": "integer"
          },
          "required_confirmations": {
            "type": "integer"
          },
          "status": {
            "type": "string",
            "enum": [
              "PENDING",
              "CONFIRMED"
            ]
          }
        }
      },
      "CreatePayment": {
        "type": "object",
        "required": [
          "amount_usdt"
        ],
        "properties": {
          "amount_usdt": {
            "type": "string",
            "example": "29.99",
            "description": "Min 0.01, max 1000000. Platform fee added on top."
          },
          "external_id": {
            "type": "string",
            "maxLength": 128
          },
          "callback_url": {
            "type": "string",
            "format": "uri",
            "description": "Public http(s) URL. Localhost/private addresses are rejected."
          },
          "success_url": {
            "type": "string",
            "format": "uri"
          },
          "metadata": {
            "type": "object"
          },
          "sandbox_scenario": {
            "type": "string",
            "enum": [
              "paid",
              "overpaid",
              "partial",
              "expired",
              "unpaid"
            ],
            "default": "paid"
          }
        }
      },
      "PaymentCreated": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "sandbox": {
            "type": "boolean"
          },
          "invoice_id": {
            "type": "integer"
          },
          "checkout_token": {
            "type": "string"
          },
          "deposit_address": {
            "type": "string",
            "description": "Synthetic. Never send real funds."
          },
          "amount_usdt": {
            "type": "string"
          },
          "merchant_amount_usdt": {
            "type": "string"
          },
          "platform_fee_usdt": {
            "type": "string"
          },
          "payment_url": {
            "type": "string",
            "format": "uri"
          },
          "status_url": {
            "type": "string",
            "format": "uri"
          },
          "success_url": {
            "type": "string",
            "nullable": true
          },
          "network": {
            "type": "string"
          },
          "token": {
            "type": "string"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "PaymentStatus": {
        "type": "object",
        "properties": {
          "invoice_id": {
            "type": "integer"
          },
          "sandbox": {
            "type": "boolean"
          },
          "payment_status": {
            "type": "string",
            "enum": [
              "UNPAID",
              "PARTIAL",
              "PAID",
              "OVERPAID",
              "EXPIRED",
              "CANCELLED"
            ]
          },
          "amount_usdt": {
            "type": "string"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "confirmations": {
            "type": "integer"
          },
          "required_confirmations": {
            "type": "integer"
          },
          "tx_count": {
            "type": "integer"
          },
          "transactions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Transaction"
            }
          }
        }
      },
      "WebhookPayload": {
        "type": "object",
        "description": "POSTed to callback_url. Headers: X-openbcp-Timestamp (unix s), X-openbcp-Signature = hex HMAC-SHA256(api_key, '<timestamp>.<raw body>').",
        "properties": {
          "invoice_id": {
            "type": "integer"
          },
          "sandbox": {
            "type": "boolean"
          },
          "external_id": {
            "type": "string",
            "nullable": true
          },
          "status": {
            "type": "string",
            "enum": [
              "UNPAID",
              "PARTIAL",
              "PAID",
              "OVERPAID",
              "EXPIRED",
              "CANCELLED"
            ]
          },
          "amount_usdt": {
            "type": "string"
          },
          "amount_received": {
            "type": "string"
          },
          "shortfall": {
            "type": "string"
          },
          "overpaid_by": {
            "type": "string"
          },
          "deposit_address": {
            "type": "string"
          },
          "txid": {
            "type": "string",
            "nullable": true
          },
          "paid": {
            "type": "boolean"
          },
          "paid_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    }
  },
  "paths": {
    "/api/v1/payment": {
      "post": {
        "summary": "Create a payment (invoice)",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreatePayment"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentCreated"
                }
              }
            }
          },
          "400": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/payment/{invoice_id}": {
      "get": {
        "summary": "Get full invoice",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "invoice_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Invoice"
          },
          "404": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/payment/{invoice_id}/status": {
      "get": {
        "summary": "Poll payment status",
        "description": "Requires ?token=<checkout_token> (or X-Checkout-Token header) or the owning API key; otherwise 404.",
        "parameters": [
          {
            "name": "invoice_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Status",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentStatus"
                }
              }
            }
          },
          "404": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/payment/{invoice_id}/webhooks": {
      "get": {
        "summary": "Webhook delivery log (sandbox only)",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "invoice_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deliveries"
          },
          "404": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/pay/{checkout_token}": {
      "get": {
        "summary": "Hosted checkout page (redirect the customer here)",
        "parameters": [
          {
            "name": "checkout_token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "HTML page"
          },
          "404": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "webhooks": {
    "invoiceStatusChange": {
      "post": {
        "summary": "Invoice reached PAID, OVERPAID, PARTIAL, EXPIRED or CANCELLED",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookPayload"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Acknowledged"
          }
        }
      }
    }
  }
}