lightspark/objects/
transaction_status.rs

1// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4use std::fmt;
5
6/// This is an enum of the potential statuses a transaction associated with your Lightspark Node can take.
7#[derive(Debug, Clone, Deserialize, Serialize)]
8pub enum TransactionStatus {
9    /// Transaction succeeded.
10
11    #[serde(rename = "SUCCESS")]
12    Success,
13    /// Transaction failed.
14
15    #[serde(rename = "FAILED")]
16    Failed,
17    /// Transaction has been initiated and is currently in-flight.
18
19    #[serde(rename = "PENDING")]
20    Pending,
21    /// For transaction type PAYMENT_REQUEST only. No payments have been made to a payment request.
22
23    #[serde(rename = "NOT_STARTED")]
24    NotStarted,
25    /// For transaction type PAYMENT_REQUEST only. A payment request has expired.
26
27    #[serde(rename = "EXPIRED")]
28    Expired,
29    /// For transaction type PAYMENT_REQUEST only.
30
31    #[serde(rename = "CANCELLED")]
32    Cancelled,
33}
34
35impl From<TransactionStatus> for Value {
36    fn from(val: TransactionStatus) -> Self {
37        Value::from(val.to_string())
38    }
39}
40
41impl fmt::Display for TransactionStatus {
42    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
43        match self {
44            Self::Success => write!(f, "SUCCESS"),
45            Self::Failed => write!(f, "FAILED"),
46            Self::Pending => write!(f, "PENDING"),
47            Self::NotStarted => write!(f, "NOT_STARTED"),
48            Self::Expired => write!(f, "EXPIRED"),
49            Self::Cancelled => write!(f, "CANCELLED"),
50        }
51    }
52}