1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
//! Response
//! ==========
//! This file contains the structs needed to represent the different response
//! of the Paystack API.

use serde::{Deserialize, Serialize};

/// This struct represents the response of the Paystack transaction initialization.
#[derive(Deserialize, Debug, Clone)]
pub struct TransactionResponse {
    /// This lets you know if your request was successful or not.
    pub status: bool,
    /// This is a summary of the response and its status.
    pub message: String,
    /// This contains the results of your request.
    pub data: TransactionResponseData,
}

/// This struct represents the data of the transaction response.
#[derive(Deserialize, Debug, Clone)]
pub struct TransactionResponseData {
    /// Generated URL to authorize the transaction.
    pub authorization_url: String,
    /// Access code of the transaction.
    pub access_code: String,
    /// Reference of the transaction.
    pub reference: String,
}

/// This struct represents the transaction status response.
#[derive(Deserialize, Debug, Clone)]
pub struct TransactionStatus {
    /// This lets you know if your request was successful or not.
    pub status: bool,
    /// This is a summary of the response and its status.
    pub message: String,
    /// This contains the results of your request.
    /// In this case, it is a single object.
    pub data: TransactionStatusData,
}

/// This struct represents a list of transaction status.
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct TransactionStatusList {
    /// This lets you know if your request was successful or not.
    pub status: bool,
    /// This is a summary of the response and its status.
    pub message: String,
    /// This contains the results of your request.
    /// In this case, it is a vector of objects.
    pub data: Vec<TransactionStatusData>,
    /// The meta key is used to provide context for the contents of the data key.
    pub meta: MetaData,
}

/// This struct represents the transaction timeline.
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct TransactionTimeline {
    /// This lets you know if your request was successful or not.
    pub status: bool,
    /// This is a summary of the response and its status.
    pub message: String,
    /// This contains the results of your request.
    pub data: TransactionTimelineData,
}

/// This struct represents the transaction timeline data.
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct TransactionTimelineData {
    /// Time spent in carrying out the transaction in ms.
    pub time_spent: Option<u32>,
    /// Number of attempts for the transaction.
    pub attempts: Option<u32>,
    /// Authentication use for the transaction.
    pub authentication: Option<String>,
    /// Number of errors for the transaction.
    pub errors: Option<u32>,
    /// Success status of the transaction.
    pub success: Option<bool>,
    /// If transaction was carried out with mobile.
    pub mobile: Option<bool>,
    /// Transaction inputs i.e. messages associated with the transaction.
    pub input: Option<String>,
    /// Transaction channel.
    pub channel: Option<String>,
    /// Transaction history.
    pub history: Option<Vec<TransactionHistory>>,
}

/// This struct represents the transaction history data
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct TransactionHistory {
    /// Transaction action.
    #[serde(rename = "type")]
    pub action_type: String,
    /// Description of the action.
    pub message: String,
    /// Time action was taken in ms.
    pub time: u32,
}

/// This struct represents the data of the transaction status response.
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct TransactionStatusData {
    /// Id of the Transaction
    pub id: Option<u32>,
    /// Status of the Transaction. It can be `success`, `abandoned` or `failed`
    pub status: Option<String>,
    /// Reference of the Transaction
    pub reference: Option<String>,
    /// Amount of the transaction in the lowest denomination of the currency e.g. Kobo for NGN and cent for USD.
    pub amount: Option<u32>,
    /// Message from the transaction.
    pub message: Option<String>,
    /// Response from the payment gateway.
    pub gateway_response: Option<String>,
    /// Time the Transaction was completed.
    pub paid_at: Option<String>,
    /// Time the Transaction was created.
    pub created_at: Option<String>,
    /// Transaction channel. It can be `card` or `bank`.
    pub channel: Option<String>,
    /// Currency code of the Transaction e.g. `NGN for Nigerian Naira` and `USD for US Dollar`.
    pub currency: Option<String>,
    /// IP address of the computers the Transaction has passed through.
    pub ip_address: Option<String>,
    /// Meta data associated with the Transaction.
    pub metadata: Option<String>,
    /// Transaction fees to override the default fees specified in the integration.
    pub fees: Option<i32>,
    /// Transaction customer data.
    pub customer: Option<Customer>,
    /// Transaction authorization data.
    pub authorization: Option<Authorization>,
}

/// This struct represents the authorization data of the transaction status response
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Authorization {
    /// Authorization code generated for the Transaction.
    pub authorization_code: Option<String>,
    /// Bin number for Transaction authorization.
    pub bin: Option<String>,
    /// Last 4 digits of authorized card.
    pub last4: Option<String>,
    /// Authorized card expiry month.
    pub exp_month: Option<String>,
    /// Authorized card expiry year.
    pub exp_year: Option<String>,
    /// Authorization channel. It could be `card` or `bank`.
    pub channel: Option<String>,
    /// Type of card used in the Authorization
    pub card_type: Option<String>,
    /// Name of bank associated with the Authorization.
    pub bank: Option<String>,
    /// Country code of the Authorization.
    pub country_code: Option<String>,
    /// Brand of of the Authorization if it is a card.
    pub brand: Option<String>,
    /// Specifies if the Authorization is reusable.
    pub reusable: Option<bool>,
    /// Signature of the Authorization.
    pub signature: Option<String>,
    /// Name of the account associated with the authorization.
    pub account_name: Option<String>,
}

/// This struct represents the Paystack customer data
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Customer {
    /// Customer's Id.
    pub id: Option<u32>,
    /// Customer's first name.
    pub first_name: Option<String>,
    /// Customer's last name.
    pub last_name: Option<String>,
    /// Customer's email address.
    pub email: Option<String>,
    /// Customer's code.
    pub customer_code: String,
    /// Customer's phone number.
    pub phone: Option<String>,
    /// Customer's metadata.
    pub metadata: Option<String>,
    /// Customer's risk action.
    pub risk_action: Option<String>,
    /// Customer's phone number in international format.
    pub international_format_phone: Option<String>,
}

/// Represents the response of the total amount received on your account
#[derive(Debug, Deserialize, Serialize)]
pub struct TransactionTotalsResponse {
    /// This lets you know if your request was successful or not.
    pub status: bool,
    /// This is a summary of the response and its status.
    pub message: String,
    /// This contains the results of your request.
    pub data: TransactionTotalData,
}

/// Transaction total data.
#[derive(Debug, Deserialize, Serialize)]
pub struct TransactionTotalData {
    /// Total number of transactions in the integration.
    pub total_transactions: Option<u32>,
    /// Total of unique number of customers in the integration.
    pub unique_customers: Option<u32>,
    /// Total volume of transaction in the integration.
    pub total_volume: Option<u32>,
    /// Total volume of transaction broken down by currency.
    pub total_volume_by_currency: Option<Vec<VolumeByCurrency>>,
    /// Total volume of pending transfers.
    pub pending_transfers: Option<u32>,
    /// Total volume of pending transfer broken down by currency.
    pub pending_transfers_by_currency: Option<Vec<VolumeByCurrency>>,
}

/// Transaction volume by currency.
#[derive(Debug, Deserialize, Serialize)]
pub struct VolumeByCurrency {
    /// Currency code.
    pub currency: String,
    /// Amount in the lowest denomination of the currency.
    pub amount: u32,
}

/// Represents the response of the export transaction.
#[derive(Debug, Serialize, Deserialize)]
pub struct ExportTransactionResponse {
    /// This lets you know if your request was successful or not.
    pub status: bool,
    /// This is a summary of the response and its status.
    pub message: String,
    /// This contains the results of your request.
    pub data: ExportTransactionData,
}

/// Export transaction response data.
#[derive(Debug, Serialize, Deserialize)]
pub struct ExportTransactionData {
    /// Path to download the exported transaction file.
    pub path: String,
}

/// Represents the response of the partial debit transaction.
#[derive(Debug, Deserialize, Serialize)]
pub struct PartialDebitTransactionResponse {
    /// This lets you know if your request was successful or not.
    pub status: bool,
    /// This is a summary of the response and its status.
    pub message: String,
    /// This contains the results of your request.
    pub data: TransactionStatusData,
}

/// Represents the JSON response containing percentage split information.
#[derive(Debug, Deserialize, Serialize)]
pub struct TransactionSplitResponse {
    /// The status of the JSON response.
    pub status: bool,
    /// The message associated with the JSON response.
    pub message: String,
    /// The percentage split data.
    pub data: SplitData,
}

/// Represents the percentage split data received in the JSON response.
#[derive(Debug, Deserialize, Serialize)]
pub struct SplitData {
    /// The ID of the percentage split.
    pub id: u32,
    /// The name of the percentage split.
    pub name: String,
    /// The type of the percentage split.
    #[serde(rename = "type")]
    pub split_type: String,
    /// The currency used for the percentage split.
    pub currency: String,
    /// The integration associated with the percentage split.
    pub integration: u32,
    /// The domain associated with the percentage split.
    pub domain: String,
    /// The split code of the percentage split.
    pub split_code: String,
    /// Indicates whether the percentage split is active or not.
    pub active: Option<bool>,
    /// The bearer type of the percentage split.
    pub bearer_type: String,
    /// The subaccount ID of the bearer associated with the percentage split.
    pub bearer_subaccount: u32,
    /// The creation timestamp of the percentage split.
    pub created_at: String,
    /// The last update timestamp of the percentage split.
    pub updated_at: String,
    /// The list of sub accounts involved in the percentage split.
    pub subaccounts: Vec<SubaccountData>,
    /// The total count of subaccounts in the percentage split.
    pub total_subaccounts: u32,
}

/// Represents the data of th Subaccounts
#[derive(Debug, Deserialize, Serialize)]
pub struct SubaccountData {
    /// Sub account data
    pub subaccount: SubaccountsResponseData,
    /// Share of split assigned to this sub
    pub share: u32,
}

/// Response from List Subaccount route
#[derive(Debug, Deserialize, Serialize)]
pub struct ListSubaccountsResponse {
    /// This lets you know if your request was successful or not.
    pub status: bool,
    /// This is a summary of the response and its status.
    pub message: String,
    /// This contain the results of your request.
    pub data: Vec<SubaccountsResponseData>,
    /// The meta key is used to provide context for the contents of the data key.
    pub meta: MetaData,
}

/// Data of the list Subaccount response
#[derive(Debug, Deserialize, Serialize)]
pub struct SubaccountsResponseData {
    /// Integration Id of subaccount.
    pub integration: Option<u32>,
    /// Subaccount domain.
    pub domain: Option<String>,
    /// The code of the subaccount.
    pub subaccount_code: String,
    /// The name of the business associated with the subaccount.
    pub business_name: String,
    /// The description of the business associated with the subaccount.
    pub description: Option<String>,
    /// The name of the primary contact for the business, if available.
    pub primary_contact_name: Option<String>,
    /// The email of the primary contact for the business, if available.
    pub primary_contact_email: Option<String>,
    /// The phone number of the primary contact for the business, if available.
    pub primary_contact_phone: Option<String>,
    /// Additional metadata associated with the subaccount, if available.
    pub metadata: Option<String>,
    /// The percentage charge for transactions associated with the subaccount.
    pub percentage_charge: f32,
    /// Verification status of subaccount.
    pub is_verified: Option<bool>,
    /// The name of the settlement bank for the subaccount.
    pub settlement_bank: String,
    /// The account number of the subaccount.
    pub account_number: String,
    /// Settlement schedule of subaccount.
    pub settlement_schedule: Option<String>,
    /// The ID of the subaccount.
    pub id: u32,
    /// Creation time of subaccount.
    #[serde(rename = "createdAt")]
    pub created_at: Option<String>,
    /// Last update time of subaccount.
    #[serde(rename = "updatedAt")]
    pub updated_at: Option<String>,
}

/// MetaData of list response
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct MetaData {
    /// This is the total number of transactions that were performed by the customer.
    pub total: u32,
    /// This is the number of records skipped before the first record in the array returned.
    pub skipped: u32,
    /// This is the maximum number of records that will be returned per request.
    #[serde(rename = "perPage")]
    pub per_page: String,
    /// This is the current `page` being returned.
    pub page: u32,
    /// This is how many pages in total are available for retrieval considering the maximum records per page specified.
    #[serde(rename = "pageCount")]
    pub page_count: u32,
}

/// Represents the JSON response containing percentage split information.
#[derive(Debug, Deserialize, Serialize)]
pub struct TransactionSplitListResponse {
    /// The status of the JSON response.
    pub status: bool,
    /// The message associated with the JSON response.
    pub message: String,
    /// The percentage split data.
    pub data: Vec<SplitData>,
}

/// Represents the JSON response of the Paystack API when there is no data property
#[derive(Debug, Deserialize, Serialize)]
pub struct ResponseWithoutData {
    /// The status of the JSON response.
    pub status: bool,
    /// The message associated with the JSON response.
    pub message: String,
}

/// Represents the JSON response for subaccount creation.
#[derive(Debug, Deserialize, Serialize)]
pub struct CreateSubaccountResponse {
    /// The status of the JSON response.
    pub status: bool,
    /// The message associated with the JSON response
    pub message: String,
    /// Subaccount response data
    pub data: SubaccountsResponseData,
}

/// Represents the JSON response for fetch subaccount.
#[derive(Debug, Deserialize, Serialize)]
pub struct FetchSubaccountResponse {
    /// The status of the JSON response.
    pub status: bool,
    /// The message associated with the JSON response.
    pub message: String,
    /// Fetch Subaccount response data.
    pub data: SubaccountsResponseData,
}