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
//! Client
//! ===========
//! The file for the Paystack API client and it's associated functions
use crate::{Subaccount, Transaction, TransactionSplit};

/// This is the struct that allows you to authenticate to the PayStack API.
/// It contains the API key which allows you to interact with the API.
pub struct PaystackClient<'a> {
    /// Transaction API route
    pub transaction: Transaction<'a>,
    /// Transaction Split API route
    pub transaction_split: TransactionSplit<'a>,
    /// Subaccount API route
    pub subaccount: Subaccount<'a>,
}

impl<'a> PaystackClient<'a> {
    /// This method creates a new PayStack client with the specified API key.
    ///
    /// It takes the following parameters:
    ///     - key: Paystack API key.
    pub fn new(key: &'a str) -> PaystackClient<'a> {
        PaystackClient {
            transaction: Transaction::new(key),
            transaction_split: TransactionSplit::new(key),
            subaccount: Subaccount::new(key),
        }
    }
}