paystack/models/transactions.rs
1//! Transactions Models
2//! ====================
3//! This file contains the models for working with the transactions endpoint.
4use crate::{Authorization, Channel, Currency, Customer, MetaData, SubaccountData};
5use derive_builder::Builder;
6use serde::{Deserialize, Serialize};
7
8/// This struct is used to create a transaction body for creating a transaction using the Paystack API.
9/// This struct should be created using the `InitializeTransactionBodyBuilder`
10/// The Builder derivation allows for the automatic implementation of the builder pattern.
11#[derive(Serialize, Debug, Default, Builder)]
12pub struct InitializeTransactionBody {
13 /// Amount should be in the smallest unit of the currency e.g. kobo if in NGN and cents if in USD
14 amount: String,
15 /// Customer's email address
16 email: String,
17 /// Currency in which amount should be charged (NGN, GHS, ZAR or USD). Defaults to your integration currency.
18 #[builder(default = "None")]
19 currency: Option<Currency>,
20 /// Unique transaction reference. Only -, ., = and alphanumeric characters allowed.
21 #[builder(default = "None")]
22 reference: Option<String>,
23 /// Fully qualified url, e.g. https://example.com/ . Use this to override the callback url provided on the dashboard for this transaction
24 #[builder(default = "None")]
25 callback_url: Option<String>,
26 /// If transaction is to create a subscription to a predefined plan, provide plan code here. This would invalidate the value provided in `amount`
27 #[builder(default = "None")]
28 plan: Option<String>,
29 /// Number of times to charge customer during subscription to plan
30 #[builder(default = "None")]
31 invoice_limit: Option<u32>,
32 /// Stringified JSON object of custom data. Kindly check the `Metadata` struct for more information.
33 #[builder(default = "None")]
34 metadata: Option<String>,
35 /// An array of payment channels to control what channels you want to make available to the user to make a payment with.
36 /// Available channels include: `["card", "bank", "ussd", "qr", "mobile_money", "bank_transfer", "eft"]`
37 #[builder(default = "None")]
38 channels: Option<Vec<Channel>>,
39 /// The split code of the transaction split. e.g. `SPL_98WF13Eb3w`
40 #[builder(default = "None")]
41 split_code: Option<String>,
42 /// The code for the subaccount that owns the payment. e.g. `ACCT_8f4s1eq7ml6rlzj`
43 #[builder(default = "None")]
44 subaccount: Option<String>,
45 /// An amount used to override the split configuration for a single split payment.
46 /// If set, the amount specified goes to the main account regardless of the split configuration.
47 #[builder(default = "None")]
48 transaction_charge: Option<u32>,
49 /// Who bears Paystack charges? `account` or `subaccount` (defaults to account).
50 #[builder(default = "None")]
51 bearer: Option<String>,
52}
53
54/// This struct is used to create a partial debit transaction body for creating a partial debit using the Paystack API.
55/// This struct should be created using the `PartialDebitTransactionBodyBuilder`
56/// The derive Builder allows for the automatic creation of the BuilderPattern
57#[derive(Debug, Clone, Serialize, Default, Builder)]
58pub struct PartialDebitTransactionBody {
59 /// Authorization Code
60 authorization_code: String,
61 /// Specify the currency you want to debit. Allowed values are NGN or GHS.
62 currency: Currency,
63 /// Amount should be in the subunit of the supported currency
64 amount: String,
65 /// Customer's email address (attached to the authorization code)
66 email: String,
67 /// Unique transaction reference. Only `-`, `.`, `=` and alphanumeric characters allowed.
68 #[builder(default = "None")]
69 reference: Option<String>,
70 /// Minimum amount to charge
71 #[builder(default = "None")]
72 at_least: Option<String>,
73}
74
75/// This struct represents the response of the Paystack transaction initialization.
76#[derive(Deserialize, Debug, Clone)]
77pub struct TransactionResponse {
78 /// This lets you know if your request was successful or not.
79 pub status: bool,
80 /// This is a summary of the response and its status.
81 pub message: String,
82 /// This contains the results of your request.
83 pub data: TransactionResponseData,
84}
85
86/// This struct represents the data of the transaction response.
87#[derive(Deserialize, Debug, Clone)]
88pub struct TransactionResponseData {
89 /// Generated URL to authorize the transaction.
90 pub authorization_url: String,
91 /// Access code of the transaction.
92 pub access_code: String,
93 /// Reference of the transaction.
94 pub reference: String,
95}
96
97/// This struct represents the transaction status response.
98#[derive(Deserialize, Debug, Clone)]
99pub struct TransactionStatusResponse {
100 /// This lets you know if your request was successful or not.
101 pub status: bool,
102 /// This is a summary of the response and its status.
103 pub message: String,
104 /// This contains the results of your request.
105 /// In this case, it is a single object.
106 pub data: TransactionStatusData,
107}
108
109/// This struct represents the data of the transaction status response.
110#[derive(Deserialize, Serialize, Debug, Clone)]
111pub struct TransactionStatusData {
112 /// Id of the Transaction
113 pub id: Option<u32>,
114 /// Status of the Transaction. It can be `success`, `abandoned` or `failed`
115 pub status: Option<String>,
116 /// Reference of the Transaction
117 pub reference: Option<String>,
118 /// Amount of the transaction in the lowest denomination of the currency e.g. Kobo for NGN and cent for USD.
119 pub amount: Option<u32>,
120 /// Message from the transaction.
121 pub message: Option<String>,
122 /// Response from the payment gateway.
123 pub gateway_response: Option<String>,
124 /// Time the Transaction was completed.
125 pub paid_at: Option<String>,
126 /// Time the Transaction was created.
127 pub created_at: Option<String>,
128 /// Transaction channel. It can be `card` or `bank`.
129 pub channel: Option<String>,
130 /// Currency code of the Transaction e.g. `NGN for Nigerian Naira` and `USD for US Dollar`.
131 pub currency: Option<String>,
132 /// IP address of the computers the Transaction has passed through.
133 pub ip_address: Option<String>,
134 /// Meta data associated with the Transaction.
135 pub metadata: Option<String>,
136 /// Transaction fees to override the default fees specified in the integration.
137 pub fees: Option<i32>,
138 /// Transaction customer data.
139 pub customer: Option<Customer>,
140 /// Transaction authorization data.
141 pub authorization: Option<Authorization>,
142}
143
144/// Represents the response of the total amount received on your account
145#[derive(Debug, Deserialize, Serialize)]
146pub struct TransactionTotalsResponse {
147 /// This lets you know if your request was successful or not.
148 pub status: bool,
149 /// This is a summary of the response and its status.
150 pub message: String,
151 /// This contains the results of your request.
152 pub data: TransactionTotalData,
153}
154
155/// Transaction total data.
156#[derive(Debug, Deserialize, Serialize)]
157pub struct TransactionTotalData {
158 /// Total number of transactions in the integration.
159 pub total_transactions: Option<u32>,
160 /// Total of unique number of customers in the integration.
161 pub unique_customers: Option<u32>,
162 /// Total volume of transaction in the integration.
163 pub total_volume: Option<u32>,
164 /// Total volume of transaction broken down by currency.
165 pub total_volume_by_currency: Option<Vec<VolumeByCurrency>>,
166 /// Total volume of pending transfers.
167 pub pending_transfers: Option<u32>,
168 /// Total volume of pending transfer broken down by currency.
169 pub pending_transfers_by_currency: Option<Vec<VolumeByCurrency>>,
170}
171
172/// Transaction volume by currency.
173#[derive(Debug, Deserialize, Serialize)]
174pub struct VolumeByCurrency {
175 /// Currency code.
176 pub currency: String,
177 /// Amount in the lowest denomination of the currency.
178 pub amount: u32,
179}
180
181/// Represents the response of the export transaction.
182#[derive(Debug, Serialize, Deserialize)]
183pub struct ExportTransactionResponse {
184 /// This lets you know if your request was successful or not.
185 pub status: bool,
186 /// This is a summary of the response and its status.
187 pub message: String,
188 /// This contains the results of your request.
189 pub data: ExportTransactionData,
190}
191
192/// Export transaction response data.
193#[derive(Debug, Serialize, Deserialize)]
194pub struct ExportTransactionData {
195 /// Path to download the exported transaction file.
196 pub path: String,
197}
198
199/// Represents the response of the partial debit transaction.
200#[derive(Debug, Deserialize, Serialize)]
201pub struct PartialDebitTransactionResponse {
202 /// This lets you know if your request was successful or not.
203 pub status: bool,
204 /// This is a summary of the response and its status.
205 pub message: String,
206 /// This contains the results of your request.
207 pub data: TransactionStatusData,
208}
209
210/// Represents the JSON response containing percentage split information.
211#[derive(Debug, Deserialize, Serialize)]
212pub struct TransactionSplitResponse {
213 /// The status of the JSON response.
214 pub status: bool,
215 /// The message associated with the JSON response.
216 pub message: String,
217 /// The percentage split data.
218 pub data: SplitData,
219}
220
221/// Represents the percentage split data received in the JSON response.
222#[derive(Debug, Deserialize, Serialize)]
223pub struct SplitData {
224 /// The ID of the percentage split.
225 pub id: u32,
226 /// The name of the percentage split.
227 pub name: String,
228 /// The type of the percentage split.
229 #[serde(rename = "type")]
230 pub split_type: String,
231 /// The currency used for the percentage split.
232 pub currency: String,
233 /// The integration associated with the percentage split.
234 pub integration: u32,
235 /// The domain associated with the percentage split.
236 pub domain: String,
237 /// The split code of the percentage split.
238 pub split_code: String,
239 /// Indicates whether the percentage split is active or not.
240 pub active: Option<bool>,
241 /// The bearer type of the percentage split.
242 pub bearer_type: String,
243 /// The subaccount ID of the bearer associated with the percentage split.
244 pub bearer_subaccount: u32,
245 /// The creation timestamp of the percentage split.
246 pub created_at: Option<String>,
247 /// The last update timestamp of the percentage split.
248 pub updated_at: Option<String>,
249 /// The list of sub accounts involved in the percentage split.
250 pub subaccounts: Vec<SubaccountData>,
251 /// The total count of subaccounts in the percentage split.
252 pub total_subaccounts: u32,
253}
254
255/// Represents the JSON response containing percentage split information.
256#[derive(Debug, Deserialize, Serialize)]
257pub struct TransactionSplitListResponse {
258 /// The status of the JSON response.
259 pub status: bool,
260 /// The message associated with the JSON response.
261 pub message: String,
262 /// The percentage split data.
263 pub data: Vec<SplitData>,
264}
265
266/// This struct represents a list of transaction status.
267#[derive(Deserialize, Serialize, Debug, Clone)]
268pub struct TransactionStatusListResponse {
269 /// This lets you know if your request was successful or not.
270 pub status: bool,
271 /// This is a summary of the response and its status.
272 pub message: String,
273 /// This contains the results of your request.
274 /// In this case, it is a vector of objects.
275 pub data: Vec<TransactionStatusData>,
276 /// The meta key is used to provide context for the contents of the data key.
277 pub meta: MetaData,
278}
279
280/// This struct represents the transaction timeline.
281#[derive(Deserialize, Serialize, Debug, Clone)]
282pub struct TransactionTimelineResponse {
283 /// This lets you know if your request was successful or not.
284 pub status: bool,
285 /// This is a summary of the response and its status.
286 pub message: String,
287 /// This contains the results of your request.
288 pub data: TransactionTimelineData,
289}
290
291/// This struct represents the transaction timeline data.
292#[derive(Deserialize, Serialize, Debug, Clone)]
293pub struct TransactionTimelineData {
294 /// Time spent in carrying out the transaction in ms.
295 pub time_spent: Option<u32>,
296 /// Number of attempts for the transaction.
297 pub attempts: Option<u32>,
298 /// Authentication use for the transaction.
299 pub authentication: Option<String>,
300 /// Number of errors for the transaction.
301 pub errors: Option<u32>,
302 /// Success status of the transaction.
303 pub success: Option<bool>,
304 /// If transaction was carried out with mobile.
305 pub mobile: Option<bool>,
306 /// Transaction inputs i.e. messages associated with the transaction.
307 pub input: Option<String>,
308 /// Transaction channel.
309 pub channel: Option<String>,
310 /// Transaction history.
311 pub history: Option<Vec<TransactionHistoryResponse>>,
312}
313
314/// This struct represents the transaction history data
315#[derive(Deserialize, Serialize, Debug, Clone)]
316pub struct TransactionHistoryResponse {
317 /// Transaction action.
318 #[serde(rename = "type")]
319 pub action_type: String,
320 /// Description of the action.
321 pub message: String,
322 /// Time action was taken in ms.
323 pub time: u32,
324}