primer_api/request/
create_client_side_token_client_session_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 CreateClientSideTokenClientSessionPostRequest<'a> {
8    pub(crate) client: &'a PrimerClient,
9    pub order_id: String,
10    pub currency_code: String,
11    pub amount: serde_json::Value,
12    pub order: OrderDetailsApiSchema,
13    pub customer_id: String,
14    pub customer: CheckoutCustomerDetailsApiSchema,
15    pub metadata: serde_json::Value,
16    pub payment_method: CheckoutPaymentMethodOptionsApiSchema,
17}
18impl<'a> CreateClientSideTokenClientSessionPostRequest<'a> {
19    pub async fn send(self) -> anyhow::Result<ClientSessionWithTokenApiResponse> {
20        let mut r = self.client.client.post("/client-session");
21        r = r.push_json(json!({ "orderId" : self.order_id }));
22        r = r.push_json(json!({ "currencyCode" : self.currency_code }));
23        r = r.push_json(json!({ "amount" : self.amount }));
24        r = r.push_json(json!({ "order" : self.order }));
25        r = r.push_json(json!({ "customerId" : self.customer_id }));
26        r = r.push_json(json!({ "customer" : self.customer }));
27        r = r.push_json(json!({ "metadata" : self.metadata }));
28        r = r.push_json(json!({ "paymentMethod" : self.payment_method }));
29        r = self.client.authenticate(r);
30        let res = r.send().await.unwrap().error_for_status();
31        match res {
32            Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
33            Err(res) => {
34                let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
35                Err(anyhow::anyhow!("{:?}", text))
36            }
37        }
38    }
39}
40pub struct CreateClientSideTokenClientSessionPostRequired<'a> {
41    pub order_id: &'a str,
42    pub currency_code: &'a str,
43    pub amount: serde_json::Value,
44    pub order: OrderDetailsApiSchema,
45    pub customer_id: &'a str,
46    pub customer: CheckoutCustomerDetailsApiSchema,
47    pub metadata: serde_json::Value,
48    pub payment_method: CheckoutPaymentMethodOptionsApiSchema,
49}
50impl<'a> CreateClientSideTokenClientSessionPostRequired<'a> {}