stripe/resources/generated/
mandate.rs

1// ======================================
2// This file was automatically generated.
3// ======================================
4
5use 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/// The resource representing a Stripe "Mandate".
12///
13/// For more details see <https://stripe.com/docs/api/mandates/object>
14#[derive(Clone, Debug, Default, Deserialize, Serialize)]
15pub struct Mandate {
16    /// Unique identifier for the object.
17    pub id: MandateId,
18
19    pub customer_acceptance: CustomerAcceptance,
20
21    /// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
22    pub livemode: bool,
23
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub multi_use: Option<MandateMultiUse>,
26
27    /// The account (if any) that the mandate is intended for.
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub on_behalf_of: Option<String>,
30
31    /// ID of the payment method associated with this mandate.
32    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    /// The mandate status indicates whether or not you can use it to initiate a payment.
40    pub status: MandateStatus,
41
42    /// The type of the mandate.
43    #[serde(rename = "type")]
44    pub type_: MandateType,
45}
46
47impl Mandate {
48    /// Retrieves a Mandate object.
49    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    /// The time that the customer accepts the mandate.
67    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    /// The mandate includes the type of customer acceptance information, such as: `online` or `offline`.
76    #[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    /// This mandate corresponds with a specific payment method type.
110    ///
111    /// The `payment_method_details` includes an additional hash with the same name and contains mandate information that's specific to that payment method.
112    #[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    /// List of Stripe products where this mandate can be selected automatically.
125    #[serde(skip_serializing_if = "Option::is_none")]
126    pub default_for: Option<Vec<MandateAcssDebitDefaultFor>>,
127
128    /// Description of the interval.
129    ///
130    /// Only required if the 'payment_schedule' parameter is 'interval' or 'combined'.
131    pub interval_description: Option<String>,
132
133    /// Payment schedule for the mandate.
134    pub payment_schedule: MandateAcssDebitPaymentSchedule,
135
136    /// Transaction type of the mandate.
137    pub transaction_type: MandateAcssDebitTransactionType,
138}
139
140#[derive(Clone, Debug, Default, Deserialize, Serialize)]
141pub struct MandateAuBecsDebit {
142    /// The URL of the mandate.
143    ///
144    /// This URL generally contains sensitive information about the customer and should be shared with them exclusively.
145    pub url: String,
146}
147
148#[derive(Clone, Debug, Default, Deserialize, Serialize)]
149pub struct MandateBacsDebit {
150    /// The status of the mandate on the Bacs network.
151    ///
152    /// Can be one of `pending`, `revoked`, `refused`, or `accepted`.
153    pub network_status: MandateBacsDebitNetworkStatus,
154
155    /// The unique reference identifying the mandate on the Bacs network.
156    pub reference: String,
157
158    /// When the mandate is revoked on the Bacs network this field displays the reason for the revocation.
159    pub revocation_reason: Option<MandateBacsDebitRevocationReason>,
160
161    /// The URL that will contain the mandate that the customer has signed.
162    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    /// The PayPal Billing Agreement ID (BAID).
174    ///
175    /// This is an ID generated by PayPal which represents the mandate between the merchant and the customer.
176    pub billing_agreement_id: Option<String>,
177
178    /// PayPal account PayerID.
179    ///
180    /// This identifier uniquely identifies the PayPal customer.
181    pub payer_id: Option<String>,
182}
183
184#[derive(Clone, Debug, Default, Deserialize, Serialize)]
185pub struct MandateSepaDebit {
186    /// The unique reference of the mandate.
187    pub reference: String,
188
189    /// The URL of the mandate.
190    ///
191    /// This URL generally contains sensitive information about the customer and should be shared with them exclusively.
192    pub url: String,
193}
194
195#[derive(Clone, Debug, Default, Deserialize, Serialize)]
196pub struct MandateSingleUse {
197    /// The amount of the payment on a single use mandate.
198    pub amount: i64,
199
200    /// The currency of the payment on a single use mandate.
201    pub currency: Currency,
202}
203
204#[derive(Clone, Debug, Default, Deserialize, Serialize)]
205pub struct MandateUsBankAccount {
206    /// Mandate collection method.
207    #[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    /// The customer accepts the mandate from this IP address.
217    pub ip_address: Option<String>,
218
219    /// The customer accepts the mandate using the user agent of the browser.
220    pub user_agent: Option<String>,
221}
222
223/// An enum representing the possible values of an `CustomerAcceptance`'s `type` field.
224#[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/// An enum representing the possible values of an `MandateAcssDebit`'s `default_for` field.
258#[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/// An enum representing the possible values of an `MandateAcssDebit`'s `payment_schedule` field.
292#[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/// An enum representing the possible values of an `MandateAcssDebit`'s `transaction_type` field.
328#[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/// An enum representing the possible values of an `MandateBacsDebit`'s `network_status` field.
362#[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/// An enum representing the possible values of an `MandateBacsDebit`'s `revocation_reason` field.
400#[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/// An enum representing the possible values of an `Mandate`'s `status` field.
440#[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/// An enum representing the possible values of an `Mandate`'s `type` field.
476#[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/// An enum representing the possible values of an `MandateUsBankAccount`'s `collection_method` field.
510#[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}