-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathclient.rs
More file actions
50 lines (48 loc) · 2.13 KB
/
Copy pathclient.rs
File metadata and controls
50 lines (48 loc) · 2.13 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
//! Client
//! =========
//! This file contains the Paystack API client, and it associated endpoints.
use crate::{
ApplePayEndpoints, CustomersEndpoints, DedicatedVirtualAccountEndpoints, HttpClient,
SubaccountEndpoints, TerminalEndpoints, TransactionEndpoints, TransactionSplitEndpoints,
VirtualTerminalEndpoints,
};
use std::sync::Arc;
/// This is the entry level struct for the paystack API.
/// it allows for authentication of the client
pub struct PaystackClient<T: HttpClient + Default> {
/// Transaction API route
pub transactions: TransactionEndpoints<T>,
/// Transaction Split API route
pub transaction_split: TransactionSplitEndpoints<T>,
/// Subaccount API route
pub subaccount: SubaccountEndpoints<T>,
/// Terminal API route
pub terminal: TerminalEndpoints<T>,
/// Virutal Terminal API route
pub virutal_terminal: VirtualTerminalEndpoints<T>,
/// Customers API route
pub customers: CustomersEndpoints<T>,
/// Dedicated Virtual Account API route
pub dedicated_virtual_account: DedicatedVirtualAccountEndpoints<T>,
/// Apple Pay API route
pub apple_pay: ApplePayEndpoints<T>,
}
impl<T: HttpClient + Default> PaystackClient<T> {
pub fn new(api_key: String) -> PaystackClient<T> {
let http = Arc::new(T::default());
let key = Arc::new(api_key);
PaystackClient {
transactions: TransactionEndpoints::new(Arc::clone(&key), Arc::clone(&http)),
transaction_split: TransactionSplitEndpoints::new(Arc::clone(&key), Arc::clone(&http)),
subaccount: SubaccountEndpoints::new(Arc::clone(&key), Arc::clone(&http)),
terminal: TerminalEndpoints::new(Arc::clone(&key), Arc::clone(&http)),
virutal_terminal: VirtualTerminalEndpoints::new(Arc::clone(&key), Arc::clone(&http)),
customers: CustomersEndpoints::new(Arc::clone(&key), Arc::clone(&http)),
dedicated_virtual_account: DedicatedVirtualAccountEndpoints::new(
Arc::clone(&key),
Arc::clone(&http),
),
apple_pay: ApplePayEndpoints::new(Arc::clone(&key), Arc::clone(&http)),
}
}
}