crypto_pay_api/models/invoice/params.rs
1use rust_decimal::Decimal;
2use serde::Serialize;
3
4use crate::{
5 models::{CryptoCurrencyCode, CurrencyType, FiatCurrencyCode, PayButtonName, SwapToAssets},
6 utils::{serialize_comma_separated_list, serialize_decimal_to_string},
7};
8
9use super::InvoiceStatus;
10
11/* #region GetInvoicesParams */
12#[derive(Debug, Default, Serialize)]
13pub struct GetInvoicesParams {
14 /// Optional. Cryptocurrency alphabetic code. Supported assets: “USDT”, “TON”, “BTC”, “ETH”, “LTC”, “BNB”, “TRX” and “USDC” (and “JET” for testnet).
15 /// Defaults to all currencies.
16 #[serde(skip_serializing_if = "Option::is_none")]
17 pub(crate) asset: Option<CryptoCurrencyCode>,
18
19 /// Optional. Fiat currency code. Supported fiat currencies: “USD”, “EUR”, “RUB”, “BYN”, “UAH”, “GBP”, “CNY”, “KZT”, “UZS”, “GEL”, “TRY”, “AMD”, “THB”, “INR”, “BRL”, “IDR”, “AZN”, “AED”, “PLN” and “ILS".
20 /// Defaults to all currencies.
21 #[serde(skip_serializing_if = "Option::is_none")]
22 pub(crate) fiat: Option<FiatCurrencyCode>,
23
24 /// Optional. List of invoice IDs separated by comma.
25 #[serde(
26 serialize_with = "serialize_comma_separated_list",
27 skip_serializing_if = "GetInvoicesParams::should_skip_invoice_ids"
28 )]
29 pub(crate) invoice_ids: Option<Vec<u64>>,
30
31 /// Optional. Status of invoices to be returned. Available statuses: “active” and “paid”.
32 /// Defaults to all statuses.
33 #[serde(skip_serializing_if = "Option::is_none")]
34 pub(crate) status: Option<InvoiceStatus>,
35
36 /// Optional. Offset needed to return a specific subset of invoices.
37 /// Defaults to 0.
38 #[serde(skip_serializing_if = "Option::is_none")]
39 pub(crate) offset: Option<u32>,
40
41 /// Optional. Number of invoices to be returned. Values between 1-1000 are accepted.
42 /// Defaults to 100.
43 #[serde(skip_serializing_if = "Option::is_none")]
44 pub(crate) count: Option<u16>,
45}
46
47impl GetInvoicesParams {
48 fn should_skip_invoice_ids(ids: &Option<Vec<u64>>) -> bool {
49 !matches!(ids, Some(ids) if !ids.is_empty())
50 }
51}
52
53/* #endregion */
54
55/* #region CreateInvoiceParams */
56
57#[derive(Debug, Serialize)]
58pub struct CreateInvoiceParams {
59 /// Optional. Type of the price, can be "crypto" or "fiat". Defaults to crypto.
60 #[serde(skip_serializing_if = "Option::is_none")]
61 pub(crate) currency_type: Option<CurrencyType>,
62
63 /// Optional. Required if currency_type is "crypto". Cryptocurrency alphabetic code. Supported assets: "USDT", "TON", "BTC", "ETH", "LTC", "BNB", "TRX" and "USDC".
64 #[serde(skip_serializing_if = "Option::is_none")]
65 pub(crate) asset: Option<CryptoCurrencyCode>,
66
67 /// Optional. Required if currency_type is "fiat". Fiat currency code. Supported fiat currencies: "USD", "EUR", "RUB", "BYN", "UAH", "GBP", "CNY", "KZT", "UZS", "GEL", "TRY", "AMD", "THB", "INR", "BRL", "IDR", "AZN", "AED", "PLN" and "ILS".
68 #[serde(skip_serializing_if = "Option::is_none")]
69 pub(crate) fiat: Option<FiatCurrencyCode>,
70
71 /// Optional. List of cryptocurrency alphabetic codes separated comma. Assets which can be used to pay the invoice. Available only if currency_type is "crypto". Supported assets: "USDT", "TON", "BTC", "ETH", "LTC", "BNB", "TRX" and "USDC" ("JET" for testnet). Defaults to all currencies.
72 #[serde(skip_serializing_if = "Option::is_none")]
73 pub(crate) accept_asset: Option<Vec<CryptoCurrencyCode>>,
74
75 /// Amount of the invoice in float. For example: 125.50
76 #[serde(serialize_with = "serialize_decimal_to_string")]
77 pub(crate) amount: Decimal,
78
79 /// Optional. Description for the invoice. User will see this description when they pay the invoice. Up to 1024 characters.
80 #[serde(skip_serializing_if = "Option::is_none")]
81 pub(crate) description: Option<String>,
82
83 /// Optional. Text of the message which will be presented to a user after the invoice is paid. Up to 2048 characters.
84 #[serde(skip_serializing_if = "Option::is_none")]
85 pub(crate) hidden_message: Option<String>,
86
87 /// Optional. Label of the button which will be presented to a user after the invoice is paid.
88 /// Supported names:
89 /// viewItem – "View Item",
90 /// openChannel – "View Channel",
91 /// openBot – "Open Bot",
92 /// callback – "Return to the bot"
93 #[serde(skip_serializing_if = "Option::is_none")]
94 pub(crate) paid_btn_name: Option<PayButtonName>,
95
96 /// Optional. Required if paid_btn_name is specified. URL opened using the button which will be presented to a user after the invoice is paid.
97 /// You can set any callback link (for example, a success link or link to homepage).
98 /// Starts with https or http.
99 #[serde(skip_serializing_if = "Option::is_none")]
100 pub(crate) paid_btn_url: Option<String>,
101
102 /// Optional.
103 /// 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".
104 #[serde(skip_serializing_if = "Option::is_none")]
105 pub(crate) swap_to: Option<SwapToAssets>,
106
107 /// Optional. Any data you want to attach to the invoice (for example, user ID, payment ID, ect).
108 /// Up to 4kb.
109 #[serde(skip_serializing_if = "Option::is_none")]
110 pub(crate) payload: Option<String>,
111
112 /// Optional. Allow a user to add a comment to the payment.
113 /// Defaults to true.
114 #[serde(skip_serializing_if = "Option::is_none")]
115 pub(crate) allow_comments: Option<bool>,
116
117 /// Optional. Allow a user to pay the invoice anonymously.
118 /// Defaults to true.
119 #[serde(skip_serializing_if = "Option::is_none")]
120 pub(crate) allow_anonymous: Option<bool>,
121
122 /// Optional. You can set a payment time limit for the invoice in seconds.
123 /// Values between 1-2678400 are accepted.
124 #[serde(skip_serializing_if = "Option::is_none")]
125 pub(crate) expires_in: Option<u32>,
126}
127
128/* #endregion */
129
130/* #region DeleteInvoiceParams */
131
132#[derive(Debug, Serialize)]
133pub struct DeleteInvoiceParams {
134 pub(crate) invoice_id: u64,
135}