adyen/
pay_with_vipps.rs

1use crate::{currency::Currency, error::Error, payment, Gateway};
2use serde::Serialize;
3
4impl Gateway {
5    // https://docs.adyen.com/payment-methods/swish/api-only/
6    pub async fn pay_with_vipps<'a>(
7        &self,
8        amount: u64,
9        currency: &'a Currency,
10        reference: &'a str,
11        return_url: &'a str,
12        merchant_account: &'a str,
13        channel: &'a str,
14        telephone_number: &'a Option<&'a str>,
15    ) -> Result<payment::Response, Error> {
16        #[derive(Serialize)]
17        #[serde(rename_all = "camelCase")]
18        struct Amount<'a> {
19            value: u64,
20            currency: &'a str,
21        }
22
23        let amount = Amount {
24            value: amount,
25            currency: &currency.to_string(),
26        };
27
28        #[derive(Serialize)]
29        #[serde(rename_all = "camelCase")]
30        struct PaymentMethod<'a> {
31            r#type: &'a str,
32
33            #[serde(skip_serializing_if = "Option::is_none")]
34            telephone_number: &'a Option<&'a str>,
35        }
36
37        let payment_method = PaymentMethod {
38            r#type: "vipps",
39            telephone_number,
40        };
41
42        #[derive(Serialize)]
43        #[serde(rename_all = "camelCase")]
44        struct Request<'a> {
45            amount: Amount<'a>,
46            reference: &'a str,
47            payment_method: PaymentMethod<'a>,
48            return_url: &'a str,
49            merchant_account: &'a str,
50            channel: &'a str,
51        }
52
53        let body = Request {
54            amount,
55            payment_method,
56            reference,
57            return_url,
58            merchant_account,
59            channel,
60        };
61
62        let url = format!("{}/v71/payments", self.base_api_url);
63        let res: payment::Response = self.post(&url, &body).await?;
64
65        Ok(res)
66    }
67}