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
use serde::{Deserialize, Serialize};
use crate::client::{Client, Response};
use crate::ids::{BankAccountId, CardId, CustomerId, PaymentSourceId};
use crate::params::{Deleted, Expand, List};
use crate::resources::{
BankAccount, Customer, PaymentMethod, PaymentSource, PaymentSourceParams, Source,
};
#[derive(Clone, Debug, Serialize, Eq, PartialEq)]
pub struct CustomerPaymentMethodRetrieval<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
pub ending_before: Option<String>,
#[serde(skip_serializing_if = "Expand::is_empty")]
pub expand: &'a [&'a str],
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub starting_after: Option<String>,
#[serde(rename = "type")]
pub type_: CustomerPaymentMethodRetrievalType,
}
impl<'a> CustomerPaymentMethodRetrieval<'a> {
pub fn new(the_type: CustomerPaymentMethodRetrievalType) -> Self {
CustomerPaymentMethodRetrieval {
ending_before: None,
expand: &[],
limit: None,
starting_after: None,
type_: the_type,
}
}
}
#[derive(Copy, Clone, Debug, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum CustomerPaymentMethodRetrievalType {
AcssDebit,
AfterpayClearpay,
Alipay,
AuBecsDebit,
BacsDebit,
Bancontact,
Boleto,
Card,
Eps,
Fpx,
Giropay,
Grabpay,
Ideal,
Klarna,
Oxxo,
P24,
SepaDebit,
Sofort,
WechatPay,
}
impl Customer {
pub fn attach_source(
client: &Client,
customer_id: &CustomerId,
source: PaymentSourceParams,
) -> Response<PaymentSource> {
#[derive(Serialize)]
struct AttachSource {
source: PaymentSourceParams,
}
let params = AttachSource { source };
client.post_form(&format!("/customers/{}/sources", customer_id), params)
}
pub fn detach_source(
client: &Client,
customer_id: &CustomerId,
source_id: &PaymentSourceId,
) -> Response<DetachedSource> {
client.delete(&format!("/customers/{}/sources/{}", customer_id, source_id))
}
pub fn retrieve_source(
client: &Client,
customer_id: &CustomerId,
source_id: &PaymentSourceId,
) -> Response<PaymentSource> {
client.get(&format!("/customers/{}/sources/{}", customer_id, source_id))
}
pub fn verify_bank_account(
client: &Client,
customer_id: &CustomerId,
bank_account_id: &BankAccountId,
params: VerifyBankAccount<'_>,
) -> Response<BankAccount> {
client.post_form(
&format!("/customers/{}/sources/{}/verify", customer_id, bank_account_id),
params,
)
}
pub fn retrieve_payment_methods(
client: &Client,
customer_id: &CustomerId,
params: CustomerPaymentMethodRetrieval<'_>,
) -> Response<List<PaymentMethod>> {
client.get_query(&format!("/customers/{}/payment_methods", customer_id), ¶ms)
}
}
#[derive(Clone, Debug, Default, Serialize)]
pub struct VerifyBankAccount<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
pub amounts: Option<Vec<i64>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub verification_method: Option<&'a str>,
}
impl VerifyBankAccount<'_> {
pub fn new() -> Self {
VerifyBankAccount { amounts: None, verification_method: None }
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "object", rename_all = "snake_case")]
pub enum DetachedSource {
BankAccount(Deleted<BankAccountId>),
Card(Deleted<CardId>),
Source(Source),
}