paypal_rust/resources/enums/
order_status.rs

1use std::str::FromStr;
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
6pub enum OrderStatus {
7    /// The order was created with the specified context.
8    #[serde(rename = "CREATED")]
9    Created,
10    /// The order was saved and persisted. The order status continues to be in progress until a capture is made with
11    /// `final_capture = true` for all purchase units within the order.
12    #[serde(rename = "SAVED")]
13    Saved,
14    /// The customer approved the payment through the PayPal wallet or another form of guest or unbranded payment.
15    /// For example, a card, bank account, or so on.
16    #[serde(rename = "APPROVED")]
17    Approved,
18    /// All purchase units in the order are voided.
19    #[serde(rename = "VOIDED")]
20    Voided,
21    /// The payment was authorized or the authorized payment was captured for the order.
22    #[serde(rename = "COMPLETED")]
23    Completed,
24    /// The order requires an action from the payer (e.g. 3DS authentication).
25    ///  Redirect the payer to the "rel":"payer-action" HATEOAS link returned as part of the response prior to authorizing or capturing
26    ///  the order.
27    #[serde(rename = "PAYER_ACTION_REQUIRED")]
28    PayerActionRequired,
29}
30
31impl OrderStatus {
32    pub const fn as_str(self) -> &'static str {
33        match self {
34            Self::Created => "CREATED",
35            Self::Saved => "SAVED",
36            Self::Approved => "APPROVED",
37            Self::Voided => "VOIDED",
38            Self::Completed => "COMPLETED",
39            Self::PayerActionRequired => "PAYER_ACTION_REQUIRED",
40        }
41    }
42}
43
44impl AsRef<str> for OrderStatus {
45    fn as_ref(&self) -> &str {
46        self.as_str()
47    }
48}
49
50impl std::fmt::Display for OrderStatus {
51    fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
52        self.as_str().fmt(formatter)
53    }
54}
55
56impl FromStr for OrderStatus {
57    type Err = OrderStatusError;
58    fn from_str(s: &str) -> Result<Self, Self::Err> {
59        match s {
60            "CREATED" => Ok(Self::Created),
61            "SAVED" => Ok(Self::Saved),
62            "APPROVED" => Ok(Self::Approved),
63            "VOIDED" => Ok(Self::Voided),
64            "COMPLETED" => Ok(Self::Completed),
65            "PAYER_ACTION_REQUIRED" => Ok(Self::PayerActionRequired),
66            _ => Err(OrderStatusError(())),
67        }
68    }
69}
70
71#[derive(Debug)]
72pub struct OrderStatusError(/* private */ ());
73
74impl std::fmt::Display for OrderStatusError {
75    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
76        "invalid order status".fmt(formatter)
77    }
78}
79
80impl std::error::Error for OrderStatusError {
81    fn description(&self) -> &str {
82        "invalid order status"
83    }
84}