primer_api/request/
vault_payment_method_payment_methods_token_vault_post.rs

1use serde_json::json;
2use crate::model::*;
3use crate::PrimerClient;
4/**Create this with the associated client method.
5
6That method takes required values as arguments. Set optional values using builder methods on this struct.*/
7pub struct VaultPaymentMethodPaymentMethodsTokenVaultPostRequest<'a> {
8    pub(crate) client: &'a PrimerClient,
9    pub payment_method_token: String,
10    pub customer_id: String,
11    pub verify: Option<bool>,
12}
13impl<'a> VaultPaymentMethodPaymentMethodsTokenVaultPostRequest<'a> {
14    pub async fn send(
15        self,
16    ) -> anyhow::Result<VerifiedMerchantPaymentMethodTokenApiResponse> {
17        let mut r = self
18            .client
19            .client
20            .post(
21                &format!(
22                    "/payment-instruments/{payment_method_token}/vault",
23                    payment_method_token = self.payment_method_token
24                ),
25            );
26        r = r.push_json(json!({ "customerId" : self.customer_id }));
27        if let Some(ref unwrapped) = self.verify {
28            r = r.push_json(json!({ "verify" : unwrapped }));
29        }
30        r = self.client.authenticate(r);
31        let res = r.send().await.unwrap().error_for_status();
32        match res {
33            Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
34            Err(res) => {
35                let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
36                Err(anyhow::anyhow!("{:?}", text))
37            }
38        }
39    }
40    pub fn verify(mut self, verify: bool) -> Self {
41        self.verify = Some(verify);
42        self
43    }
44}