plaid/request/
sandbox_public_token_create.rs

1use crate::FluentRequest;
2use serde::{Serialize, Deserialize};
3use httpclient::InMemoryResponseExt;
4use crate::model::{Products, SandboxPublicTokenCreateRequestOptions};
5/**You should use this struct via [`PlaidClient::sandbox_public_token_create`].
6
7On request success, this will return a [`SandboxPublicTokenCreateResponse`].*/
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct SandboxPublicTokenCreateRequest {
10    pub initial_products: Vec<Products>,
11    pub institution_id: String,
12    pub options: Option<SandboxPublicTokenCreateRequestOptions>,
13    pub user_token: Option<String>,
14}
15impl FluentRequest<'_, SandboxPublicTokenCreateRequest> {
16    ///Set the value of the options field.
17    pub fn options(mut self, options: SandboxPublicTokenCreateRequestOptions) -> Self {
18        self.params.options = Some(options);
19        self
20    }
21    ///Set the value of the user_token field.
22    pub fn user_token(mut self, user_token: &str) -> Self {
23        self.params.user_token = Some(user_token.to_owned());
24        self
25    }
26}
27impl<'a> ::std::future::IntoFuture
28for FluentRequest<'a, SandboxPublicTokenCreateRequest> {
29    type Output = httpclient::InMemoryResult<
30        crate::model::SandboxPublicTokenCreateResponse,
31    >;
32    type IntoFuture = ::futures::future::BoxFuture<'a, Self::Output>;
33    fn into_future(self) -> Self::IntoFuture {
34        Box::pin(async move {
35            let url = "/sandbox/public_token/create";
36            let mut r = self.client.client.post(url);
37            r = r
38                .json(
39                    serde_json::json!(
40                        { "initial_products" : self.params.initial_products }
41                    ),
42                );
43            r = r
44                .json(
45                    serde_json::json!({ "institution_id" : self.params.institution_id }),
46                );
47            if let Some(ref unwrapped) = self.params.options {
48                r = r.json(serde_json::json!({ "options" : unwrapped }));
49            }
50            if let Some(ref unwrapped) = self.params.user_token {
51                r = r.json(serde_json::json!({ "user_token" : unwrapped }));
52            }
53            r = self.client.authenticate(r);
54            let res = r.await?;
55            res.json().map_err(Into::into)
56        })
57    }
58}
59impl crate::PlaidClient {
60    /**Create a test Item
61
62Use the `/sandbox/public_token/create` endpoint to create a valid `public_token`  for an arbitrary institution ID, initial products, and test credentials. The created `public_token` maps to a new Sandbox Item. You can then call `/item/public_token/exchange` to exchange the `public_token` for an `access_token` and perform all API actions. `/sandbox/public_token/create` can also be used with the [`user_custom` test username](https://plaid.com/docs/sandbox/user-custom) to generate a test account with custom data, or with Plaid's [pre-populated Sandbox test accounts](https://plaid.com/docs/sandbox/test-credentials/).
63
64See endpoint docs at <https://plaid.com/docs/api/sandbox/#sandboxpublic_tokencreate>.*/
65    pub fn sandbox_public_token_create(
66        &self,
67        initial_products: Vec<Products>,
68        institution_id: &str,
69    ) -> FluentRequest<'_, SandboxPublicTokenCreateRequest> {
70        FluentRequest {
71            client: self,
72            params: SandboxPublicTokenCreateRequest {
73                initial_products,
74                institution_id: institution_id.to_owned(),
75                options: None,
76                user_token: None,
77            },
78        }
79    }
80}