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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
use crate::errors::Result;
use crate::types::*;
use uuid::Uuid;

use std::fmt::Debug;

/// Contains information about the payment method chosen by the user
pub trait TDInputCredentials: Debug + RObject {}

/// Contains information about the payment method chosen by the user
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(tag = "@type")]
pub enum InputCredentials {
    #[doc(hidden)]
    _Default,
    /// Applies if a user enters new credentials using Apple Pay
    #[serde(rename(deserialize = "inputCredentialsApplePay"))]
    ApplePay(InputCredentialsApplePay),
    /// Applies if a user enters new credentials using Google Pay
    #[serde(rename(deserialize = "inputCredentialsGooglePay"))]
    GooglePay(InputCredentialsGooglePay),
    /// Applies if a user enters new credentials on a payment provider website
    #[serde(rename(deserialize = "inputCredentialsNew"))]
    New(InputCredentialsNew),
    /// Applies if a user chooses some previously saved payment credentials. To use their previously saved credentials, the user must have a valid temporary password
    #[serde(rename(deserialize = "inputCredentialsSaved"))]
    Saved(InputCredentialsSaved),
}

impl Default for InputCredentials {
    fn default() -> Self {
        InputCredentials::_Default
    }
}

impl RObject for InputCredentials {
    #[doc(hidden)]
    fn extra(&self) -> Option<&str> {
        match self {
            InputCredentials::ApplePay(t) => t.extra(),
            InputCredentials::GooglePay(t) => t.extra(),
            InputCredentials::New(t) => t.extra(),
            InputCredentials::Saved(t) => t.extra(),

            _ => None,
        }
    }
    #[doc(hidden)]
    fn client_id(&self) -> Option<i32> {
        match self {
            InputCredentials::ApplePay(t) => t.client_id(),
            InputCredentials::GooglePay(t) => t.client_id(),
            InputCredentials::New(t) => t.client_id(),
            InputCredentials::Saved(t) => t.client_id(),

            _ => None,
        }
    }
}

impl InputCredentials {
    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
        Ok(serde_json::from_str(json.as_ref())?)
    }
    #[doc(hidden)]
    pub fn _is_default(&self) -> bool {
        matches!(self, InputCredentials::_Default)
    }
}

impl AsRef<InputCredentials> for InputCredentials {
    fn as_ref(&self) -> &InputCredentials {
        self
    }
}

/// Applies if a user enters new credentials using Apple Pay
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct InputCredentialsApplePay {
    #[doc(hidden)]
    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
    extra: Option<String>,
    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
    client_id: Option<i32>,
    /// JSON-encoded data with the credential identifier

    #[serde(default)]
    data: String,
}

impl RObject for InputCredentialsApplePay {
    #[doc(hidden)]
    fn extra(&self) -> Option<&str> {
        self.extra.as_deref()
    }
    #[doc(hidden)]
    fn client_id(&self) -> Option<i32> {
        self.client_id
    }
}

impl TDInputCredentials for InputCredentialsApplePay {}

impl InputCredentialsApplePay {
    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
        Ok(serde_json::from_str(json.as_ref())?)
    }
    pub fn builder() -> InputCredentialsApplePayBuilder {
        let mut inner = InputCredentialsApplePay::default();
        inner.extra = Some(Uuid::new_v4().to_string());

        InputCredentialsApplePayBuilder { inner }
    }

    pub fn data(&self) -> &String {
        &self.data
    }
}

#[doc(hidden)]
pub struct InputCredentialsApplePayBuilder {
    inner: InputCredentialsApplePay,
}

#[deprecated]
pub type RTDInputCredentialsApplePayBuilder = InputCredentialsApplePayBuilder;

impl InputCredentialsApplePayBuilder {
    pub fn build(&self) -> InputCredentialsApplePay {
        self.inner.clone()
    }

    pub fn data<T: AsRef<str>>(&mut self, data: T) -> &mut Self {
        self.inner.data = data.as_ref().to_string();
        self
    }
}

impl AsRef<InputCredentialsApplePay> for InputCredentialsApplePay {
    fn as_ref(&self) -> &InputCredentialsApplePay {
        self
    }
}

impl AsRef<InputCredentialsApplePay> for InputCredentialsApplePayBuilder {
    fn as_ref(&self) -> &InputCredentialsApplePay {
        &self.inner
    }
}

/// Applies if a user enters new credentials using Google Pay
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct InputCredentialsGooglePay {
    #[doc(hidden)]
    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
    extra: Option<String>,
    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
    client_id: Option<i32>,
    /// JSON-encoded data with the credential identifier

    #[serde(default)]
    data: String,
}

impl RObject for InputCredentialsGooglePay {
    #[doc(hidden)]
    fn extra(&self) -> Option<&str> {
        self.extra.as_deref()
    }
    #[doc(hidden)]
    fn client_id(&self) -> Option<i32> {
        self.client_id
    }
}

impl TDInputCredentials for InputCredentialsGooglePay {}

impl InputCredentialsGooglePay {
    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
        Ok(serde_json::from_str(json.as_ref())?)
    }
    pub fn builder() -> InputCredentialsGooglePayBuilder {
        let mut inner = InputCredentialsGooglePay::default();
        inner.extra = Some(Uuid::new_v4().to_string());

        InputCredentialsGooglePayBuilder { inner }
    }

    pub fn data(&self) -> &String {
        &self.data
    }
}

#[doc(hidden)]
pub struct InputCredentialsGooglePayBuilder {
    inner: InputCredentialsGooglePay,
}

#[deprecated]
pub type RTDInputCredentialsGooglePayBuilder = InputCredentialsGooglePayBuilder;

impl InputCredentialsGooglePayBuilder {
    pub fn build(&self) -> InputCredentialsGooglePay {
        self.inner.clone()
    }

    pub fn data<T: AsRef<str>>(&mut self, data: T) -> &mut Self {
        self.inner.data = data.as_ref().to_string();
        self
    }
}

impl AsRef<InputCredentialsGooglePay> for InputCredentialsGooglePay {
    fn as_ref(&self) -> &InputCredentialsGooglePay {
        self
    }
}

impl AsRef<InputCredentialsGooglePay> for InputCredentialsGooglePayBuilder {
    fn as_ref(&self) -> &InputCredentialsGooglePay {
        &self.inner
    }
}

/// Applies if a user enters new credentials on a payment provider website
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct InputCredentialsNew {
    #[doc(hidden)]
    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
    extra: Option<String>,
    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
    client_id: Option<i32>,
    /// JSON-encoded data with the credential identifier from the payment provider

    #[serde(default)]
    data: String,
    /// True, if the credential identifier can be saved on the server side

    #[serde(default)]
    allow_save: bool,
}

impl RObject for InputCredentialsNew {
    #[doc(hidden)]
    fn extra(&self) -> Option<&str> {
        self.extra.as_deref()
    }
    #[doc(hidden)]
    fn client_id(&self) -> Option<i32> {
        self.client_id
    }
}

impl TDInputCredentials for InputCredentialsNew {}

impl InputCredentialsNew {
    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
        Ok(serde_json::from_str(json.as_ref())?)
    }
    pub fn builder() -> InputCredentialsNewBuilder {
        let mut inner = InputCredentialsNew::default();
        inner.extra = Some(Uuid::new_v4().to_string());

        InputCredentialsNewBuilder { inner }
    }

    pub fn data(&self) -> &String {
        &self.data
    }

    pub fn allow_save(&self) -> bool {
        self.allow_save
    }
}

#[doc(hidden)]
pub struct InputCredentialsNewBuilder {
    inner: InputCredentialsNew,
}

#[deprecated]
pub type RTDInputCredentialsNewBuilder = InputCredentialsNewBuilder;

impl InputCredentialsNewBuilder {
    pub fn build(&self) -> InputCredentialsNew {
        self.inner.clone()
    }

    pub fn data<T: AsRef<str>>(&mut self, data: T) -> &mut Self {
        self.inner.data = data.as_ref().to_string();
        self
    }

    pub fn allow_save(&mut self, allow_save: bool) -> &mut Self {
        self.inner.allow_save = allow_save;
        self
    }
}

impl AsRef<InputCredentialsNew> for InputCredentialsNew {
    fn as_ref(&self) -> &InputCredentialsNew {
        self
    }
}

impl AsRef<InputCredentialsNew> for InputCredentialsNewBuilder {
    fn as_ref(&self) -> &InputCredentialsNew {
        &self.inner
    }
}

/// Applies if a user chooses some previously saved payment credentials. To use their previously saved credentials, the user must have a valid temporary password
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct InputCredentialsSaved {
    #[doc(hidden)]
    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
    extra: Option<String>,
    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
    client_id: Option<i32>,
    /// Identifier of the saved credentials

    #[serde(default)]
    saved_credentials_id: String,
}

impl RObject for InputCredentialsSaved {
    #[doc(hidden)]
    fn extra(&self) -> Option<&str> {
        self.extra.as_deref()
    }
    #[doc(hidden)]
    fn client_id(&self) -> Option<i32> {
        self.client_id
    }
}

impl TDInputCredentials for InputCredentialsSaved {}

impl InputCredentialsSaved {
    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
        Ok(serde_json::from_str(json.as_ref())?)
    }
    pub fn builder() -> InputCredentialsSavedBuilder {
        let mut inner = InputCredentialsSaved::default();
        inner.extra = Some(Uuid::new_v4().to_string());

        InputCredentialsSavedBuilder { inner }
    }

    pub fn saved_credentials_id(&self) -> &String {
        &self.saved_credentials_id
    }
}

#[doc(hidden)]
pub struct InputCredentialsSavedBuilder {
    inner: InputCredentialsSaved,
}

#[deprecated]
pub type RTDInputCredentialsSavedBuilder = InputCredentialsSavedBuilder;

impl InputCredentialsSavedBuilder {
    pub fn build(&self) -> InputCredentialsSaved {
        self.inner.clone()
    }

    pub fn saved_credentials_id<T: AsRef<str>>(&mut self, saved_credentials_id: T) -> &mut Self {
        self.inner.saved_credentials_id = saved_credentials_id.as_ref().to_string();
        self
    }
}

impl AsRef<InputCredentialsSaved> for InputCredentialsSaved {
    fn as_ref(&self) -> &InputCredentialsSaved {
        self
    }
}

impl AsRef<InputCredentialsSaved> for InputCredentialsSavedBuilder {
    fn as_ref(&self) -> &InputCredentialsSaved {
        &self.inner
    }
}