-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgrant.rs
More file actions
50 lines (45 loc) · 1.54 KB
/
grant.rs
File metadata and controls
50 lines (45 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use crate::client::AuthenticatedOpenPaymentsClient;
use crate::request::AuthenticatedRequest;
use crate::types::{ContinueRequest, ContinueResponse, GrantRequest, GrantResponse};
use crate::OpClientError;
use crate::Result;
use reqwest::Method;
pub(crate) async fn request_grant(
client: &AuthenticatedOpenPaymentsClient,
auth_url: &str,
grant: &GrantRequest,
) -> Result<GrantResponse> {
let grant_with_client = GrantRequest {
client: client.config.wallet_address_url.clone(),
..grant.clone()
};
let body = serde_json::to_string(&grant_with_client).map_err(OpClientError::from)?;
AuthenticatedRequest::new(client, Method::POST, auth_url.to_string())
.with_body(body)
.build_and_execute(None)
.await
}
pub(crate) async fn continue_grant(
client: &AuthenticatedOpenPaymentsClient,
continue_uri: &str,
interact_ref: &str,
access_token: Option<&str>,
) -> Result<ContinueResponse> {
let body = serde_json::to_string(&ContinueRequest {
interact_ref: Some(interact_ref.to_string()),
})
.map_err(OpClientError::from)?;
AuthenticatedRequest::new(client, Method::POST, continue_uri.to_string())
.with_body(body)
.build_and_execute(access_token)
.await
}
pub(crate) async fn cancel_grant(
client: &AuthenticatedOpenPaymentsClient,
continue_uri: &str,
access_token: Option<&str>,
) -> Result<()> {
AuthenticatedRequest::new(client, Method::DELETE, continue_uri.to_string())
.build_and_execute(access_token)
.await
}