opennode_client/
lib.rs

1pub mod client;
2pub mod error;
3
4use opennode::account::{Balance};
5use opennode::charge;
6use opennode::charge::Charge;
7use opennode::withdrawal;
8use opennode::withdrawal::Withdrawal;
9use opennode::refund;
10use opennode::refund::Refund;
11use opennode::currency::Currency;
12use opennode::rate::Rates;
13
14use crate::client::Client;
15use crate::error::Error;
16
17/// Create charge
18pub async fn create_charge(client: &Client, payload: charge::Payload) -> Result<Charge, Error> {
19    client.post("/v1/charges", Some(payload)).await
20}
21
22/// Retrieve charge with the given id
23pub async fn get_charge(client: &Client, id: &str) -> Result< Charge, Error> {
24    let path = format!("/v1/charge/{}", id);
25    client.get(&path, None as Option<String>).await
26}
27
28/// Retrieve paid charges.
29pub async fn list_charges(client: &Client) -> Result<Vec<Charge>, Error> {
30    client.get("/v1/charges", None as Option<String>).await
31}
32
33/// Create withdrawal
34pub async fn create_withdrawal(client: &Client, payload: withdrawal::Payload) -> Result< Withdrawal,  Error> {
35    client.post("/v2/withdrawals", Some(payload)).await
36}
37
38/// Retrieve withdrawal with the given id
39pub async fn get_withdrawal(client: &Client, id: &str) -> Result<Withdrawal, Error> {
40    let path = format!("/v1/withdrawal/{}", id);
41    client.get(&path, None as Option<String>).await
42}
43
44/// Retrieve withdrawals.
45pub async fn list_withdrawals(client: &Client) -> Result<Vec<Withdrawal>, Error> {
46    client.get("/v1/withdrawals", None as Option<String>).await
47}
48
49/// Create refund
50pub async fn create_refund(client: &Client, payload: refund::Payload) -> Result<Refund, Error> {
51    client.post("/v1/refunds", Some(payload)).await
52}
53
54/// Retrieve refund with the given id
55pub async fn get_refund(client: &Client, id: &str) -> Result<Refund, Error> {
56    let path = format!("/v1/refund/{}", id);
57    client.get(&path, None as Option<String>).await
58}
59
60/// Retrieve refunds.
61pub async fn list_refunds(client: &Client) -> Result<Vec<Refund>, Error> {
62    client.get("/v1/refunds", None as Option<String>).await
63}
64
65/// Retrieve available currencies.
66pub async fn list_currencies(client: &Client) -> Result<Vec<Currency>, Error> {
67    client.get("/v1/currencies", None as Option<String>).await
68}
69
70/// Retrieve account balance.
71pub async fn get_account_balance(client: &Client) -> Result<Balance, Error> {
72    client.get("/v1/account/balance", None as Option<String>).await
73}
74
75/// Retrieve rate list.
76pub async fn list_rates(client: &Client) -> Result<Rates,  Error> {
77    client.get("/v1/rates", None as Option<String>).await
78}