Skip to main content

lago_types/models/
payment.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4use strum_macros::EnumString;
5use uuid::Uuid;
6
7/// Represents a payment in the Lago billing system.
8///
9/// A payment records a monetary transaction associated with an invoice
10/// or payment request.
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct Payment {
13    /// Unique identifier for the payment in Lago.
14    pub lago_id: Uuid,
15    /// Unique identifier of the customer in Lago.
16    pub lago_customer_id: Uuid,
17    /// The customer external unique identifier.
18    pub external_customer_id: String,
19    /// List of invoice IDs associated with the payment.
20    pub invoice_ids: Vec<Uuid>,
21    /// The unique identifier of the paid resource in Lago.
22    pub lago_payable_id: Uuid,
23    /// The type of the paid resource (Invoice or PaymentRequest).
24    pub payable_type: PayableType,
25    /// The amount of the payment in cents.
26    pub amount_cents: i64,
27    /// The currency of the payment amount.
28    pub amount_currency: String,
29    /// The status of the payment within the payment provider.
30    pub status: String,
31    /// The normalized payment status by Lago.
32    pub payment_status: PaymentStatus,
33    /// The type of payment (manual or provider).
34    #[serde(rename = "type")]
35    pub payment_type: PaymentType,
36    /// Reference for the payment.
37    pub reference: Option<String>,
38    /// Code of the payment provider.
39    pub payment_provider_code: Option<String>,
40    /// The type of payment provider.
41    pub payment_provider_type: Option<PaymentProviderType>,
42    /// DEPRECATED: use provider_payment_id.
43    pub external_payment_id: Option<String>,
44    /// Unique identifier of the payment within the payment provider.
45    pub provider_payment_id: Option<String>,
46    /// Unique identifier of the customer within the payment provider.
47    pub provider_customer_id: Option<String>,
48    /// The next action to be taken by the customer to complete the payment.
49    pub next_action: Option<Value>,
50    /// When the payment was created.
51    pub created_at: DateTime<Utc>,
52}
53
54/// The type of the paid resource.
55#[derive(Debug, Clone, Serialize, Deserialize, EnumString, PartialEq, Eq)]
56pub enum PayableType {
57    /// An invoice payment.
58    Invoice,
59    /// A payment request.
60    PaymentRequest,
61}
62
63/// The normalized payment status by Lago.
64#[derive(Debug, Clone, Serialize, Deserialize, EnumString, PartialEq, Eq)]
65#[serde(rename_all = "snake_case")]
66#[strum(serialize_all = "snake_case")]
67pub enum PaymentStatus {
68    /// Payment succeeded.
69    Succeeded,
70    /// Payment failed.
71    Failed,
72    /// Payment is pending.
73    Pending,
74    /// Payment is being processed.
75    Processing,
76}
77
78/// The type of payment.
79#[derive(Debug, Clone, Serialize, Deserialize, EnumString, PartialEq, Eq)]
80#[serde(rename_all = "snake_case")]
81#[strum(serialize_all = "snake_case")]
82pub enum PaymentType {
83    /// Manual payment.
84    Manual,
85    /// Payment through a provider.
86    Provider,
87}
88
89/// The type of payment provider.
90#[derive(Debug, Clone, Serialize, Deserialize, EnumString, PartialEq, Eq)]
91#[serde(rename_all = "snake_case")]
92#[strum(serialize_all = "snake_case")]
93pub enum PaymentProviderType {
94    /// Adyen payment provider.
95    #[serde(alias = "PaymentProviders::AdyenProvider")]
96    Adyen,
97    /// Cashfree payment provider.
98    #[serde(alias = "PaymentProviders::CashfreeProvider")]
99    Cashfree,
100    /// GoCardless payment provider.
101    #[serde(alias = "PaymentProviders::GocardlessProvider")]
102    Gocardless,
103    /// Stripe payment provider.
104    #[serde(alias = "PaymentProviders::StripeProvider")]
105    Stripe,
106    /// Flutterwave payment provider.
107    #[serde(alias = "PaymentProviders::FlutterwaveProvider")]
108    Flutterwave,
109    /// MoneyHash payment provider.
110    #[serde(alias = "PaymentProviders::MoneyhashProvider")]
111    Moneyhash,
112}