paystack/models/split.rs
1//! Split Type
2//! ===============
3//! This file contains the transaction split options for the paystack API.
4
5use serde::Serialize;
6use std::fmt;
7
8/// Represents the type of transaction split.
9///
10/// The `SplitType` enum defines the possible types of transaction splits that can be created,
11/// indicating whether the split is based on a percentage or a flat amount.
12///
13/// # Variants
14///
15/// - `Percentage`: A split based on a percentage.
16/// - `Flat`: A split based on an amount.
17///
18/// # Examples
19///
20/// ```
21/// use paystack::SplitType;
22///
23/// let percentage_split = SplitType::Percentage;
24/// let flat_split = SplitType::Flat;
25///
26/// println!("{:?}", percentage_split); // Prints: Percentage
27/// ```
28///
29/// The example demonstrates the usage of the `SplitType` enum, creating instances of each variant
30/// and printing their debug representation.
31#[derive(Debug, Serialize, Clone, Default)]
32#[serde(rename_all = "lowercase")]
33pub enum SplitType {
34 /// A split based on a percentage
35 #[default]
36 Percentage,
37 /// A split based on an amount
38 Flat,
39}
40
41impl fmt::Display for SplitType {
42 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43 let lowercase_string = match self {
44 SplitType::Percentage => "percentage",
45 SplitType::Flat => "flat",
46 };
47 write!(f, "{}", lowercase_string)
48 }
49}