paddle_rust_sdk/
payment_methods.rs1use reqwest::Method;
6use serde::Serialize;
7use serde_with::skip_serializing_none;
8
9use crate::entities::PaymentMethod;
10use crate::ids::{AddressID, CustomerID, PaymentMethodID};
11use crate::paginated::Paginated;
12use crate::{Paddle, Result};
13
14#[skip_serializing_none]
16#[derive(Serialize)]
17pub struct PaymentMethodsList<'a> {
18 #[serde(skip)]
19 client: &'a Paddle,
20 #[serde(skip)]
21 customer_id: CustomerID,
22 #[serde(serialize_with = "crate::comma_separated")]
23 address_id: Option<Vec<AddressID>>,
24 after: Option<PaymentMethodID>,
25 order_by: Option<String>,
26 per_page: Option<usize>,
27 supports_checkout: Option<bool>,
28}
29
30impl<'a> PaymentMethodsList<'a> {
31 pub fn new(client: &'a Paddle, customer_id: impl Into<CustomerID>) -> Self {
32 Self {
33 client,
34 customer_id: customer_id.into(),
35 after: None,
36 address_id: None,
37 order_by: None,
38 per_page: None,
39 supports_checkout: None,
40 }
41 }
42
43 pub fn address_ids(
45 &mut self,
46 address_ids: impl IntoIterator<Item = impl Into<AddressID>>,
47 ) -> &mut Self {
48 self.address_id = Some(address_ids.into_iter().map(Into::into).collect());
49 self
50 }
51
52 pub fn after(&mut self, id: impl Into<PaymentMethodID>) -> &mut Self {
54 self.after = Some(id.into());
55 self
56 }
57
58 pub fn order_by_asc(&mut self, field: &str) -> &mut Self {
60 self.order_by = Some(format!("{}[ASC]", field));
61 self
62 }
63
64 pub fn order_by_desc(&mut self, field: &str) -> &mut Self {
66 self.order_by = Some(format!("{}[DESC]", field));
67 self
68 }
69
70 pub fn per_page(&mut self, entities_per_page: usize) -> &mut Self {
75 self.per_page = Some(entities_per_page);
76 self
77 }
78
79 pub fn supports_checkout(&mut self, flag: bool) -> &mut Self {
81 self.supports_checkout = Some(flag);
82 self
83 }
84
85 pub fn send(&self) -> Paginated<Vec<PaymentMethod>> {
87 let url = format!("/customers/{}/payment-methods", self.customer_id.as_ref());
88
89 Paginated::new(self.client, &url, self)
90 }
91}
92
93#[skip_serializing_none]
95#[derive(Serialize)]
96pub struct PaymentMethodGet<'a> {
97 #[serde(skip)]
98 client: &'a Paddle,
99 #[serde(skip)]
100 customer_id: CustomerID,
101 #[serde(skip)]
102 payment_method_id: PaymentMethodID,
103}
104
105impl<'a> PaymentMethodGet<'a> {
106 pub fn new(
107 client: &'a Paddle,
108 customer_id: impl Into<CustomerID>,
109 payment_method_id: impl Into<PaymentMethodID>,
110 ) -> Self {
111 Self {
112 client,
113 customer_id: customer_id.into(),
114 payment_method_id: payment_method_id.into(),
115 }
116 }
117
118 pub async fn send(&self) -> Result<PaymentMethod> {
120 self.client
121 .send(
122 self,
123 Method::GET,
124 &format!(
125 "/customers/{}/payment-methods/{}",
126 self.customer_id.as_ref(),
127 self.payment_method_id.as_ref()
128 ),
129 )
130 .await
131 }
132}