fapshi_rs/
models.rs

1use serde::{Deserialize, Serialize};
2
3/// Request payload for creating a payment link.
4#[derive(Serialize, Deserialize, Debug)]
5pub struct PaymentRequest {
6    /// The payment amount should be greater than 100.
7    pub amount: f64,
8    /// If the email is set, then the user will no longer be required to provide his/her email during the payment process
9    pub email: Option<String>,
10    /// URL to which your user will be redirected after completing a payment
11    #[serde(rename = "redirectUrl")]
12    pub redirect_url: Option<String>,
13    /// The user ID associated with the payment (optional).
14    #[serde(rename = "userId")]
15    pub user_id: Option<String>,
16    #[serde(rename = "ExternalId")]
17    /// This can be a transaction id, an order id or anything that can be used to reconcile this payment transaction to your application.
18    pub external_id: Option<String>,
19    /// Contains a message describing the reason for the payment.
20    #[serde(rename = "message")]
21    pub message: String,
22    ///  If set to true, only international payment options will be available on the generated link
23    #[serde(rename = "CardOnly")]
24    pub card_only: Option<bool>,
25}
26
27#[derive(Serialize, Deserialize, Debug, Clone)]
28pub struct PaymentTransactionResponse {
29    #[serde(rename = "transId")]
30    pub transaction_id: String,
31}
32/// Response payload for a created payment link.
33#[derive(Serialize, Deserialize, Debug, Clone)]
34pub struct PaymentResponse {
35    pub message: String,
36    /// The generated payment link valid for 24hours.
37    #[serde(rename = "link")]
38    pub payment_link: String,
39    /// The unique transaction ID.
40    #[serde(rename = "transId")]
41    pub transaction_id: String,
42    #[serde(rename = "dateInitiated")]
43    pub date_initiated: String,
44}
45
46/// Transaction status information.
47#[derive(Serialize, Deserialize, Debug, Clone)]
48pub struct TransactionStatus {
49    #[serde(rename = "transId")]
50    pub transaction_id: String,
51    pub status: Status,
52    #[serde(skip_serializing_if = "Option::is_none")]
53    pub medium: Option<String>,
54    #[serde(rename = "serviceName")]
55    pub service_name: String,
56    pub amount: f64,
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub revenue: Option<f64>,
59    #[serde(rename = "payerName")]
60    #[serde(skip_serializing_if = "Option::is_none")]
61    pub payer_name: Option<String>,
62    pub email: String,
63    #[serde(rename = "redirectUrl")]
64    pub redirect_url: String,
65    #[serde(rename = "externalId")]
66    #[serde(skip_serializing_if = "Option::is_none")]
67    pub external_id: Option<String>,
68    #[serde(rename = "userId")]
69    #[serde(skip_serializing_if = "Option::is_none")]
70    pub user_id: Option<String>,
71    #[serde(skip_serializing_if = "Option::is_none")]
72    pub webhook: Option<String>,
73    #[serde(rename = "financialTransId")]
74    #[serde(skip_serializing_if = "Option::is_none")]
75    pub financial_transaction_id: Option<String>,
76    #[serde(rename = "dateInitiated")]
77    pub date_initiated: String,
78    #[serde(rename = "dateConfirmed")]
79    pub date_confirmed: String,
80}
81#[derive(Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq)]
82pub enum Status {
83    #[default]
84    CREATED,
85    PENDING,
86    SUCCESSFUL,
87    FAILED,
88    EXPIRED,
89}
90
91impl From<String> for Status {
92    fn from(s: String) -> Self {
93        match s.to_lowercase().as_str() {
94            "created" => Status::CREATED,
95            "pending" => Status::PENDING,
96            "successful" => Status::SUCCESSFUL,
97            "failed" => Status::FAILED,
98            "expired" => Status::EXPIRED,
99            _ => Status::CREATED,
100        }
101    }
102}
103
104/// Expired Transaction
105#[derive(Serialize, Deserialize, Debug, Clone)]
106pub struct ExpiredTransaction {
107    /// The unique transaction ID.
108    pub transaction_id: String,
109}
110
111#[derive(Serialize, Deserialize, Debug, Clone)]
112pub struct ExpiredTransactionResponse {
113    /// The status of the expired transaction.
114    pub status: String,
115    /// The unique transaction ID.
116    pub transaction_id: String,
117    /// The transaction amount.
118    pub amount: f64,
119}
120
121/// Configuration for a webhook.
122#[derive(Serialize, Deserialize, Debug, Clone)]
123pub struct WebhookConfig {
124    /// The URL to receive webhook notifications.
125    pub url: String,
126    /// The service ID for the webhook.
127    pub service_id: String,
128}
129
130/// Request payload for initiating a direct payment to a mobile device.
131#[derive(Serialize, Deserialize, Debug, Clone)]
132pub struct DirectPaymentRequest {
133    /// The payment amount (integer >= 100).
134    pub amount: f32, // Changed to i32 to enforce integer type
135    /// The phone number to which the request will be performed (e.g., 67XXXXXXX).
136    pub phone: String,
137    /// The payment medium (either "mobile money" or "orange money").
138    #[serde(skip_serializing_if = "Option::is_none")]
139    pub medium: Option<String>, // Optional, restricted to "mobile money" or "orange money"
140    /// The name of the user performing the payment.
141    #[serde(skip_serializing_if = "Option::is_none")]
142    pub name: Option<String>, // Optional
143    /// The email of the user performing the payment.
144    #[serde(skip_serializing_if = "Option::is_none")]
145    pub email: Option<String>, // Optional
146    /// The user ID in the caller's system (1-100 characters, alphanumeric with -_).
147    #[serde(skip_serializing_if = "Option::is_none")]
148    pub user_id: Option<String>, // Optional
149    /// The external ID for reconciliation (1-100 characters, alphanumeric with -_).
150    #[serde(skip_serializing_if = "Option::is_none")]
151    pub external_id: Option<String>, // Optional
152    /// A message describing the reason for the payment.
153    #[serde(skip_serializing_if = "Option::is_none")]
154    pub message: Option<String>, // Optional, renamed from description
155}
156/// Response payload for a direct payment request.
157#[derive(Serialize, Deserialize, Debug, Clone)]
158pub struct DirectPaymentResponse {
159    /// The unique transaction ID.
160    #[serde(rename = "transId")]
161    pub transaction_id: String,
162    /// The status of the direct payment request.
163    pub message: String,
164    /// date initiated
165    #[serde(rename = "dateInitiated")]
166    pub date_initiated: String,
167}
168
169/// Query parameters for searching transactions.
170#[derive(Serialize, Deserialize, Debug, Default, Clone)]
171pub struct TransactionSearchQuery {
172    /// Transaction status (e.g., "created", "successful", "failed", "expired").
173    pub status: Status,
174    /// Payment medium (e.g., "mobile money", "orange money").
175    pub medium: String,
176    /// Name of the user performing the payment (optional).
177    #[serde(skip_serializing_if = "Option::is_none")]
178    pub name: Option<String>,
179    /// Start date (yyyy-mm-dd) for transactions.
180    pub start: String,
181    /// End date (yyyy-mm-dd) for transactions.
182    pub end: String,
183    /// Exact transaction amount.
184    pub amt: f64,
185    /// Maximum number of transactions to return
186    pub limit: u32,
187}
188
189/// Response payload for a transaction search or user ID query.
190#[derive(Serialize, Deserialize, Debug)]
191pub struct TransactionList {
192    /// Array of transactions matching the query.
193    #[serde(flatten)]
194    pub transactions: Vec<TransactionStatus>,
195}
196
197/// Response payload for service balance.
198#[derive(Serialize, Deserialize, Debug, Clone)]
199pub struct ServiceBalance {
200    /// The current balance amount.
201    pub balance: f64,
202    /// The currency code.
203    pub currency: String,
204}
205
206#[derive(Serialize, Deserialize, Debug, Clone)]
207pub struct Payouts {
208    /// amount to be sent to the user.
209    pub amount: f64,
210    /// phone number to which the amount will be sent e.g., 67XXXXXXX, 69XXXXXXX, 65XXXXXXX.
211    pub phone_number: String,
212    /// medium can either be “mobile money” for MTN numbers or “orange money” for Orange numbers.
213    pub medium: String,
214    /// name of the user receiving the payment.
215    pub name: Option<String>,
216    /// email of the user receiving the payment
217    pub email: Option<String>,
218    /// contains a message describing the reason for the payout.
219    pub message: Option<String>,
220}