plaid/request/
item_public_token_exchange.rs

1use crate::FluentRequest;
2use serde::{Serialize, Deserialize};
3use httpclient::InMemoryResponseExt;
4/**You should use this struct via [`PlaidClient::item_public_token_exchange`].
5
6On request success, this will return a [`ItemPublicTokenExchangeResponse`].*/
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct ItemPublicTokenExchangeRequest {
9    pub public_token: String,
10}
11impl FluentRequest<'_, ItemPublicTokenExchangeRequest> {}
12impl<'a> ::std::future::IntoFuture
13for FluentRequest<'a, ItemPublicTokenExchangeRequest> {
14    type Output = httpclient::InMemoryResult<
15        crate::model::ItemPublicTokenExchangeResponse,
16    >;
17    type IntoFuture = ::futures::future::BoxFuture<'a, Self::Output>;
18    fn into_future(self) -> Self::IntoFuture {
19        Box::pin(async move {
20            let url = "/item/public_token/exchange";
21            let mut r = self.client.client.post(url);
22            r = r.json(serde_json::json!({ "public_token" : self.params.public_token }));
23            r = self.client.authenticate(r);
24            let res = r.await?;
25            res.json().map_err(Into::into)
26        })
27    }
28}
29impl crate::PlaidClient {
30    /**Exchange public token for an access token
31
32Exchange a Link `public_token` for an API `access_token`. Link hands off the `public_token` client-side via the `onSuccess` callback once a user has successfully created an Item. The `public_token` is ephemeral and expires after 30 minutes. An `access_token` does not expire, but can be revoked by calling `/item/remove`.
33
34The response also includes an `item_id` that should be stored with the `access_token`. The `item_id` is used to identify an Item in a webhook. The `item_id` can also be retrieved by making an `/item/get` request.
35
36See endpoint docs at <https://plaid.com/docs/api/items/#itempublic_tokenexchange>.*/
37    pub fn item_public_token_exchange(
38        &self,
39        public_token: &str,
40    ) -> FluentRequest<'_, ItemPublicTokenExchangeRequest> {
41        FluentRequest {
42            client: self,
43            params: ItemPublicTokenExchangeRequest {
44                public_token: public_token.to_owned(),
45            },
46        }
47    }
48}