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