stripe_core/payment_source/
requests.rs1use stripe_client_core::{
2 RequestBuilder, StripeBlockingClient, StripeClient, StripeMethod, StripeRequest,
3};
4
5#[derive(Clone, Debug, serde::Serialize)]
6struct ListCustomerPaymentSourceBuilder {
7 #[serde(skip_serializing_if = "Option::is_none")]
8 ending_before: Option<String>,
9 #[serde(skip_serializing_if = "Option::is_none")]
10 expand: Option<Vec<String>>,
11 #[serde(skip_serializing_if = "Option::is_none")]
12 limit: Option<i64>,
13 #[serde(skip_serializing_if = "Option::is_none")]
14 object: Option<String>,
15 #[serde(skip_serializing_if = "Option::is_none")]
16 starting_after: Option<String>,
17}
18impl ListCustomerPaymentSourceBuilder {
19 fn new() -> Self {
20 Self { ending_before: None, expand: None, limit: None, object: None, starting_after: None }
21 }
22}
23#[derive(Clone, Debug, serde::Serialize)]
25pub struct ListCustomerPaymentSource {
26 inner: ListCustomerPaymentSourceBuilder,
27 customer: stripe_shared::CustomerId,
28}
29impl ListCustomerPaymentSource {
30 pub fn new(customer: impl Into<stripe_shared::CustomerId>) -> Self {
32 Self { customer: customer.into(), inner: ListCustomerPaymentSourceBuilder::new() }
33 }
34 pub fn ending_before(mut self, ending_before: impl Into<String>) -> Self {
38 self.inner.ending_before = Some(ending_before.into());
39 self
40 }
41 pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
43 self.inner.expand = Some(expand.into());
44 self
45 }
46 pub fn limit(mut self, limit: impl Into<i64>) -> Self {
49 self.inner.limit = Some(limit.into());
50 self
51 }
52 pub fn object(mut self, object: impl Into<String>) -> Self {
54 self.inner.object = Some(object.into());
55 self
56 }
57 pub fn starting_after(mut self, starting_after: impl Into<String>) -> Self {
61 self.inner.starting_after = Some(starting_after.into());
62 self
63 }
64}
65impl ListCustomerPaymentSource {
66 pub async fn send<C: StripeClient>(
68 &self,
69 client: &C,
70 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
71 self.customize().send(client).await
72 }
73
74 pub fn send_blocking<C: StripeBlockingClient>(
76 &self,
77 client: &C,
78 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
79 self.customize().send_blocking(client)
80 }
81
82 pub fn paginate(
83 &self,
84 ) -> stripe_client_core::ListPaginator<stripe_types::List<stripe_shared::PaymentSource>> {
85 let customer = &self.customer;
86
87 stripe_client_core::ListPaginator::new_list(
88 format!("/customers/{customer}/sources"),
89 &self.inner,
90 )
91 }
92}
93
94impl StripeRequest for ListCustomerPaymentSource {
95 type Output = stripe_types::List<stripe_shared::PaymentSource>;
96
97 fn build(&self) -> RequestBuilder {
98 let customer = &self.customer;
99 RequestBuilder::new(StripeMethod::Get, format!("/customers/{customer}/sources"))
100 .query(&self.inner)
101 }
102}
103#[derive(Clone, Debug, serde::Serialize)]
104struct RetrievePaymentSourceBuilder {
105 #[serde(skip_serializing_if = "Option::is_none")]
106 expand: Option<Vec<String>>,
107}
108impl RetrievePaymentSourceBuilder {
109 fn new() -> Self {
110 Self { expand: None }
111 }
112}
113#[derive(Clone, Debug, serde::Serialize)]
115pub struct RetrievePaymentSource {
116 inner: RetrievePaymentSourceBuilder,
117 customer: stripe_shared::CustomerId,
118 id: String,
119}
120impl RetrievePaymentSource {
121 pub fn new(customer: impl Into<stripe_shared::CustomerId>, id: impl Into<String>) -> Self {
123 Self {
124 customer: customer.into(),
125 id: id.into(),
126 inner: RetrievePaymentSourceBuilder::new(),
127 }
128 }
129 pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
131 self.inner.expand = Some(expand.into());
132 self
133 }
134}
135impl RetrievePaymentSource {
136 pub async fn send<C: StripeClient>(
138 &self,
139 client: &C,
140 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
141 self.customize().send(client).await
142 }
143
144 pub fn send_blocking<C: StripeBlockingClient>(
146 &self,
147 client: &C,
148 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
149 self.customize().send_blocking(client)
150 }
151}
152
153impl StripeRequest for RetrievePaymentSource {
154 type Output = stripe_shared::PaymentSource;
155
156 fn build(&self) -> RequestBuilder {
157 let customer = &self.customer;
158 let id = &self.id;
159 RequestBuilder::new(StripeMethod::Get, format!("/customers/{customer}/sources/{id}"))
160 .query(&self.inner)
161 }
162}
163#[derive(Clone, Debug, serde::Serialize)]
164struct CreateCustomerPaymentSourceBuilder {
165 #[serde(skip_serializing_if = "Option::is_none")]
166 expand: Option<Vec<String>>,
167 #[serde(skip_serializing_if = "Option::is_none")]
168 metadata: Option<std::collections::HashMap<String, String>>,
169 source: String,
170 #[serde(skip_serializing_if = "Option::is_none")]
171 validate: Option<bool>,
172}
173impl CreateCustomerPaymentSourceBuilder {
174 fn new(source: impl Into<String>) -> Self {
175 Self { expand: None, metadata: None, source: source.into(), validate: None }
176 }
177}
178#[derive(Clone, Debug, serde::Serialize)]
184pub struct CreateCustomerPaymentSource {
185 inner: CreateCustomerPaymentSourceBuilder,
186 customer: stripe_shared::CustomerId,
187}
188impl CreateCustomerPaymentSource {
189 pub fn new(customer: impl Into<stripe_shared::CustomerId>, source: impl Into<String>) -> Self {
191 Self {
192 customer: customer.into(),
193 inner: CreateCustomerPaymentSourceBuilder::new(source.into()),
194 }
195 }
196 pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
198 self.inner.expand = Some(expand.into());
199 self
200 }
201 pub fn metadata(
206 mut self,
207 metadata: impl Into<std::collections::HashMap<String, String>>,
208 ) -> Self {
209 self.inner.metadata = Some(metadata.into());
210 self
211 }
212 pub fn validate(mut self, validate: impl Into<bool>) -> Self {
213 self.inner.validate = Some(validate.into());
214 self
215 }
216}
217impl CreateCustomerPaymentSource {
218 pub async fn send<C: StripeClient>(
220 &self,
221 client: &C,
222 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
223 self.customize().send(client).await
224 }
225
226 pub fn send_blocking<C: StripeBlockingClient>(
228 &self,
229 client: &C,
230 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
231 self.customize().send_blocking(client)
232 }
233}
234
235impl StripeRequest for CreateCustomerPaymentSource {
236 type Output = stripe_shared::PaymentSource;
237
238 fn build(&self) -> RequestBuilder {
239 let customer = &self.customer;
240 RequestBuilder::new(StripeMethod::Post, format!("/customers/{customer}/sources"))
241 .form(&self.inner)
242 }
243}