{
  "openapi": "3.1.0",
  "info": {
    "title": "DirectPagos Payments API",
    "version": "1.0.0",
    "description": "Non-custodial USDT (TRC20) payments. Create charges, monitor them on-chain, receive webhooks."
  },
  "servers": [
    {
      "url": "https://app.directpagos.com/api/public/v1"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key in the format `<prefix>.<secret>`. Test keys start with `ctest_`, live keys with `clive_`. Create keys at /dashboard/developers."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            },
            "required": [
              "code",
              "message"
            ]
          }
        }
      },
      "Wallet": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "address": {
            "type": "string",
            "example": "T..."
          },
          "network": {
            "type": "string",
            "example": "TRC20"
          },
          "is_active": {
            "type": "boolean"
          },
          "is_default": {
            "type": "boolean"
          }
        }
      },
      "ChargeCreate": {
        "type": "object",
        "required": [
          "amount"
        ],
        "properties": {
          "wallet_id": {
            "type": "string",
            "format": "uuid"
          },
          "wallet_address": {
            "type": "string",
            "pattern": "^T[a-zA-Z0-9]{33}$"
          },
          "amount": {
            "type": "number",
            "minimum": 0.01,
            "maximum": 1000000
          },
          "description": {
            "type": "string",
            "maxLength": 200
          },
          "reference": {
            "type": "string",
            "maxLength": 80
          },
          "customer_name": {
            "type": "string",
            "maxLength": 120
          },
          "customer_email": {
            "type": "string",
            "format": "email"
          },
          "customer_whatsapp": {
            "type": "string",
            "maxLength": 40
          },
          "return_url": {
            "type": "string",
            "format": "uri"
          },
          "webhook_url": {
            "type": "string",
            "format": "uri"
          },
          "ttl_minutes": {
            "type": "integer",
            "minimum": 5,
            "maximum": 1440,
            "default": 60
          },
          "checkout_language": {
            "type": "string",
            "enum": [
              "en",
              "pt",
              "es"
            ]
          }
        }
      },
      "Charge": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "pay_XXXX"
          },
          "amount": {
            "type": "number"
          },
          "expected_amount": {
            "type": "number",
            "description": "Amount with unique cents to identify the payment"
          },
          "currency": {
            "type": "string",
            "example": "USDT"
          },
          "network": {
            "type": "string",
            "example": "TRC20"
          },
          "wallet_address": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "created",
              "waiting_payment",
              "confirmed",
              "underpaid",
              "overpaid",
              "expired",
              "cancelled"
            ]
          },
          "description": {
            "type": "string",
            "nullable": true
          },
          "reference": {
            "type": "string",
            "nullable": true
          },
          "return_url": {
            "type": "string",
            "nullable": true
          },
          "webhook_url": {
            "type": "string",
            "nullable": true
          },
          "tx_hash": {
            "type": "string",
            "nullable": true
          },
          "received_amount": {
            "type": "number",
            "nullable": true
          },
          "detected_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "confirmed_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "hosted_url": {
            "type": "string",
            "example": "/pay/pay_XXXX"
          }
        }
      }
    }
  },
  "paths": {
    "/charges": {
      "post": {
        "summary": "Create a charge",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChargeCreate"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Charge"
                }
              }
            }
          },
          "400": {
            "description": "Invalid body",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Wallet not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "summary": "List charges",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Charge"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/charges/{paymentId}": {
      "get": {
        "summary": "Fetch a charge",
        "parameters": [
          {
            "name": "paymentId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Charge"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Cancel a charge",
        "parameters": [
          {
            "name": "paymentId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Cancelled"
          },
          "404": {
            "description": "Not found"
          },
          "409": {
            "description": "Invalid state"
          }
        }
      }
    },
    "/wallets": {
      "get": {
        "summary": "List wallets",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Wallet"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}