paystack/models/bearer_models.rs
1//! Bearer Type
2//! =================
3//! This file contains the charge bearer option for the paystack API.
4
5use serde::Serialize;
6use std::fmt;
7
8/// Represents the type of bearer for a charge.
9///
10/// The `BearerType` enum defines the possible types of bearers for a charge, indicating who
11/// is responsible for the transaction split.
12///
13/// # Variants
14///
15/// - `Subaccount`: The subaccount bears the transaction split.
16/// - `Account`: The main account bears the transaction split.
17/// - `AllProportional`: The transaction is split proportionally to all accounts.
18/// - `All`: The transaction is paid by all accounts.
19///
20/// # Examples
21///
22/// ```
23/// use paystack::BearerType;
24///
25/// let subaccount_bearer = BearerType::Subaccount;
26/// let account_bearer = BearerType::Account;
27/// let all_proportional_bearer = BearerType::AllProportional;
28/// let all_bearer = BearerType::All;
29///
30/// println!("{:?}", subaccount_bearer); // Prints: Subaccount
31/// ```
32///
33/// The example demonstrates the usage of the `BearerType` enum, creating instances of each variant
34/// and printing their debug representation.
35#[derive(Debug, Serialize, Clone, Default)]
36#[serde(rename_all = "lowercase")]
37pub enum BearerType {
38 /// The subaccount bears the transaction split
39 #[default]
40 Subaccount,
41 /// The main account bears the transaction split
42 Account,
43 /// The transaction is split proportionally to all accounts
44 #[serde(rename = "all-proportional")]
45 AllProportional,
46 /// The transaction is paid by all accounts
47 All,
48}
49
50impl fmt::Display for BearerType {
51 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
52 let lowercase_string = match self {
53 BearerType::Subaccount => "subaccount",
54 BearerType::Account => "account",
55 BearerType::AllProportional => "all-proportional",
56 BearerType::All => "all",
57 };
58 write!(f, "{lowercase_string}")
59 }
60}