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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
//! Paystack Enums
//! ===============
//! This file contains enums of options sent to or returned from the Paystack API

use std::fmt;

use serde::{Deserialize, Serialize};

/// Represents different currencies supported by the Paystack API.
///
/// The `Currency` enum defines the possible currency options that can be used with Paystack,
/// including Nigerian Naira (NGN), Ghanaian Cedis (GHS), American Dollar (USD),
/// and South African Rands (ZAR). It also includes an `EMPTY` variant to represent cases
/// where the currency can be empty.
///
/// # Variants
///
/// - `NGN`: Nigerian Naira.
/// - `GHS`: Ghanaian Cedis.
/// - `USD`: American Dollar.
/// - `ZAR`: South African Rands.
/// - `EMPTY`: Used when the currency can be empty.
///
/// # Examples
///
/// ```
/// use paystack::Currency;
///
/// let ngn_currency = Currency::NGN;
/// let ghs_currency = Currency::GHS;
/// let usd_currency = Currency::USD;
/// let zar_currency = Currency::ZAR;
/// let empty_currency = Currency::EMPTY;
///
/// println!("{:?}", ngn_currency); // Prints: NGN
/// ```
///
/// The example demonstrates the usage of the `Currency` enum from the Paystack crate,
/// creating instances of each variant and printing their debug representation.
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub enum Currency {
    /// Nigerian Naira
    #[default]
    NGN,
    /// Ghanaian Cedis
    GHS,
    /// American Dollar
    USD,
    /// South African Rands
    ZAR,
    /// Used when currency can be empty.
    EMPTY,
}

impl fmt::Display for Currency {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let currency = match self {
            Currency::NGN => "NGN",
            Currency::GHS => "GHS",
            Currency::USD => "USD",
            Currency::ZAR => "ZAR",
            Currency::EMPTY => "",
        };
        write!(f, "{}", currency)
    }
}

/// Represents the payment channels supported by Paystack.
///
/// The `Channel` enum defines the possible payment channels that can be used with Paystack,
/// including debit card, bank interface, USSD code, QR code, mobile money, bank transfer,
/// and Apple Pay.
///
/// # Variants
///
/// - `Card`: Payment with a debit card.
/// - `Bank`: Payment with a bank interface.
/// - `Ussd`: Payment with a USSD code.
/// - `Qr`: Payment with a QR code.
/// - `MobileMoney`: Payment with mobile money.
/// - `BankTransfer`: Payment with a bank transfer.
/// - `ApplePay`: Payment with Apple Pay.
///
/// # Examples
///
/// ```
/// use paystack::Channel;
///
/// let card_channel = Channel::Card;
/// let bank_channel = Channel::Bank;
/// let ussd_channel = Channel::Ussd;
/// let qr_channel = Channel::Qr;
/// let mobile_money_channel = Channel::MobileMoney;
/// let bank_transfer_channel = Channel::BankTransfer;
/// let apple_pay_channel = Channel::ApplePay;
///
/// println!("{:?}", card_channel); // Prints: card
/// println!("{:?}", mobile_money_channel); // Prints: mobile_money
/// ```
///
/// The example demonstrates the usage of the `Channel` enum from the Paystack crate,
/// creating instances of each variant and printing their debug representation.
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "snake_case")]
pub enum Channel {
    /// Debit Card
    #[default]
    Card,
    /// Payment with Bank Interface
    Bank,
    /// Payment with USSD Code
    Ussd,
    /// Payment with QR Code
    Qr,
    /// Payment with Mobile Money
    MobileMoney,
    /// Payment with Bank Transfer
    BankTransfer,
    /// Payment with Apple Pay
    ApplePay,
}

impl fmt::Display for Channel {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let lower_case = match self {
            Channel::Card => "card",
            Channel::Bank => "bank",
            Channel::Ussd => "ussd",
            Channel::Qr => "qr",
            Channel::MobileMoney => "mobile_money",
            Channel::BankTransfer => "bank_transfer",
            Channel::ApplePay => "mobile_money",
        };
        write!(f, "{}", lower_case)
    }
}

/// Represents the status of a transaction.
///
/// The `Status` enum defines the possible status values for a transaction,
/// indicating whether the transaction was successful, abandoned, or failed.
///
/// # Variants
///
/// - `Success`: Represents a successful transaction.
/// - `Abandoned`: Represents an abandoned transaction.
/// - `Failed`: Represents a failed transaction.
///
/// # Examples
///
/// ```
/// use paystack::Status;
///
/// let success_status = Status::Success;
/// let abandoned_status = Status::Abandoned;
/// let failed_status = Status::Failed;
///
/// println!("{:?}", success_status); // Prints: Success
/// ```
///
/// The example demonstrates the usage of the `Status` enum, creating instances of each variant
/// and printing their debug representation.
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "lowercase")]
pub enum Status {
    /// A successful transaction.
    Success,
    /// An abandoned transaction.
    Abandoned,
    /// A failed transaction.
    Failed,
}

impl fmt::Display for Status {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let lowercase_string = match self {
            Status::Success => "success",
            Status::Abandoned => "abandoned",
            Status::Failed => "failed",
        };
        write!(f, "{}", lowercase_string)
    }
}

/// Represents the type of transaction split.
///
/// The `SplitType` enum defines the possible types of transaction splits that can be created,
/// indicating whether the split is based on a percentage or a flat amount.
///
/// # Variants
///
/// - `Percentage`: A split based on a percentage.
/// - `Flat`: A split based on an amount.
///
/// # Examples
///
/// ```
/// use paystack::SplitType;
///
/// let percentage_split = SplitType::Percentage;
/// let flat_split = SplitType::Flat;
///
/// println!("{:?}", percentage_split); // Prints: Percentage
/// ```
///
/// The example demonstrates the usage of the `SplitType` enum, creating instances of each variant
/// and printing their debug representation.
#[derive(Debug, Serialize, Clone, Default)]
#[serde(rename_all = "lowercase")]
pub enum SplitType {
    /// A split based on a percentage
    #[default]
    Percentage,
    /// A split based on an amount
    Flat,
}

impl fmt::Display for SplitType {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let lowercase_string = match self {
            SplitType::Percentage => "percentage",
            SplitType::Flat => "flat",
        };
        write!(f, "{}", lowercase_string)
    }
}

/// Represents the type of bearer for a charge.
///
/// The `BearerType` enum defines the possible types of bearers for a charge, indicating who
/// is responsible for the transaction split.
///
/// # Variants
///
/// - `Subaccount`: The subaccount bears the transaction split.
/// - `Account`: The main account bears the transaction split.
/// - `AllProportional`: The transaction is split proportionally to all accounts.
/// - `All`: The transaction is paid by all accounts.
///
/// # Examples
///
/// ```
/// use paystack::BearerType;
///
/// let subaccount_bearer = BearerType::Subaccount;
/// let account_bearer = BearerType::Account;
/// let all_proportional_bearer = BearerType::AllProportional;
/// let all_bearer = BearerType::All;
///
/// println!("{:?}", subaccount_bearer); // Prints: Subaccount
/// ```
///
/// The example demonstrates the usage of the `BearerType` enum, creating instances of each variant
/// and printing their debug representation.
#[derive(Debug, Serialize, Clone, Default)]
#[serde(rename_all = "lowercase")]
pub enum BearerType {
    /// The subaccount bears the transaction split
    #[default]
    Subaccount,
    /// The main account bears the transaction split
    Account,
    /// The transaction is split proportionally to all accounts
    #[serde(rename = "all-proportional")]
    AllProportional,
    /// The transaction is paid by all accounts
    All,
}

impl fmt::Display for BearerType {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let lowercase_string = match self {
            BearerType::Subaccount => "subaccount",
            BearerType::Account => "account",
            BearerType::AllProportional => "all-proportional",
            BearerType::All => "all",
        };
        write!(f, "{}", lowercase_string)
    }
}