paystack/models/
channel_models.rs

1//! Channel
2//! ===============
3//! This file contains the Channel option for the paystack API.
4
5use serde::{Deserialize, Serialize};
6use std::fmt;
7
8/// Represents the payment channels supported by Paystack.
9///
10/// The `Channel` enum defines the possible payment channels that can be used with Paystack,
11/// including debit card, bank interface, USSD code, QR code, mobile money, bank transfer,
12/// and Apple Pay.
13///
14/// # Variants
15///
16/// - `Card`: Payment with a debit card.
17/// - `Bank`: Payment with a bank interface.
18/// - `Ussd`: Payment with a USSD code.
19/// - `Qr`: Payment with a QR code.
20/// - `MobileMoney`: Payment with mobile money.
21/// - `BankTransfer`: Payment with a bank transfer.
22/// - `ApplePay`: Payment with Apple Pay.
23///
24/// # Examples
25///
26/// ```
27/// use paystack::Channel;
28///
29/// let card = Channel::Card;
30/// let bank = Channel::Bank;
31/// let ussd = Channel::Ussd;
32/// let qr = Channel::Qr;
33/// let mobile_money = Channel::MobileMoney;
34/// let bank_transfer = Channel::BankTransfer;
35/// let apple_pay = Channel::ApplePay;
36///
37/// println!("{:?}", card); // Prints: card
38/// println!("{:?}", mobile_money); // Prints: mobile_money
39/// ```
40///
41/// The example demonstrates the usage of the `Channel` enum from the Paystack crate,
42/// creating instances of each variant and printing their debug representation.
43#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq)]
44#[serde(rename_all = "snake_case")]
45pub enum Channel {
46    /// Debit Card
47    #[default]
48    Card,
49    /// Payment with Bank Interface
50    Bank,
51    /// Payment with USSD Code
52    Ussd,
53    /// Payment with QR Code
54    Qr,
55    /// Payment with Mobile Money
56    MobileMoney,
57    /// Payment with Bank Transfer
58    BankTransfer,
59    /// Payment with Apple Pay
60    ApplePay,
61}
62
63impl fmt::Display for Channel {
64    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
65        let lower_case = match self {
66            Channel::Card => "card",
67            Channel::Bank => "bank",
68            Channel::Ussd => "ussd",
69            Channel::Qr => "qr",
70            Channel::MobileMoney => "mobile_money",
71            Channel::BankTransfer => "bank_transfer",
72            Channel::ApplePay => "mobile_money",
73        };
74        write!(f, "{}", lower_case)
75    }
76}