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

/// The intent to either capture payment immediately or authorize a payment for an order after order creation.
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
pub enum OrderIntent {
    /// The merchant intends to capture payment immediately after the customer makes a payment.
    #[serde(rename = "CAPTURE")]
    Capture,
    /// The merchant intends to authorize a payment and place funds on hold after the customer makes a payment.
    /// Authorized payments are best captured within three days of authorization but are available to capture for up to 29 days.
    /// After the three-day honor period, the original authorized payment expires and you must re-authorize the payment.
    /// You must make a separate request to capture payments on demand. This intent is not supported when you have more than one
    /// `purchase_unit` within your order.
    #[serde(rename = "AUTHORIZE")]
    Authorize,
}

impl OrderIntent {
    pub fn as_str(self) -> &'static str {
        match self {
            OrderIntent::Capture => "CAPTURE",
            OrderIntent::Authorize => "AUTHORIZE",
        }
    }
}

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

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