paystack/models/charge_models.rs
1//! Charge
2//! ===========
3//! This file contains all the structs and definitions needed to
4//! create charges using the Paystack API.
5
6use crate::{Channel, Currency};
7use derive_builder::Builder;
8use serde::{Deserialize, Serialize};
9
10use super::{Authorization, CustomerResponseData};
11
12/// This struct is used to create a charge body for creating a Charge Authorization using the Paystack API.
13/// The struct is constructed using the `ChargeBodyBuilder`
14#[derive(Serialize, Debug, Builder)]
15pub struct ChargeRequest {
16 /// Customer's email address
17 email: String,
18 /// Amount should be in the smallest unit of the currency e.g. kobo if in NGN and cents if in USD
19 amount: String,
20 /// Valid authorization code to charge
21 authorization_code: String,
22 /// Unique transaction reference. Only `-`, `.`, `=` and alphanumeric characters allowed.
23 #[builder(setter(strip_option), default)]
24 reference: Option<String>,
25 /// Currency in which amount should be charged.
26 #[builder(setter(strip_option), default)]
27 currency: Option<Currency>,
28 /// Stringified JSON object.
29 /// Add a custom_fields attribute which has an array of objects if you would like the fields to be added to your transaction
30 /// when displayed on the dashboard.
31 /// Sample: {"custom_fields":[{"display_name":"Cart ID","variable_name": "cart_id","value": "8393"}]}
32 #[builder(setter(strip_option), default)]
33 metadata: Option<String>,
34 /// Send us 'card' or 'bank' or 'card','bank' as an array to specify what options to show the user paying
35 #[builder(setter(strip_option), default)]
36 channel: Option<Vec<Channel>>,
37 /// The code for the subaccount that owns the payment. e.g. `ACCT_8f4s1eq7ml6rlzj`
38 #[builder(setter(strip_option), default)]
39 subaccount: Option<String>,
40 /// A flat fee to charge the subaccount for this transaction in the subunit of the supported currency.
41 /// This overrides the split percentage set when the subaccount was created.
42 /// Ideally, you will need to use this if you are splitting in flat rates (since subaccount creation only allows for percentage split).
43 #[builder(setter(strip_option), default)]
44 transaction_charge: Option<u32>,
45 /// Who bears Paystack charges? account or subaccount (defaults to account).
46 #[builder(setter(strip_option), default)]
47 bearer: Option<String>,
48 /// If you are making a scheduled charge call, it is a good idea to queue them so the processing system does not
49 /// get overloaded causing transaction processing errors.
50 /// Send queue:true to take advantage of our queued charging.
51 #[builder(setter(strip_option), default)]
52 queue: Option<bool>,
53}
54
55/// This struct represents the charge response
56#[derive(Deserialize, Serialize, Debug, Clone, Default)]
57pub struct ChargeResponseData {
58 pub amount: u64,
59 pub currency: String,
60 pub transaction_date: String,
61 pub status: String,
62 pub reference: String,
63 pub metadata: Option<String>,
64 pub gateway_response: String,
65 pub message: Option<String>,
66 pub channel: String,
67 pub ip_address: Option<String>,
68 pub fees: u64,
69 pub authorization: Authorization,
70 pub customer: CustomerResponseData,
71 pub plan: Option<String>,
72 pub id: Option<u64>,
73}