lightspark/objects/
incoming_payment_attempt.rs

1// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2use crate::objects::currency_amount::CurrencyAmount;
3use crate::objects::entity::Entity;
4use crate::objects::incoming_payment_attempt_status::IncomingPaymentAttemptStatus;
5use crate::types::custom_date_formats::custom_date_format;
6use crate::types::custom_date_formats::custom_date_format_option;
7use crate::types::entity_wrapper::EntityWrapper;
8use crate::types::get_entity::GetEntity;
9use chrono::{DateTime, Utc};
10use serde::{Deserialize, Serialize};
11
12/// This object represents any attempted payment sent to a Lightspark node on the Lightning Network. You can retrieve this object to receive payment related information about a specific incoming payment attempt.
13#[derive(Debug, Clone, Deserialize, Serialize)]
14pub struct IncomingPaymentAttempt {
15    /// The unique identifier of this entity across all Lightspark systems. Should be treated as an opaque string.
16    #[serde(rename = "incoming_payment_attempt_id")]
17    pub id: String,
18
19    /// The date and time when the entity was first created.
20    #[serde(
21        with = "custom_date_format",
22        rename = "incoming_payment_attempt_created_at"
23    )]
24    pub created_at: DateTime<Utc>,
25
26    /// The date and time when the entity was last updated.
27    #[serde(
28        with = "custom_date_format",
29        rename = "incoming_payment_attempt_updated_at"
30    )]
31    pub updated_at: DateTime<Utc>,
32
33    /// The status of the incoming payment attempt.
34    #[serde(rename = "incoming_payment_attempt_status")]
35    pub status: IncomingPaymentAttemptStatus,
36
37    /// The time the incoming payment attempt failed or succeeded.
38    #[serde(
39        with = "custom_date_format_option",
40        rename = "incoming_payment_attempt_resolved_at"
41    )]
42    pub resolved_at: Option<DateTime<Utc>>,
43
44    /// The total amount of that was attempted to send.
45    #[serde(rename = "incoming_payment_attempt_amount")]
46    pub amount: CurrencyAmount,
47
48    /// The channel this attempt was made on.
49    #[serde(rename = "incoming_payment_attempt_channel")]
50    pub channel: EntityWrapper,
51
52    /// The typename of the object
53    #[serde(rename = "__typename")]
54    pub typename: String,
55}
56
57impl Entity for IncomingPaymentAttempt {
58    /// The unique identifier of this entity across all Lightspark systems. Should be treated as an opaque string.
59    fn get_id(&self) -> String {
60        self.id.clone()
61    }
62
63    /// The date and time when the entity was first created.
64    fn get_created_at(&self) -> DateTime<Utc> {
65        self.created_at
66    }
67
68    /// The date and time when the entity was last updated.
69    fn get_updated_at(&self) -> DateTime<Utc> {
70        self.updated_at
71    }
72
73    fn type_name(&self) -> &'static str {
74        "IncomingPaymentAttempt"
75    }
76}
77
78impl GetEntity for IncomingPaymentAttempt {
79    fn get_entity_query() -> String {
80        format!(
81            "
82        query GetEntity($id: ID!) {{
83            entity(id: $id) {{
84                ... on IncomingPaymentAttempt {{
85                    ... IncomingPaymentAttemptFragment
86                }}
87            }}
88        }}
89
90        {}",
91            FRAGMENT
92        )
93    }
94}
95
96pub const FRAGMENT: &str = "
97fragment IncomingPaymentAttemptFragment on IncomingPaymentAttempt {
98    __typename
99    incoming_payment_attempt_id: id
100    incoming_payment_attempt_created_at: created_at
101    incoming_payment_attempt_updated_at: updated_at
102    incoming_payment_attempt_status: status
103    incoming_payment_attempt_resolved_at: resolved_at
104    incoming_payment_attempt_amount: amount {
105        __typename
106        currency_amount_original_value: original_value
107        currency_amount_original_unit: original_unit
108        currency_amount_preferred_currency_unit: preferred_currency_unit
109        currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
110        currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
111    }
112    incoming_payment_attempt_channel: channel {
113        id
114    }
115}
116";