rust_tdlib/types/
input_credentials.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5use std::fmt::Debug;
6
7/// Contains information about the payment method chosen by the user
8pub trait TDInputCredentials: Debug + RObject {}
9
10/// Contains information about the payment method chosen by the user
11#[derive(Debug, Clone, Deserialize, Serialize, Default)]
12#[serde(tag = "@type")]
13pub enum InputCredentials {
14    #[doc(hidden)]
15    #[default]
16    _Default,
17    /// Applies if a user enters new credentials using Apple Pay
18    #[serde(rename = "inputCredentialsApplePay")]
19    ApplePay(InputCredentialsApplePay),
20    /// Applies if a user enters new credentials using Google Pay
21    #[serde(rename = "inputCredentialsGooglePay")]
22    GooglePay(InputCredentialsGooglePay),
23    /// Applies if a user enters new credentials on a payment provider website
24    #[serde(rename = "inputCredentialsNew")]
25    New(InputCredentialsNew),
26    /// Applies if a user chooses some previously saved payment credentials. To use their previously saved credentials, the user must have a valid temporary password
27    #[serde(rename = "inputCredentialsSaved")]
28    Saved(InputCredentialsSaved),
29}
30
31impl RObject for InputCredentials {
32    #[doc(hidden)]
33    fn extra(&self) -> Option<&str> {
34        match self {
35            InputCredentials::ApplePay(t) => t.extra(),
36            InputCredentials::GooglePay(t) => t.extra(),
37            InputCredentials::New(t) => t.extra(),
38            InputCredentials::Saved(t) => t.extra(),
39
40            _ => None,
41        }
42    }
43    #[doc(hidden)]
44    fn client_id(&self) -> Option<i32> {
45        match self {
46            InputCredentials::ApplePay(t) => t.client_id(),
47            InputCredentials::GooglePay(t) => t.client_id(),
48            InputCredentials::New(t) => t.client_id(),
49            InputCredentials::Saved(t) => t.client_id(),
50
51            _ => None,
52        }
53    }
54}
55
56impl InputCredentials {
57    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
58        Ok(serde_json::from_str(json.as_ref())?)
59    }
60    #[doc(hidden)]
61    pub fn _is_default(&self) -> bool {
62        matches!(self, InputCredentials::_Default)
63    }
64}
65
66impl AsRef<InputCredentials> for InputCredentials {
67    fn as_ref(&self) -> &InputCredentials {
68        self
69    }
70}
71
72/// Applies if a user enters new credentials using Apple Pay
73#[derive(Debug, Clone, Default, Serialize, Deserialize)]
74pub struct InputCredentialsApplePay {
75    #[doc(hidden)]
76    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
77    extra: Option<String>,
78    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
79    client_id: Option<i32>,
80    /// JSON-encoded data with the credential identifier
81
82    #[serde(default)]
83    data: String,
84}
85
86impl RObject for InputCredentialsApplePay {
87    #[doc(hidden)]
88    fn extra(&self) -> Option<&str> {
89        self.extra.as_deref()
90    }
91    #[doc(hidden)]
92    fn client_id(&self) -> Option<i32> {
93        self.client_id
94    }
95}
96
97impl TDInputCredentials for InputCredentialsApplePay {}
98
99impl InputCredentialsApplePay {
100    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
101        Ok(serde_json::from_str(json.as_ref())?)
102    }
103    pub fn builder() -> InputCredentialsApplePayBuilder {
104        let mut inner = InputCredentialsApplePay::default();
105        inner.extra = Some(Uuid::new_v4().to_string());
106
107        InputCredentialsApplePayBuilder { inner }
108    }
109
110    pub fn data(&self) -> &String {
111        &self.data
112    }
113}
114
115#[doc(hidden)]
116pub struct InputCredentialsApplePayBuilder {
117    inner: InputCredentialsApplePay,
118}
119
120#[deprecated]
121pub type RTDInputCredentialsApplePayBuilder = InputCredentialsApplePayBuilder;
122
123impl InputCredentialsApplePayBuilder {
124    pub fn build(&self) -> InputCredentialsApplePay {
125        self.inner.clone()
126    }
127
128    pub fn data<T: AsRef<str>>(&mut self, data: T) -> &mut Self {
129        self.inner.data = data.as_ref().to_string();
130        self
131    }
132}
133
134impl AsRef<InputCredentialsApplePay> for InputCredentialsApplePay {
135    fn as_ref(&self) -> &InputCredentialsApplePay {
136        self
137    }
138}
139
140impl AsRef<InputCredentialsApplePay> for InputCredentialsApplePayBuilder {
141    fn as_ref(&self) -> &InputCredentialsApplePay {
142        &self.inner
143    }
144}
145
146/// Applies if a user enters new credentials using Google Pay
147#[derive(Debug, Clone, Default, Serialize, Deserialize)]
148pub struct InputCredentialsGooglePay {
149    #[doc(hidden)]
150    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
151    extra: Option<String>,
152    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
153    client_id: Option<i32>,
154    /// JSON-encoded data with the credential identifier
155
156    #[serde(default)]
157    data: String,
158}
159
160impl RObject for InputCredentialsGooglePay {
161    #[doc(hidden)]
162    fn extra(&self) -> Option<&str> {
163        self.extra.as_deref()
164    }
165    #[doc(hidden)]
166    fn client_id(&self) -> Option<i32> {
167        self.client_id
168    }
169}
170
171impl TDInputCredentials for InputCredentialsGooglePay {}
172
173impl InputCredentialsGooglePay {
174    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
175        Ok(serde_json::from_str(json.as_ref())?)
176    }
177    pub fn builder() -> InputCredentialsGooglePayBuilder {
178        let mut inner = InputCredentialsGooglePay::default();
179        inner.extra = Some(Uuid::new_v4().to_string());
180
181        InputCredentialsGooglePayBuilder { inner }
182    }
183
184    pub fn data(&self) -> &String {
185        &self.data
186    }
187}
188
189#[doc(hidden)]
190pub struct InputCredentialsGooglePayBuilder {
191    inner: InputCredentialsGooglePay,
192}
193
194#[deprecated]
195pub type RTDInputCredentialsGooglePayBuilder = InputCredentialsGooglePayBuilder;
196
197impl InputCredentialsGooglePayBuilder {
198    pub fn build(&self) -> InputCredentialsGooglePay {
199        self.inner.clone()
200    }
201
202    pub fn data<T: AsRef<str>>(&mut self, data: T) -> &mut Self {
203        self.inner.data = data.as_ref().to_string();
204        self
205    }
206}
207
208impl AsRef<InputCredentialsGooglePay> for InputCredentialsGooglePay {
209    fn as_ref(&self) -> &InputCredentialsGooglePay {
210        self
211    }
212}
213
214impl AsRef<InputCredentialsGooglePay> for InputCredentialsGooglePayBuilder {
215    fn as_ref(&self) -> &InputCredentialsGooglePay {
216        &self.inner
217    }
218}
219
220/// Applies if a user enters new credentials on a payment provider website
221#[derive(Debug, Clone, Default, Serialize, Deserialize)]
222pub struct InputCredentialsNew {
223    #[doc(hidden)]
224    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
225    extra: Option<String>,
226    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
227    client_id: Option<i32>,
228    /// JSON-encoded data with the credential identifier from the payment provider
229
230    #[serde(default)]
231    data: String,
232    /// True, if the credential identifier can be saved on the server side
233
234    #[serde(default)]
235    allow_save: bool,
236}
237
238impl RObject for InputCredentialsNew {
239    #[doc(hidden)]
240    fn extra(&self) -> Option<&str> {
241        self.extra.as_deref()
242    }
243    #[doc(hidden)]
244    fn client_id(&self) -> Option<i32> {
245        self.client_id
246    }
247}
248
249impl TDInputCredentials for InputCredentialsNew {}
250
251impl InputCredentialsNew {
252    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
253        Ok(serde_json::from_str(json.as_ref())?)
254    }
255    pub fn builder() -> InputCredentialsNewBuilder {
256        let mut inner = InputCredentialsNew::default();
257        inner.extra = Some(Uuid::new_v4().to_string());
258
259        InputCredentialsNewBuilder { inner }
260    }
261
262    pub fn data(&self) -> &String {
263        &self.data
264    }
265
266    pub fn allow_save(&self) -> bool {
267        self.allow_save
268    }
269}
270
271#[doc(hidden)]
272pub struct InputCredentialsNewBuilder {
273    inner: InputCredentialsNew,
274}
275
276#[deprecated]
277pub type RTDInputCredentialsNewBuilder = InputCredentialsNewBuilder;
278
279impl InputCredentialsNewBuilder {
280    pub fn build(&self) -> InputCredentialsNew {
281        self.inner.clone()
282    }
283
284    pub fn data<T: AsRef<str>>(&mut self, data: T) -> &mut Self {
285        self.inner.data = data.as_ref().to_string();
286        self
287    }
288
289    pub fn allow_save(&mut self, allow_save: bool) -> &mut Self {
290        self.inner.allow_save = allow_save;
291        self
292    }
293}
294
295impl AsRef<InputCredentialsNew> for InputCredentialsNew {
296    fn as_ref(&self) -> &InputCredentialsNew {
297        self
298    }
299}
300
301impl AsRef<InputCredentialsNew> for InputCredentialsNewBuilder {
302    fn as_ref(&self) -> &InputCredentialsNew {
303        &self.inner
304    }
305}
306
307/// Applies if a user chooses some previously saved payment credentials. To use their previously saved credentials, the user must have a valid temporary password
308#[derive(Debug, Clone, Default, Serialize, Deserialize)]
309pub struct InputCredentialsSaved {
310    #[doc(hidden)]
311    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
312    extra: Option<String>,
313    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
314    client_id: Option<i32>,
315    /// Identifier of the saved credentials
316
317    #[serde(default)]
318    saved_credentials_id: String,
319}
320
321impl RObject for InputCredentialsSaved {
322    #[doc(hidden)]
323    fn extra(&self) -> Option<&str> {
324        self.extra.as_deref()
325    }
326    #[doc(hidden)]
327    fn client_id(&self) -> Option<i32> {
328        self.client_id
329    }
330}
331
332impl TDInputCredentials for InputCredentialsSaved {}
333
334impl InputCredentialsSaved {
335    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
336        Ok(serde_json::from_str(json.as_ref())?)
337    }
338    pub fn builder() -> InputCredentialsSavedBuilder {
339        let mut inner = InputCredentialsSaved::default();
340        inner.extra = Some(Uuid::new_v4().to_string());
341
342        InputCredentialsSavedBuilder { inner }
343    }
344
345    pub fn saved_credentials_id(&self) -> &String {
346        &self.saved_credentials_id
347    }
348}
349
350#[doc(hidden)]
351pub struct InputCredentialsSavedBuilder {
352    inner: InputCredentialsSaved,
353}
354
355#[deprecated]
356pub type RTDInputCredentialsSavedBuilder = InputCredentialsSavedBuilder;
357
358impl InputCredentialsSavedBuilder {
359    pub fn build(&self) -> InputCredentialsSaved {
360        self.inner.clone()
361    }
362
363    pub fn saved_credentials_id<T: AsRef<str>>(&mut self, saved_credentials_id: T) -> &mut Self {
364        self.inner.saved_credentials_id = saved_credentials_id.as_ref().to_string();
365        self
366    }
367}
368
369impl AsRef<InputCredentialsSaved> for InputCredentialsSaved {
370    fn as_ref(&self) -> &InputCredentialsSaved {
371        self
372    }
373}
374
375impl AsRef<InputCredentialsSaved> for InputCredentialsSavedBuilder {
376    fn as_ref(&self) -> &InputCredentialsSaved {
377        &self.inner
378    }
379}