Skip to main content

brevo_rust/api/types/
transaction.rs

1pub use crate::prelude::*;
2
3/// Represents a transaction involving a balance, including status and timestamps.
4#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
5pub struct Transaction {
6    /// Unique identifier (UUID) of the transaction.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub id: Option<String>,
9    /// The transaction amount.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    #[serde(default)]
12    #[serde(with = "crate::core::number_serializers::option")]
13    pub amount: Option<f64>,
14    /// The contact's total balance for this balance definition after the transaction was applied. Only returned when the transaction actually updated the balance (i.e. it was completed or auto-completed).
15    #[serde(skip_serializing_if = "Option::is_none")]
16    #[serde(default)]
17    #[serde(with = "crate::core::number_serializers::option")]
18    pub balance: Option<f64>,
19    /// The type of the transaction.
20    #[serde(rename = "transactionType")]
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub transaction_type: Option<TransactionTransactionType>,
23    /// Optional metadata associated with the transaction.
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub meta: Option<HashMap<String, serde_json::Value>>,
26    /// The current status of the transaction.
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub status: Option<TransactionStatus>,
29    /// Unique identifier (UUID) of the associated loyalty program.
30    #[serde(rename = "loyaltyProgramId")]
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub loyalty_program_id: Option<String>,
33    /// Unique identifier (UUID) of the associated balance definition.
34    #[serde(rename = "balanceDefinitionId")]
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub balance_definition_id: Option<String>,
37    /// Unique identifier of the contact associated with the transaction.
38    #[serde(rename = "contactId")]
39    #[serde(skip_serializing_if = "Option::is_none")]
40    pub contact_id: Option<i64>,
41    /// Optional timestamp indicating when the transaction event occurred (ISO 8601 format).
42    #[serde(rename = "eventTime")]
43    #[serde(skip_serializing_if = "Option::is_none")]
44    #[serde(default)]
45    #[serde(with = "crate::core::flexible_datetime::offset::option")]
46    pub event_time: Option<DateTime<FixedOffset>>,
47    /// Reason for rejection if the transaction was declined (nullable).
48    #[serde(rename = "rejectReason")]
49    #[serde(skip_serializing_if = "Option::is_none")]
50    pub reject_reason: Option<String>,
51    /// Timestamp when the transaction was rejected (nullable).
52    #[serde(rename = "rejectedAt")]
53    #[serde(skip_serializing_if = "Option::is_none")]
54    #[serde(default)]
55    #[serde(with = "crate::core::flexible_datetime::offset::option")]
56    pub rejected_at: Option<DateTime<FixedOffset>>,
57    /// Expiry date of the transaction (nullable).
58    #[serde(rename = "expirationDate")]
59    #[serde(skip_serializing_if = "Option::is_none")]
60    #[serde(default)]
61    #[serde(with = "crate::core::flexible_datetime::offset::option")]
62    pub expiration_date: Option<DateTime<FixedOffset>>,
63    /// Timestamp when the transaction was completed (nullable).
64    #[serde(rename = "completedAt")]
65    #[serde(skip_serializing_if = "Option::is_none")]
66    #[serde(default)]
67    #[serde(with = "crate::core::flexible_datetime::offset::option")]
68    pub completed_at: Option<DateTime<FixedOffset>>,
69    /// Timestamp when the transaction was canceled (nullable).
70    #[serde(rename = "cancelledAt")]
71    #[serde(skip_serializing_if = "Option::is_none")]
72    #[serde(default)]
73    #[serde(with = "crate::core::flexible_datetime::offset::option")]
74    pub cancelled_at: Option<DateTime<FixedOffset>>,
75    /// Timestamp when the transaction was created.
76    #[serde(rename = "createdAt")]
77    #[serde(skip_serializing_if = "Option::is_none")]
78    #[serde(default)]
79    #[serde(with = "crate::core::flexible_datetime::offset::option")]
80    pub created_at: Option<DateTime<FixedOffset>>,
81    /// Timestamp when the transaction was last updated.
82    #[serde(rename = "updatedAt")]
83    #[serde(skip_serializing_if = "Option::is_none")]
84    #[serde(default)]
85    #[serde(with = "crate::core::flexible_datetime::offset::option")]
86    pub updated_at: Option<DateTime<FixedOffset>>,
87}
88
89impl Transaction {
90    pub fn builder() -> TransactionBuilder {
91        <TransactionBuilder as Default>::default()
92    }
93}
94
95#[derive(Clone, PartialEq, Default, Debug)]
96#[non_exhaustive]
97pub struct TransactionBuilder {
98    id: Option<String>,
99    amount: Option<f64>,
100    balance: Option<f64>,
101    transaction_type: Option<TransactionTransactionType>,
102    meta: Option<HashMap<String, serde_json::Value>>,
103    status: Option<TransactionStatus>,
104    loyalty_program_id: Option<String>,
105    balance_definition_id: Option<String>,
106    contact_id: Option<i64>,
107    event_time: Option<DateTime<FixedOffset>>,
108    reject_reason: Option<String>,
109    rejected_at: Option<DateTime<FixedOffset>>,
110    expiration_date: Option<DateTime<FixedOffset>>,
111    completed_at: Option<DateTime<FixedOffset>>,
112    cancelled_at: Option<DateTime<FixedOffset>>,
113    created_at: Option<DateTime<FixedOffset>>,
114    updated_at: Option<DateTime<FixedOffset>>,
115}
116
117impl TransactionBuilder {
118    pub fn id(mut self, value: impl Into<String>) -> Self {
119        self.id = Some(value.into());
120        self
121    }
122
123    pub fn amount(mut self, value: f64) -> Self {
124        self.amount = Some(value);
125        self
126    }
127
128    pub fn balance(mut self, value: f64) -> Self {
129        self.balance = Some(value);
130        self
131    }
132
133    pub fn transaction_type(mut self, value: TransactionTransactionType) -> Self {
134        self.transaction_type = Some(value);
135        self
136    }
137
138    pub fn meta(mut self, value: HashMap<String, serde_json::Value>) -> Self {
139        self.meta = Some(value);
140        self
141    }
142
143    pub fn status(mut self, value: TransactionStatus) -> Self {
144        self.status = Some(value);
145        self
146    }
147
148    pub fn loyalty_program_id(mut self, value: impl Into<String>) -> Self {
149        self.loyalty_program_id = Some(value.into());
150        self
151    }
152
153    pub fn balance_definition_id(mut self, value: impl Into<String>) -> Self {
154        self.balance_definition_id = Some(value.into());
155        self
156    }
157
158    pub fn contact_id(mut self, value: i64) -> Self {
159        self.contact_id = Some(value);
160        self
161    }
162
163    pub fn event_time(mut self, value: DateTime<FixedOffset>) -> Self {
164        self.event_time = Some(value);
165        self
166    }
167
168    pub fn reject_reason(mut self, value: impl Into<String>) -> Self {
169        self.reject_reason = Some(value.into());
170        self
171    }
172
173    pub fn rejected_at(mut self, value: DateTime<FixedOffset>) -> Self {
174        self.rejected_at = Some(value);
175        self
176    }
177
178    pub fn expiration_date(mut self, value: DateTime<FixedOffset>) -> Self {
179        self.expiration_date = Some(value);
180        self
181    }
182
183    pub fn completed_at(mut self, value: DateTime<FixedOffset>) -> Self {
184        self.completed_at = Some(value);
185        self
186    }
187
188    pub fn cancelled_at(mut self, value: DateTime<FixedOffset>) -> Self {
189        self.cancelled_at = Some(value);
190        self
191    }
192
193    pub fn created_at(mut self, value: DateTime<FixedOffset>) -> Self {
194        self.created_at = Some(value);
195        self
196    }
197
198    pub fn updated_at(mut self, value: DateTime<FixedOffset>) -> Self {
199        self.updated_at = Some(value);
200        self
201    }
202
203    /// Consumes the builder and constructs a [`Transaction`].
204    pub fn build(self) -> Result<Transaction, BuildError> {
205        Ok(Transaction {
206            id: self.id,
207            amount: self.amount,
208            balance: self.balance,
209            transaction_type: self.transaction_type,
210            meta: self.meta,
211            status: self.status,
212            loyalty_program_id: self.loyalty_program_id,
213            balance_definition_id: self.balance_definition_id,
214            contact_id: self.contact_id,
215            event_time: self.event_time,
216            reject_reason: self.reject_reason,
217            rejected_at: self.rejected_at,
218            expiration_date: self.expiration_date,
219            completed_at: self.completed_at,
220            cancelled_at: self.cancelled_at,
221            created_at: self.created_at,
222            updated_at: self.updated_at,
223        })
224    }
225}