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