telers/types/pre_checkout_query.rs
1use serde::{Deserialize, Serialize};
2/// This object contains information about an incoming pre-checkout query.
3/// # Documentation
4/// <https://core.telegram.org/bots/api#precheckoutquery>
5#[derive(Clone, Debug, Serialize, Deserialize)]
6pub struct PreCheckoutQuery {
7 /// Unique query identifier
8 pub id: Box<str>,
9 /// User who sent the query
10 pub from: Box<crate::types::User>,
11 /// Three-letter ISO 4217 currency code, or `XTR` for payments in Telegram Stars
12 pub currency: Box<str>,
13 /// Total price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies).
14 pub total_amount: i64,
15 /// Bot-specified invoice payload
16 pub invoice_payload: Box<str>,
17 /// Identifier of the shipping option chosen by the user
18 #[serde(skip_serializing_if = "Option::is_none")]
19 pub shipping_option_id: Option<Box<str>>,
20 /// Order information provided by the user
21 #[serde(skip_serializing_if = "Option::is_none")]
22 pub order_info: Option<crate::types::OrderInfo>,
23}
24impl PreCheckoutQuery {
25 /// Creates a new `PreCheckoutQuery`.
26 ///
27 /// # Arguments
28 /// * `id` - Unique query identifier
29 /// * `from` - User who sent the query
30 /// * `currency` - Three-letter ISO 4217 currency code, or `XTR` for payments in Telegram Stars
31 /// * `total_amount` - Total price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies).
32 /// * `invoice_payload` - Bot-specified invoice payload
33 ///
34 /// # Notes
35 /// Use builder methods to set optional fields.
36 #[must_use]
37 pub fn new<
38 T0: Into<Box<str>>,
39 T1: Into<crate::types::User>,
40 T2: Into<Box<str>>,
41 T3: Into<i64>,
42 T4: Into<Box<str>>,
43 >(
44 id: T0,
45 from: T1,
46 currency: T2,
47 total_amount: T3,
48 invoice_payload: T4,
49 ) -> Self {
50 Self {
51 id: id.into(),
52 from: Box::new(from.into()),
53 currency: currency.into(),
54 total_amount: total_amount.into(),
55 invoice_payload: invoice_payload.into(),
56 shipping_option_id: None,
57 order_info: None,
58 }
59 }
60
61 /// Unique query identifier
62 #[must_use]
63 pub fn id<T: Into<Box<str>>>(self, val: T) -> Self {
64 let mut this = self;
65 this.id = val.into();
66 this
67 }
68
69 /// User who sent the query
70 #[must_use]
71 pub fn from<T: Into<crate::types::User>>(self, val: T) -> Self {
72 let mut this = self;
73 this.from = Box::new(val.into());
74 this
75 }
76
77 /// Three-letter ISO 4217 currency code, or `XTR` for payments in Telegram Stars
78 #[must_use]
79 pub fn currency<T: Into<Box<str>>>(self, val: T) -> Self {
80 let mut this = self;
81 this.currency = val.into();
82 this
83 }
84
85 /// Total price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies).
86 #[must_use]
87 pub fn total_amount<T: Into<i64>>(self, val: T) -> Self {
88 let mut this = self;
89 this.total_amount = val.into();
90 this
91 }
92
93 /// Bot-specified invoice payload
94 #[must_use]
95 pub fn invoice_payload<T: Into<Box<str>>>(self, val: T) -> Self {
96 let mut this = self;
97 this.invoice_payload = val.into();
98 this
99 }
100
101 /// Identifier of the shipping option chosen by the user
102 #[must_use]
103 pub fn shipping_option_id<T: Into<Box<str>>>(self, val: T) -> Self {
104 let mut this = self;
105 this.shipping_option_id = Some(val.into());
106 this
107 }
108
109 /// Identifier of the shipping option chosen by the user
110 #[must_use]
111 pub fn shipping_option_id_option<T: Into<Box<str>>>(self, val: Option<T>) -> Self {
112 let mut this = self;
113 this.shipping_option_id = val.map(Into::into);
114 this
115 }
116
117 /// Order information provided by the user
118 #[must_use]
119 pub fn order_info<T: Into<crate::types::OrderInfo>>(self, val: T) -> Self {
120 let mut this = self;
121 this.order_info = Some(val.into());
122 this
123 }
124
125 /// Order information provided by the user
126 #[must_use]
127 pub fn order_info_option<T: Into<crate::types::OrderInfo>>(self, val: Option<T>) -> Self {
128 let mut this = self;
129 this.order_info = val.map(Into::into);
130 this
131 }
132}