{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/tgpaycrypto-com/json-schema/tgpaycrypto-com-create-invoice-request-schema.json",
  "title": "CreateInvoiceRequest",
  "x-generated": "2026-11-25",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/tgpaycrypto-com-openapi.json#/components/schemas/CreateInvoiceRequest",
  "type": "object",
  "properties": {
    "currency_type": {
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "crypto",
            "fiat"
          ],
          "default": "crypto"
        },
        {
          "type": "null"
        }
      ]
    },
    "asset": {
      "anyOf": [
        {
          "type": "string",
          "description": "Required in crypto mode; non-empty asset is rejected in fiat mode.",
          "maxLength": 16
        },
        {
          "type": "null"
        }
      ]
    },
    "fiat": {
      "anyOf": [
        {
          "type": "string",
          "description": "Fiat mode: the fiat currency the invoice is priced in (is_fiat rows of getCurrencies).",
          "maxLength": 8
        },
        {
          "type": "null"
        }
      ]
    },
    "accepted_assets": {
      "anyOf": [
        {
          "description": "Fiat mode: comma-separated asset codes or a JSON array. Omitted, null or empty list means all enabled assets.",
          "oneOf": [
            {
              "type": "string"
            },
            {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "amount": {
      "anyOf": [
        {
          "$ref": "#/$defs/AmountInput",
          "description": "Required unless open_amount. Crypto mode: in asset units; fiat mode: in fiat units, max 2 decimal places."
        },
        {
          "type": "null"
        }
      ]
    },
    "open_amount": {
      "anyOf": [
        {
          "$ref": "#/$defs/BooleanInput",
          "description": "Crypto mode only: no fixed amount — the payer enters it at pay time. Mutually exclusive with amount.",
          "default": false
        },
        {
          "type": "null"
        }
      ]
    },
    "description": {
      "anyOf": [
        {
          "type": "string",
          "maxLength": 1024,
          "description": "Shown to the payer."
        },
        {
          "type": "null"
        }
      ]
    },
    "hidden_message": {
      "anyOf": [
        {
          "type": "string",
          "maxLength": 2048,
          "description": "Shown to the payer only after payment."
        },
        {
          "type": "null"
        }
      ]
    },
    "payload": {
      "anyOf": [
        {
          "type": "string",
          "maxLength": 4096,
          "description": "Opaque merchant data echoed back in the invoice object and webhook."
        },
        {
          "type": "null"
        }
      ]
    },
    "allow_comments": {
      "anyOf": [
        {
          "$ref": "#/$defs/BooleanInput",
          "default": true
        },
        {
          "type": "null"
        }
      ]
    },
    "allow_anonymous": {
      "anyOf": [
        {
          "$ref": "#/$defs/BooleanInput",
          "default": false
        },
        {
          "type": "null"
        }
      ]
    },
    "paid_btn_name": {
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "viewItem",
            "openChannel",
            "openBot",
            "callback"
          ],
          "description": "Post-payment CTA button."
        },
        {
          "type": "null"
        }
      ]
    },
    "paid_btn_url": {
      "anyOf": [
        {
          "type": "string",
          "maxLength": 512,
          "description": "Required with paid_btn_name; must begin with lowercase http:// or https://. Without paid_btn_name it is ignored."
        },
        {
          "type": "null"
        }
      ]
    },
    "swap_to": {
      "anyOf": [
        {
          "type": "string",
          "description": "Auto-swap the received amount to this asset after payment, on a best-effort basis: if pricing, tradability or capacity is unavailable, the conversion is skipped and the paid asset is kept.",
          "maxLength": 16
        },
        {
          "type": "null"
        }
      ]
    },
    "expires_in": {
      "anyOf": [
        {
          "oneOf": [
            {
              "type": "integer",
              "maximum": 2678400,
              "minimum": 0
            },
            {
              "type": "string",
              "pattern": "^\\s*(?:\\+?0*(?:[1-9][0-9]{0,5}|1[0-9]{6}|2[0-5][0-9]{5}|26[0-6][0-9]{4}|267[0-7][0-9]{3}|2678[0-3][0-9]{2}|2678400)|[+-]?0+)\\s*$"
            }
          ],
          "description": "Seconds until expiry, at most 31 days. Omitted, null or zero uses the default lifetime. Read expiration_date in the response for the actual deadline; null means no deadline."
        },
        {
          "type": "null"
        }
      ]
    },
    "rate_lock_seconds": {
      "anyOf": [
        {
          "oneOf": [
            {
              "type": "integer",
              "maximum": 86400,
              "minimum": 0
            },
            {
              "type": "string",
              "pattern": "^\\s*(?:\\+?0*(?:[1-9][0-9]{0,3}|[1-7][0-9]{4}|8[0-5][0-9]{3}|86[0-3][0-9]{2}|86400)|[+-]?0+)\\s*$"
            }
          ],
          "description": "Fiat mode: positive value requests a rate lock, clamped to the platform window (minimum requested window 60 s). Zero/omitted/null disables the lock; expired locks revert to fresh rates."
        },
        {
          "type": "null"
        }
      ]
    },
    "success_url": {
      "anyOf": [
        {
          "$ref": "#/$defs/ReturnUrl",
          "description": "A Return button after payment — the short form of the paid button (sets paid_btn_name to callback). Exclusive with paid_btn_name / paid_btn_url."
        },
        {
          "type": "null"
        }
      ]
    },
    "cancel_url": {
      "anyOf": [
        {
          "$ref": "#/$defs/ReturnUrl",
          "description": "A Return button shown while the invoice is unpaid."
        },
        {
          "type": "null"
        }
      ]
    },
    "customer": {
      "anyOf": [
        {
          "$ref": "#/$defs/CustomerInput"
        },
        {
          "type": "string",
          "description": "Form/query transport: the customer object as JSON text. An empty string means none."
        },
        {
          "type": "null"
        }
      ]
    },
    "max_payments": {
      "anyOf": [
        {
          "oneOf": [
            {
              "type": "integer",
              "maximum": 1000000,
              "minimum": 1
            },
            {
              "type": "string",
              "pattern": "^\\s*\\+?0*(?:[1-9][0-9]{0,5}|1000000)\\s*$"
            }
          ],
          "description": "How many payments one pay_url takes (default 1). Above 1, each payment becomes its own invoice with parent_invoice_id; the link itself is never paid and reads status paid once payments_count reaches max_payments. Such an invoice is paid from a wallet only, not by a transfer to an address."
        },
        {
          "type": "null"
        }
      ]
    },
    "client_invoice_id": {
      "anyOf": [
        {
          "type": "string",
          "maxLength": 64,
          "description": "The seller's own invoice id, unique within the app; surrounding spaces are trimmed and an empty string means none. A create repeating an id in use returns the existing invoice (current state, other parameters not compared). Reusable after deleteInvoice."
        },
        {
          "type": "null"
        }
      ]
    },
    "webhook_url": {
      "anyOf": [
        {
          "$ref": "#/$defs/OperationWebhookUrl"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "allOf": [
    {
      "if": {
        "required": [
          "currency_type"
        ],
        "properties": {
          "currency_type": {
            "const": "fiat"
          }
        }
      },
      "then": {
        "allOf": [
          {
            "required": [
              "fiat"
            ],
            "properties": {
              "fiat": {
                "not": {
                  "type": "null"
                }
              }
            }
          },
          {
            "required": [
              "amount"
            ],
            "properties": {
              "amount": {
                "not": {
                  "type": "null"
                }
              }
            }
          }
        ],
        "properties": {
          "asset": {
            "enum": [
              null,
              ""
            ]
          },
          "open_amount": {
            "not": {
              "oneOf": [
                {
                  "const": true
                },
                {
                  "const": 1
                },
                {
                  "type": "string",
                  "pattern": "^\\s*(?:[Tt][Rr][Uu][Ee]|1|[Yy][Ee][Ss]|[Oo][Nn])\\s*$"
                }
              ]
            }
          },
          "fiat": {
            "type": "string",
            "minLength": 1
          }
        }
      },
      "else": {
        "allOf": [
          {
            "required": [
              "asset"
            ],
            "properties": {
              "asset": {
                "not": {
                  "type": "null"
                }
              }
            }
          },
          {
            "if": {
              "required": [
                "open_amount"
              ],
              "properties": {
                "open_amount": {
                  "oneOf": [
                    {
                      "const": true
                    },
                    {
                      "const": 1
                    },
                    {
                      "type": "string",
                      "pattern": "^\\s*(?:[Tt][Rr][Uu][Ee]|1|[Yy][Ee][Ss]|[Oo][Nn])\\s*$"
                    }
                  ]
                }
              }
            },
            "then": {
              "properties": {
                "amount": {
                  "type": "null"
                }
              }
            },
            "else": {
              "required": [
                "amount"
              ],
              "properties": {
                "amount": {
                  "not": {
                    "type": "null"
                  }
                }
              }
            }
          }
        ],
        "properties": {
          "asset": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    }
  ],
  "$defs": {
    "AmountInput": {
      "type": "string",
      "minLength": 1,
      "maxLength": 40,
      "description": "Positive amount as a decimal string (not a JSON number). Surrounding whitespace and exponent notation are accepted. Crypto rounds to asset precision, midpoint away from zero, and must remain positive; fiat requires exact positive cents. Values must fit the server decimal parser and scaling arithmetic.",
      "pattern": "^\\s*\\+?(?=[0-9.]*[1-9])(?:[0-9]+(?:\\.[0-9]*)?|\\.[0-9]+)(?:[eE][+-]?[0-9]+)?\\s*$"
    },
    "BooleanInput": {
      "oneOf": [
        {
          "type": "boolean"
        },
        {
          "type": "integer",
          "enum": [
            0,
            1
          ]
        },
        {
          "type": "string",
          "pattern": "^\\s*(?:[Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee]|[01]|[Yy][Ee][Ss]|[Nn][Oo]|[Oo][Nn]|[Oo][Ff][Ff])\\s*$"
        }
      ]
    },
    "CustomerInput": {
      "type": "object",
      "description": "The seller's own record of the buyer, echoed in the invoice and its webhooks; the payer does not see it. Only these four keys; each value is a scalar whose text form is 1–256 characters (null values are rejected). An empty object means none.",
      "properties": {
        "id": {
          "type": [
            "string",
            "number",
            "boolean"
          ],
          "minLength": 1,
          "maxLength": 256
        },
        "email": {
          "type": [
            "string",
            "number",
            "boolean"
          ],
          "minLength": 1,
          "maxLength": 256
        },
        "telegram_id": {
          "type": [
            "string",
            "number",
            "boolean"
          ],
          "minLength": 1,
          "maxLength": 256
        },
        "telegram_username": {
          "type": [
            "string",
            "number",
            "boolean"
          ],
          "minLength": 1,
          "maxLength": 256
        }
      },
      "additionalProperties": false
    },
    "OperationWebhookUrl": {
      "type": "string",
      "maxLength": 256,
      "description": "This operation's own webhook address — an absolute public HTTPS URL, no embedded credentials, surrounding spaces trimmed. Every update of the operation goes here instead of the app's webhook URL, regardless of the app's event selection. An empty string means the app's URL. Not returned in objects. With a spend_id it is part of the compared request."
    },
    "ReturnUrl": {
      "type": "string",
      "maxLength": 512,
      "description": "An absolute http:// or https:// URL; surrounding spaces trimmed, an empty string means none."
    }
  }
}