1use crate::client::{Client, Response};
6use crate::ids::MandateId;
7use crate::params::{Expand, Expandable, Object, Timestamp};
8use crate::resources::{Currency, PaymentMethod};
9use serde::{Deserialize, Serialize};
10
11#[derive(Clone, Debug, Default, Deserialize, Serialize)]
15pub struct Mandate {
16 pub id: MandateId,
18
19 pub customer_acceptance: CustomerAcceptance,
20
21 pub livemode: bool,
23
24 #[serde(skip_serializing_if = "Option::is_none")]
25 pub multi_use: Option<MandateMultiUse>,
26
27 #[serde(skip_serializing_if = "Option::is_none")]
29 pub on_behalf_of: Option<String>,
30
31 pub payment_method: Expandable<PaymentMethod>,
33
34 pub payment_method_details: MandatePaymentMethodDetails,
35
36 #[serde(skip_serializing_if = "Option::is_none")]
37 pub single_use: Option<MandateSingleUse>,
38
39 pub status: MandateStatus,
41
42 #[serde(rename = "type")]
44 pub type_: MandateType,
45}
46
47impl Mandate {
48 pub fn retrieve(client: &Client, id: &MandateId, expand: &[&str]) -> Response<Mandate> {
50 client.get_query(&format!("/mandates/{}", id), Expand { expand })
51 }
52}
53
54impl Object for Mandate {
55 type Id = MandateId;
56 fn id(&self) -> Self::Id {
57 self.id.clone()
58 }
59 fn object(&self) -> &'static str {
60 "mandate"
61 }
62}
63
64#[derive(Clone, Debug, Default, Deserialize, Serialize)]
65pub struct CustomerAcceptance {
66 pub accepted_at: Option<Timestamp>,
68
69 #[serde(skip_serializing_if = "Option::is_none")]
70 pub offline: Option<OfflineAcceptance>,
71
72 #[serde(skip_serializing_if = "Option::is_none")]
73 pub online: Option<OnlineAcceptance>,
74
75 #[serde(rename = "type")]
77 pub type_: CustomerAcceptanceType,
78}
79
80#[derive(Clone, Debug, Default, Deserialize, Serialize)]
81pub struct MandateMultiUse {}
82
83#[derive(Clone, Debug, Default, Deserialize, Serialize)]
84pub struct MandatePaymentMethodDetails {
85 #[serde(skip_serializing_if = "Option::is_none")]
86 pub acss_debit: Option<MandateAcssDebit>,
87
88 #[serde(skip_serializing_if = "Option::is_none")]
89 pub au_becs_debit: Option<MandateAuBecsDebit>,
90
91 #[serde(skip_serializing_if = "Option::is_none")]
92 pub bacs_debit: Option<MandateBacsDebit>,
93
94 #[serde(skip_serializing_if = "Option::is_none")]
95 pub card: Option<CardMandatePaymentMethodDetails>,
96
97 #[serde(skip_serializing_if = "Option::is_none")]
98 pub cashapp: Option<MandateCashapp>,
99
100 #[serde(skip_serializing_if = "Option::is_none")]
101 pub link: Option<MandateLink>,
102
103 #[serde(skip_serializing_if = "Option::is_none")]
104 pub paypal: Option<MandatePaypal>,
105
106 #[serde(skip_serializing_if = "Option::is_none")]
107 pub sepa_debit: Option<MandateSepaDebit>,
108
109 #[serde(rename = "type")]
113 pub type_: String,
114
115 #[serde(skip_serializing_if = "Option::is_none")]
116 pub us_bank_account: Option<MandateUsBankAccount>,
117}
118
119#[derive(Clone, Debug, Default, Deserialize, Serialize)]
120pub struct CardMandatePaymentMethodDetails {}
121
122#[derive(Clone, Debug, Default, Deserialize, Serialize)]
123pub struct MandateAcssDebit {
124 #[serde(skip_serializing_if = "Option::is_none")]
126 pub default_for: Option<Vec<MandateAcssDebitDefaultFor>>,
127
128 pub interval_description: Option<String>,
132
133 pub payment_schedule: MandateAcssDebitPaymentSchedule,
135
136 pub transaction_type: MandateAcssDebitTransactionType,
138}
139
140#[derive(Clone, Debug, Default, Deserialize, Serialize)]
141pub struct MandateAuBecsDebit {
142 pub url: String,
146}
147
148#[derive(Clone, Debug, Default, Deserialize, Serialize)]
149pub struct MandateBacsDebit {
150 pub network_status: MandateBacsDebitNetworkStatus,
154
155 pub reference: String,
157
158 pub revocation_reason: Option<MandateBacsDebitRevocationReason>,
160
161 pub url: String,
163}
164
165#[derive(Clone, Debug, Default, Deserialize, Serialize)]
166pub struct MandateCashapp {}
167
168#[derive(Clone, Debug, Default, Deserialize, Serialize)]
169pub struct MandateLink {}
170
171#[derive(Clone, Debug, Default, Deserialize, Serialize)]
172pub struct MandatePaypal {
173 pub billing_agreement_id: Option<String>,
177
178 pub payer_id: Option<String>,
182}
183
184#[derive(Clone, Debug, Default, Deserialize, Serialize)]
185pub struct MandateSepaDebit {
186 pub reference: String,
188
189 pub url: String,
193}
194
195#[derive(Clone, Debug, Default, Deserialize, Serialize)]
196pub struct MandateSingleUse {
197 pub amount: i64,
199
200 pub currency: Currency,
202}
203
204#[derive(Clone, Debug, Default, Deserialize, Serialize)]
205pub struct MandateUsBankAccount {
206 #[serde(skip_serializing_if = "Option::is_none")]
208 pub collection_method: Option<MandateUsBankAccountCollectionMethod>,
209}
210
211#[derive(Clone, Debug, Default, Deserialize, Serialize)]
212pub struct OfflineAcceptance {}
213
214#[derive(Clone, Debug, Default, Deserialize, Serialize)]
215pub struct OnlineAcceptance {
216 pub ip_address: Option<String>,
218
219 pub user_agent: Option<String>,
221}
222
223#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
225#[serde(rename_all = "snake_case")]
226pub enum CustomerAcceptanceType {
227 Offline,
228 Online,
229}
230
231impl CustomerAcceptanceType {
232 pub fn as_str(self) -> &'static str {
233 match self {
234 CustomerAcceptanceType::Offline => "offline",
235 CustomerAcceptanceType::Online => "online",
236 }
237 }
238}
239
240impl AsRef<str> for CustomerAcceptanceType {
241 fn as_ref(&self) -> &str {
242 self.as_str()
243 }
244}
245
246impl std::fmt::Display for CustomerAcceptanceType {
247 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
248 self.as_str().fmt(f)
249 }
250}
251impl std::default::Default for CustomerAcceptanceType {
252 fn default() -> Self {
253 Self::Offline
254 }
255}
256
257#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
259#[serde(rename_all = "snake_case")]
260pub enum MandateAcssDebitDefaultFor {
261 Invoice,
262 Subscription,
263}
264
265impl MandateAcssDebitDefaultFor {
266 pub fn as_str(self) -> &'static str {
267 match self {
268 MandateAcssDebitDefaultFor::Invoice => "invoice",
269 MandateAcssDebitDefaultFor::Subscription => "subscription",
270 }
271 }
272}
273
274impl AsRef<str> for MandateAcssDebitDefaultFor {
275 fn as_ref(&self) -> &str {
276 self.as_str()
277 }
278}
279
280impl std::fmt::Display for MandateAcssDebitDefaultFor {
281 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
282 self.as_str().fmt(f)
283 }
284}
285impl std::default::Default for MandateAcssDebitDefaultFor {
286 fn default() -> Self {
287 Self::Invoice
288 }
289}
290
291#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
293#[serde(rename_all = "snake_case")]
294pub enum MandateAcssDebitPaymentSchedule {
295 Combined,
296 Interval,
297 Sporadic,
298}
299
300impl MandateAcssDebitPaymentSchedule {
301 pub fn as_str(self) -> &'static str {
302 match self {
303 MandateAcssDebitPaymentSchedule::Combined => "combined",
304 MandateAcssDebitPaymentSchedule::Interval => "interval",
305 MandateAcssDebitPaymentSchedule::Sporadic => "sporadic",
306 }
307 }
308}
309
310impl AsRef<str> for MandateAcssDebitPaymentSchedule {
311 fn as_ref(&self) -> &str {
312 self.as_str()
313 }
314}
315
316impl std::fmt::Display for MandateAcssDebitPaymentSchedule {
317 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
318 self.as_str().fmt(f)
319 }
320}
321impl std::default::Default for MandateAcssDebitPaymentSchedule {
322 fn default() -> Self {
323 Self::Combined
324 }
325}
326
327#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
329#[serde(rename_all = "snake_case")]
330pub enum MandateAcssDebitTransactionType {
331 Business,
332 Personal,
333}
334
335impl MandateAcssDebitTransactionType {
336 pub fn as_str(self) -> &'static str {
337 match self {
338 MandateAcssDebitTransactionType::Business => "business",
339 MandateAcssDebitTransactionType::Personal => "personal",
340 }
341 }
342}
343
344impl AsRef<str> for MandateAcssDebitTransactionType {
345 fn as_ref(&self) -> &str {
346 self.as_str()
347 }
348}
349
350impl std::fmt::Display for MandateAcssDebitTransactionType {
351 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
352 self.as_str().fmt(f)
353 }
354}
355impl std::default::Default for MandateAcssDebitTransactionType {
356 fn default() -> Self {
357 Self::Business
358 }
359}
360
361#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
363#[serde(rename_all = "snake_case")]
364pub enum MandateBacsDebitNetworkStatus {
365 Accepted,
366 Pending,
367 Refused,
368 Revoked,
369}
370
371impl MandateBacsDebitNetworkStatus {
372 pub fn as_str(self) -> &'static str {
373 match self {
374 MandateBacsDebitNetworkStatus::Accepted => "accepted",
375 MandateBacsDebitNetworkStatus::Pending => "pending",
376 MandateBacsDebitNetworkStatus::Refused => "refused",
377 MandateBacsDebitNetworkStatus::Revoked => "revoked",
378 }
379 }
380}
381
382impl AsRef<str> for MandateBacsDebitNetworkStatus {
383 fn as_ref(&self) -> &str {
384 self.as_str()
385 }
386}
387
388impl std::fmt::Display for MandateBacsDebitNetworkStatus {
389 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
390 self.as_str().fmt(f)
391 }
392}
393impl std::default::Default for MandateBacsDebitNetworkStatus {
394 fn default() -> Self {
395 Self::Accepted
396 }
397}
398
399#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
401#[serde(rename_all = "snake_case")]
402pub enum MandateBacsDebitRevocationReason {
403 AccountClosed,
404 BankAccountRestricted,
405 BankOwnershipChanged,
406 CouldNotProcess,
407 DebitNotAuthorized,
408}
409
410impl MandateBacsDebitRevocationReason {
411 pub fn as_str(self) -> &'static str {
412 match self {
413 MandateBacsDebitRevocationReason::AccountClosed => "account_closed",
414 MandateBacsDebitRevocationReason::BankAccountRestricted => "bank_account_restricted",
415 MandateBacsDebitRevocationReason::BankOwnershipChanged => "bank_ownership_changed",
416 MandateBacsDebitRevocationReason::CouldNotProcess => "could_not_process",
417 MandateBacsDebitRevocationReason::DebitNotAuthorized => "debit_not_authorized",
418 }
419 }
420}
421
422impl AsRef<str> for MandateBacsDebitRevocationReason {
423 fn as_ref(&self) -> &str {
424 self.as_str()
425 }
426}
427
428impl std::fmt::Display for MandateBacsDebitRevocationReason {
429 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
430 self.as_str().fmt(f)
431 }
432}
433impl std::default::Default for MandateBacsDebitRevocationReason {
434 fn default() -> Self {
435 Self::AccountClosed
436 }
437}
438
439#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
441#[serde(rename_all = "snake_case")]
442pub enum MandateStatus {
443 Active,
444 Inactive,
445 Pending,
446}
447
448impl MandateStatus {
449 pub fn as_str(self) -> &'static str {
450 match self {
451 MandateStatus::Active => "active",
452 MandateStatus::Inactive => "inactive",
453 MandateStatus::Pending => "pending",
454 }
455 }
456}
457
458impl AsRef<str> for MandateStatus {
459 fn as_ref(&self) -> &str {
460 self.as_str()
461 }
462}
463
464impl std::fmt::Display for MandateStatus {
465 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
466 self.as_str().fmt(f)
467 }
468}
469impl std::default::Default for MandateStatus {
470 fn default() -> Self {
471 Self::Active
472 }
473}
474
475#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
477#[serde(rename_all = "snake_case")]
478pub enum MandateType {
479 MultiUse,
480 SingleUse,
481}
482
483impl MandateType {
484 pub fn as_str(self) -> &'static str {
485 match self {
486 MandateType::MultiUse => "multi_use",
487 MandateType::SingleUse => "single_use",
488 }
489 }
490}
491
492impl AsRef<str> for MandateType {
493 fn as_ref(&self) -> &str {
494 self.as_str()
495 }
496}
497
498impl std::fmt::Display for MandateType {
499 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
500 self.as_str().fmt(f)
501 }
502}
503impl std::default::Default for MandateType {
504 fn default() -> Self {
505 Self::MultiUse
506 }
507}
508
509#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
511#[serde(rename_all = "snake_case")]
512pub enum MandateUsBankAccountCollectionMethod {
513 Paper,
514}
515
516impl MandateUsBankAccountCollectionMethod {
517 pub fn as_str(self) -> &'static str {
518 match self {
519 MandateUsBankAccountCollectionMethod::Paper => "paper",
520 }
521 }
522}
523
524impl AsRef<str> for MandateUsBankAccountCollectionMethod {
525 fn as_ref(&self) -> &str {
526 self.as_str()
527 }
528}
529
530impl std::fmt::Display for MandateUsBankAccountCollectionMethod {
531 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
532 self.as_str().fmt(f)
533 }
534}
535impl std::default::Default for MandateUsBankAccountCollectionMethod {
536 fn default() -> Self {
537 Self::Paper
538 }
539}