stripe/resources/
payment_method_ext.rs

1use serde::{Deserialize, Serialize};
2
3use crate::client::{Client, Response};
4use crate::ids::{CustomerId, PaymentMethodId};
5use crate::resources::PaymentMethod;
6
7/// The parameters for `PaymentMethod::attach`
8///
9/// For more details see <https://stripe.com/docs/api/payment_methods/attach>.
10#[derive(Clone, Debug, Deserialize, Serialize)]
11pub struct AttachPaymentMethod {
12    pub customer: CustomerId,
13}
14
15impl PaymentMethod {
16    /// Attach a payment method to a customer
17    ///
18    /// For more details see <https://stripe.com/docs/api/payment_methods/attach>.
19    pub fn attach(
20        client: &Client,
21        payment_method_id: &PaymentMethodId,
22        params: AttachPaymentMethod,
23    ) -> Response<PaymentMethod> {
24        client.post_form(&format!("/payment_methods/{}/attach", payment_method_id), params)
25    }
26
27    /// Detach a PaymentMethod from a Customer
28    ///
29    /// For more details see <https://stripe.com/docs/api/payment_methods/detach>.
30    pub fn detach(client: &Client, payment_method_id: &PaymentMethodId) -> Response<PaymentMethod> {
31        client.post(&format!("/payment_methods/{}/detach", payment_method_id))
32    }
33}