crypto_pay_api/models/invoice/mod.rs
1mod params;
2
3use chrono::{DateTime, Utc};
4pub use params::*;
5use rust_decimal::Decimal;
6use serde::{Deserialize, Serialize};
7
8use super::{CryptoCurrencyCode, CurrencyType, FiatCurrencyCode, PayButtonName};
9use crate::utils::{deserialize_decimal, deserialize_optional_decimal_from_string};
10
11#[derive(Debug, Deserialize, Clone)]
12pub struct Invoice {
13 /// Unique ID for this invoice.
14 pub invoice_id: u64,
15
16 /// Hash of the invoice.
17 pub hash: String,
18
19 /// Type of the price, can be "crypto" or "fiat".
20 pub currency_type: CurrencyType,
21
22 /// Optional. Cryptocurrency code. Available only if the value of the field currency_type is "crypto". Currently, can be "USDT", "TON", "BTC", "ETH", "LTC", "BNB", "TRX" and "USDC" (and "JET" for testnet).
23 pub asset: Option<CryptoCurrencyCode>,
24
25 /// Optional. Fiat currency code. Available only if the value of the field currency_type is "fiat". Currently one of "USD", "EUR", "RUB", "BYN", "UAH", "GBP", "CNY", "KZT", "UZS", "GEL", "TRY", "AMD", "THB", "INR", "BRL", "IDR", "AZN", "AED", "PLN" and "ILS".
26 pub fiat: Option<FiatCurrencyCode>,
27
28 /// Amount of the invoice for which the invoice was created.
29 #[serde(deserialize_with = "deserialize_decimal")]
30 pub amount: Decimal,
31
32 /// Optional. Cryptocurrency alphabetic code for which the invoice was paid. Available only if currency_type is "crypto" and status is "paid".
33 pub paid_asset: Option<CryptoCurrencyCode>,
34
35 /// Optional. Amount of the invoice for which the invoice was paid. Available only if currency_type is "fiat" and status is "paid".
36 #[serde(default)]
37 #[serde(deserialize_with = "deserialize_optional_decimal_from_string")]
38 pub paid_amount: Option<Decimal>,
39
40 /// Optional. The rate of the paid_asset valued in the fiat currency. Available only if the value of the field currency_type is "fiat" and the value of the field status is "paid".
41 #[serde(default)]
42 #[serde(deserialize_with = "deserialize_optional_decimal_from_string")]
43 pub paid_fiat_rate: Option<Decimal>,
44
45 /// Optional. List of assets which can be used to pay the invoice. Available only if currency_type is "fiat". Currently, can be "USDT", "TON", "BTC", "ETH", "LTC", "BNB", "TRX" and "USDC" ("JET" for testnet).
46 pub accept_asset: Option<Vec<CryptoCurrencyCode>>,
47
48 /// Optional. Asset of service fees charged when the invoice was paid. Available only if status is "paid".
49 pub fee_asset: Option<String>,
50
51 /// Optional. Amount of service fees charged when the invoice was paid. Available only if status is "paid".
52 #[serde(default)]
53 #[serde(deserialize_with = "deserialize_optional_decimal_from_string")]
54 pub fee_amount: Option<Decimal>,
55
56 /// URL should be provided to the user to pay the invoice.
57 pub bot_invoice_url: String,
58
59 /// Use this URL to pay an invoice to the Telegram Mini App version.
60 pub mini_app_invoice_url: String,
61
62 /// Use this URL to pay an invoice to the Web version of Crypto Bot.
63 pub web_app_invoice_url: String,
64
65 /// Optional. Description for this invoice.
66 pub description: Option<String>,
67
68 /// Status of the transfer, can be "active", "paid" or "expired".
69 pub status: InvoiceStatus,
70
71 /// Optional. The asset that will be attempted to be swapped into after the user makes a payment (the swap is not guaranteed). Supported assets: "USDT", "TON", "TRX", "ETH", "SOL", "BTC", "LTC".
72 pub swap_to: Option<SwapToAssets>,
73
74 /// Optional. For invoices with the "paid" status, this flag indicates whether the swap was successful (only applicable if swap_to is set).
75 pub is_swapped: Option<String>,
76
77 /// Optional. If is_swapped is true, stores the unique identifier of the swap.
78 pub swapped_uid: Option<String>,
79
80 /// Optional. If is_swapped is true, stores the asset into which the swap was made.
81 pub swapped_to: Option<SwapToAssets>,
82
83 /// Optional. If is_swapped is true, stores the exchange rate at which the swap was executed.
84 pub swapped_rate: Option<Decimal>,
85
86 /// Optional. If is_swapped is true, stores the amount received as a result of the swap (in the swapped_to asset).
87 pub swapped_output: Option<Decimal>,
88
89 /// Optional. If is_swapped is true, stores the resulting swap amount in USD.
90 pub swapped_usd_amount: Option<Decimal>,
91
92 /// Optional. If is_swapped is true, stores the USD exchange rate of the currency from swapped_to.
93 pub swapped_usd_rate: Option<Decimal>,
94
95 /// Date the invoice was created in ISO 8601 format.
96 pub created_at: DateTime<Utc>,
97
98 /// Optional. Price of the asset in USD. Available only if status is "paid".
99 #[serde(default)]
100 #[serde(deserialize_with = "deserialize_optional_decimal_from_string")]
101 pub paid_usd_rate: Option<Decimal>,
102
103 /// True, if the user can add comment to the payment.
104 pub allow_comments: bool,
105
106 /// True, if the user can pay the invoice anonymously.
107 pub allow_anonymous: bool,
108
109 /// Optional. Date the invoice expires in ISO 8601 format.
110 pub expires_date: Option<DateTime<Utc>>,
111
112 /// Optional. Date the invoice was paid in ISO 8601 format.
113 pub paid_at: Option<DateTime<Utc>>,
114
115 /// True, if the invoice was paid anonymously.
116 pub paid_anonymously: Option<bool>,
117
118 /// Optional. Comment to the payment from the user.
119 pub comment: Option<String>,
120
121 /// Optional. Text of the hidden message for this invoice.
122 pub hidden_message: Option<String>,
123
124 /// Optional. Previously provided data for this invoice.
125 pub payload: Option<String>,
126
127 /// Optional. Label of the button, can be "viewItem", "openChannel", "openBot" or "callback".
128 pub paid_btn_name: Option<PayButtonName>,
129
130 /// Optional. URL opened using the button.
131 pub paid_btn_url: Option<String>,
132}
133
134#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone)]
135#[serde(rename_all = "lowercase")]
136pub enum InvoiceStatus {
137 Active,
138 Paid,
139 Expired,
140}
141
142#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone)]
143#[serde(rename_all = "UPPERCASE")]
144pub enum SwapToAssets {
145 Usdt,
146 Ton,
147 Trx,
148 Eth,
149 Sol,
150 Btc,
151 Ltc,
152}