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