paystack/
client.rs

1//! Client
2//! =========
3//! This file contains the Paystack API client, and it associated endpoints.
4use crate::{
5    ApplePayEndpoints, CustomersEndpoints, DedicatedVirtualAccountEndpoints, HttpClient,
6    SubaccountEndpoints, TerminalEndpoints, TransactionEndpoints, TransactionSplitEndpoints,
7    VirtualTerminalEndpoints,
8};
9use std::sync::Arc;
10
11/// This is the entry level struct for the paystack API.
12/// it allows for authentication of the client
13pub struct PaystackClient<T: HttpClient + Default> {
14    /// Transaction API route
15    pub transactions: TransactionEndpoints<T>,
16    /// Transaction Split API route
17    pub transaction_split: TransactionSplitEndpoints<T>,
18    /// Subaccount API route
19    pub subaccount: SubaccountEndpoints<T>,
20    /// Terminal API route
21    pub terminal: TerminalEndpoints<T>,
22    /// Virutal Terminal API route
23    pub virutal_terminal: VirtualTerminalEndpoints<T>,
24    /// Customers API route
25    pub customers: CustomersEndpoints<T>,
26    /// Dedicated Virtual Account API route
27    pub dedicated_virtual_account: DedicatedVirtualAccountEndpoints<T>,
28    /// Apple Pay API route
29    pub apple_pay: ApplePayEndpoints<T>,
30}
31
32impl<T: HttpClient + Default> PaystackClient<T> {
33    pub fn new(api_key: String) -> PaystackClient<T> {
34        let http = Arc::new(T::default());
35        let key = Arc::new(api_key);
36        PaystackClient {
37            transactions: TransactionEndpoints::new(Arc::clone(&key), Arc::clone(&http)),
38            transaction_split: TransactionSplitEndpoints::new(Arc::clone(&key), Arc::clone(&http)),
39            subaccount: SubaccountEndpoints::new(Arc::clone(&key), Arc::clone(&http)),
40            terminal: TerminalEndpoints::new(Arc::clone(&key), Arc::clone(&http)),
41            virutal_terminal: VirtualTerminalEndpoints::new(Arc::clone(&key), Arc::clone(&http)),
42            customers: CustomersEndpoints::new(Arc::clone(&key), Arc::clone(&http)),
43            dedicated_virtual_account: DedicatedVirtualAccountEndpoints::new(
44                Arc::clone(&key),
45                Arc::clone(&http),
46            ),
47            apple_pay: ApplePayEndpoints::new(Arc::clone(&key), Arc::clone(&http)),
48        }
49    }
50}