use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use crate::Amount;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StartRequest {
pub amount: Amount,
pub description: String,
pub callback_url: String,
pub email: Option<String>,
pub mobile: Option<String>,
pub order_id: Option<String>,
#[serde(default)]
pub extras: HashMap<String, String>,
}
impl StartRequest {
#[must_use]
pub fn builder() -> StartRequestBuilder {
StartRequestBuilder::default()
}
}
#[derive(Debug, Default)]
pub struct StartRequestBuilder {
amount: Option<Amount>,
description: Option<String>,
callback_url: Option<String>,
email: Option<String>,
mobile: Option<String>,
order_id: Option<String>,
extras: HashMap<String, String>,
}
impl StartRequestBuilder {
#[must_use]
pub fn amount(mut self, amount: Amount) -> Self {
self.amount = Some(amount);
self
}
#[must_use]
pub fn description(mut self, d: impl Into<String>) -> Self {
self.description = Some(d.into());
self
}
#[must_use]
pub fn callback_url(mut self, url: impl Into<String>) -> Self {
self.callback_url = Some(url.into());
self
}
#[must_use]
pub fn email(mut self, email: impl Into<String>) -> Self {
self.email = Some(email.into());
self
}
#[must_use]
pub fn mobile(mut self, mobile: impl Into<String>) -> Self {
self.mobile = Some(mobile.into());
self
}
#[must_use]
pub fn order_id(mut self, id: impl Into<String>) -> Self {
self.order_id = Some(id.into());
self
}
#[must_use]
pub fn extra(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.extras.insert(key.into(), value.into());
self
}
pub fn build(self) -> StartRequest {
StartRequest {
amount: self.amount.expect("StartRequest: amount is required"),
description: self
.description
.expect("StartRequest: description is required"),
callback_url: self
.callback_url
.expect("StartRequest: callback_url is required"),
email: self.email,
mobile: self.mobile,
order_id: self.order_id,
extras: self.extras,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StartResponse {
pub authority: String,
pub payment_url: String,
pub provider: &'static str,
#[serde(default)]
pub raw: serde_json::Value,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VerifyRequest {
pub authority: String,
pub amount: Amount,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VerifyResponse {
pub transaction_id: String,
pub authority: String,
pub amount: Amount,
pub card_pan: Option<String>,
pub card_hash: Option<String>,
pub fee: Option<Amount>,
pub provider: &'static str,
#[serde(default)]
pub raw: serde_json::Value,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RefundRequest {
pub transaction_id: String,
pub amount: Option<Amount>,
pub reason: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RefundResponse {
pub refund_id: String,
pub transaction_id: String,
pub amount: Amount,
pub provider: &'static str,
#[serde(default)]
pub raw: serde_json::Value,
}