{
 "openapi": "3.1.0",
 "info": {
  "title": "Amerifax Payments API",
  "version": "1.0.0",
  "summary": "Accept USDT (TRC20) payments with invoices, a hosted checkout and signed webhooks.",
  "description": "Create an invoice, send the customer to checkout_url, and receive an `invoice.paid` webhook when the exact pay_amount arrives on TRON. Webhooks are POSTed as JSON `{event, created, data: Invoice}` with headers `X-Amerifax-Event`, `X-Amerifax-Timestamp` and `X-Amerifax-Signature: sha256=<hex>` where hex = HMAC-SHA256(webhook_secret, timestamp + \".\" + raw_body). Failed deliveries are retried up to 6 times. API keys are created in the Amerifax dashboard (identity verification required). Rate limit: 120 requests per minute.",
  "contact": {
   "name": "Amerifax support",
   "url": "https://amerifax.com/support#contact"
  }
 },
 "externalDocs": {
  "description": "Developer guide",
  "url": "https://amerifax.com/developers"
 },
 "servers": [
  {
   "url": "https://api.amerifax.com/v1"
  }
 ],
 "security": [
  {
   "bearerAuth": []
  }
 ],
 "paths": {
  "/rates": {
   "get": {
    "operationId": "getRates",
    "summary": "Supported coins, fee percent and invoice lifetime",
    "security": [],
    "responses": {
     "200": {
      "description": "Rates",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "fee_percent": {
           "type": "number",
           "example": 0.5
          },
          "invoice_ttl_minutes": {
           "type": "integer"
          },
          "coins": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "coin": {
              "type": "string"
             },
             "ticker": {
              "type": "string"
             },
             "network": {
              "type": "string"
             },
             "enabled": {
              "type": "boolean"
             }
            }
           }
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/invoices": {
   "post": {
    "operationId": "createInvoice",
    "summary": "Create an invoice",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "amount"
        ],
        "properties": {
         "amount": {
          "type": "string",
          "description": "USD-pegged amount, 1 to 1000000, up to 2 decimals",
          "example": "25.00"
         },
         "coin": {
          "type": "string",
          "default": "USDT-TRC20",
          "enum": [
           "USDT-TRC20"
          ]
         },
         "order_id": {
          "type": "string",
          "maxLength": 100
         },
         "description": {
          "type": "string",
          "maxLength": 300
         },
         "redirect_url": {
          "type": "string",
          "description": "Where checkout sends the customer after payment"
         },
         "webhook_url": {
          "type": "string",
          "description": "Overrides the API key's default webhook URL (must be a public https URL)"
         },
         "expires_in_minutes": {
          "type": "integer",
          "minimum": 10,
          "maximum": 1440
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Invoice created",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Invoice"
        }
       }
      }
     },
     "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"
        }
       }
      }
     },
     "503": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "get": {
    "operationId": "listInvoices",
    "summary": "List your invoices, newest first",
    "parameters": [
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "pending",
        "paid",
        "expired",
        "cancelled"
       ]
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 20
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Invoices",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Invoice"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/invoices/{id}": {
   "get": {
    "operationId": "getInvoice",
    "summary": "Get one invoice",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Invoice",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Invoice"
        }
       }
      }
     },
     "401": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/invoices/{id}/cancel": {
   "post": {
    "operationId": "cancelInvoice",
    "summary": "Cancel a pending invoice",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Cancelled invoice",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Invoice"
        }
       }
      }
     },
     "400": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/balance": {
   "get": {
    "operationId": "getBalance",
    "summary": "Your non-zero balances",
    "responses": {
     "200": {
      "description": "Balances",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "balances": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "coin": {
              "type": "string"
             },
             "amount": {
              "type": "string"
             }
            }
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  }
 },
 "webhooks": {
  "invoice.paid": {
   "post": {
    "summary": "Sent when an invoice is paid in full on-chain",
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "event": {
          "const": "invoice.paid"
         },
         "created": {
          "type": "string",
          "format": "date-time"
         },
         "data": {
          "$ref": "#/components/schemas/Invoice"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Return any 2xx to acknowledge"
     }
    }
   }
  }
 },
 "components": {
  "securitySchemes": {
   "bearerAuth": {
    "type": "http",
    "scheme": "bearer",
    "description": "API key in the form ak_xxxxxxxx_<40 hex>"
   }
  },
  "schemas": {
   "Invoice": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "example": "inv_3f9a1c0b7d2e4a6f8b10"
     },
     "status": {
      "type": "string",
      "enum": [
       "pending",
       "paid",
       "expired",
       "cancelled"
      ]
     },
     "coin": {
      "type": "string",
      "example": "USDT-TRC20"
     },
     "currency": {
      "type": "string",
      "example": "USDT"
     },
     "network": {
      "type": "string",
      "example": "TRC20"
     },
     "amount": {
      "type": "string",
      "description": "Amount you asked for",
      "example": "25.00"
     },
     "pay_amount": {
      "type": "string",
      "description": "Exact amount the customer must send (amount + 0.01–0.99 to make it unique)",
      "example": "25.37"
     },
     "address": {
      "type": "string",
      "description": "TRON address the customer pays to"
     },
     "description": {
      "type": "string"
     },
     "order_id": {
      "type": "string"
     },
     "fee": {
      "type": "string",
      "description": "Amerifax fee for this invoice"
     },
     "net_amount": {
      "type": "string",
      "description": "amount minus fee, credited to your balance when paid"
     },
     "redirect_url": {
      "type": "string"
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "expires_at": {
      "type": "string",
      "format": "date-time"
     },
     "paid_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "txid": {
      "type": [
       "string",
       "null"
      ],
      "description": "On-chain transaction hash once paid"
     },
     "checkout_url": {
      "type": "string",
      "example": "https://pay.amerifax.com/i/inv_3f9a1c0b7d2e4a6f8b10"
     }
    }
   },
   "Error": {
    "type": "object",
    "properties": {
     "error": {
      "type": "string"
     }
    }
   }
  }
 }
}