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
use serde::{Deserialize, Serialize};

/// Indicates if this is a first or subsequent payment using a stored payment source
/// (also referred to as stored credential or card on file).
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
pub enum Usage {
    /// Indicates the Initial/First payment with a payment_source that is intended to be stored upon
    //  successful processing of the payment.
    #[serde(rename = "FIRST")]
    First,
    ///  Indicates a payment using a stored payment_source which has been successfully used previously for a payment.
    #[serde(rename = "SUBSEQUENT")]
    Subsequent,
    /// Indicates that PayPal will derive the value of `FIRST` or `SUBSEQUENT` based on data available to PayPal.
    #[serde(rename = "Derived")]
    Derived,
}

impl Usage {
    pub fn as_str(self) -> &'static str {
        match self {
            Usage::First => "FIRST",
            Usage::Subsequent => "SUBSEQUENT",
            Usage::Derived => "Derived",
        }
    }
}

impl AsRef<str> for Usage {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl std::fmt::Display for Usage {
    fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
        self.as_str().fmt(formatter)
    }
}