mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 12:06:56 +08:00
refactor(connector): added amount conversion framework for Mifinity (#5460)
This commit is contained in:
@ -1,12 +1,12 @@
|
||||
pub mod transformers;
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
use common_utils::types::{AmountConvertor, StringMajorUnit, StringMajorUnitForConnector};
|
||||
use error_stack::{report, Report, ResultExt};
|
||||
use masking::ExposeInterface;
|
||||
use transformers as mifinity;
|
||||
|
||||
use self::transformers::auth_headers;
|
||||
use super::utils::convert_amount;
|
||||
use crate::{
|
||||
configs::settings,
|
||||
consts,
|
||||
@ -26,8 +26,18 @@ use crate::{
|
||||
utils::BytesExt,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Mifinity;
|
||||
#[derive(Clone)]
|
||||
pub struct Mifinity {
|
||||
amount_converter: &'static (dyn AmountConvertor<Output = StringMajorUnit> + Sync),
|
||||
}
|
||||
|
||||
impl Mifinity {
|
||||
pub fn new() -> &'static Self {
|
||||
&Self {
|
||||
amount_converter: &StringMajorUnitForConnector,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl api::Payment for Mifinity {}
|
||||
impl api::PaymentSession for Mifinity {}
|
||||
@ -224,12 +234,13 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
|
||||
req: &types::PaymentsAuthorizeRouterData,
|
||||
_connectors: &settings::Connectors,
|
||||
) -> CustomResult<RequestContent, errors::ConnectorError> {
|
||||
let connector_router_data = mifinity::MifinityRouterData::try_from((
|
||||
&self.get_currency_unit(),
|
||||
let amount = convert_amount(
|
||||
self.amount_converter,
|
||||
req.request.minor_amount,
|
||||
req.request.currency,
|
||||
req.request.amount,
|
||||
req,
|
||||
))?;
|
||||
)?;
|
||||
|
||||
let connector_router_data = mifinity::MifinityRouterData::from((amount, req));
|
||||
let connector_req = mifinity::MifinityPaymentsRequest::try_from(&connector_router_data)?;
|
||||
Ok(RequestContent::Json(Box::new(connector_req)))
|
||||
}
|
||||
|
||||
@ -1,4 +1,7 @@
|
||||
use common_utils::pii::{self, Email};
|
||||
use common_utils::{
|
||||
pii::{self, Email},
|
||||
types::StringMajorUnit,
|
||||
};
|
||||
use error_stack::ResultExt;
|
||||
use masking::Secret;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -8,27 +11,22 @@ use crate::{
|
||||
connector::utils::{self, PaymentsAuthorizeRequestData, PhoneDetailsData, RouterData},
|
||||
core::errors,
|
||||
services,
|
||||
types::{self, api, domain, storage::enums},
|
||||
types::{self, domain, storage::enums},
|
||||
};
|
||||
|
||||
pub struct MifinityRouterData<T> {
|
||||
pub amount: String,
|
||||
pub amount: StringMajorUnit,
|
||||
pub router_data: T,
|
||||
}
|
||||
|
||||
impl<T> TryFrom<(&api::CurrencyUnit, enums::Currency, i64, T)> for MifinityRouterData<T> {
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
fn try_from(
|
||||
(currency_unit, currency, amount, item): (&api::CurrencyUnit, enums::Currency, i64, T),
|
||||
) -> Result<Self, Self::Error> {
|
||||
let amount = utils::get_amount_as_string(currency_unit, amount, currency)?;
|
||||
Ok(Self {
|
||||
impl<T> From<(StringMajorUnit, T)> for MifinityRouterData<T> {
|
||||
fn from((amount, router_data): (StringMajorUnit, T)) -> Self {
|
||||
Self {
|
||||
amount,
|
||||
router_data: item,
|
||||
})
|
||||
router_data,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod auth_headers {
|
||||
pub const API_VERSION: &str = "api-version";
|
||||
}
|
||||
@ -69,7 +67,7 @@ pub struct MifinityPaymentsRequest {
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq)]
|
||||
pub struct Money {
|
||||
amount: String,
|
||||
amount: StringMajorUnit,
|
||||
currency: String,
|
||||
}
|
||||
|
||||
|
||||
@ -449,7 +449,7 @@ impl ConnectorData {
|
||||
Ok(ConnectorEnum::Old(Box::new(&connector::Worldpay)))
|
||||
}
|
||||
enums::Connector::Mifinity => {
|
||||
Ok(ConnectorEnum::Old(Box::new(&connector::Mifinity)))
|
||||
Ok(ConnectorEnum::Old(Box::new(connector::Mifinity::new())))
|
||||
}
|
||||
enums::Connector::Multisafepay => {
|
||||
Ok(ConnectorEnum::Old(Box::new(&connector::Multisafepay)))
|
||||
|
||||
Reference in New Issue
Block a user