mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
refactor(connector): added amount conversion framework for Gpayments (#4978)
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
pub mod gpayments_types;
|
||||
pub mod transformers;
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
use common_utils::request::RequestContent;
|
||||
use common_utils::{
|
||||
request::RequestContent,
|
||||
types::{AmountConvertor, MinorUnit, MinorUnitForConnector},
|
||||
};
|
||||
use error_stack::{report, ResultExt};
|
||||
use transformers as gpayments;
|
||||
|
||||
@ -22,8 +23,18 @@ use crate::{
|
||||
utils::BytesExt,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Gpayments;
|
||||
#[derive(Clone)]
|
||||
pub struct Gpayments {
|
||||
_amount_converter: &'static (dyn AmountConvertor<Output = MinorUnit> + Sync),
|
||||
}
|
||||
|
||||
impl Gpayments {
|
||||
pub fn new() -> &'static Self {
|
||||
&Self {
|
||||
_amount_converter: &MinorUnitForConnector,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl api::Payment for Gpayments {}
|
||||
impl api::PaymentSession for Gpayments {}
|
||||
@ -246,7 +257,7 @@ impl
|
||||
req: &types::authentication::ConnectorAuthenticationRouterData,
|
||||
_connectors: &settings::Connectors,
|
||||
) -> CustomResult<RequestContent, errors::ConnectorError> {
|
||||
let connector_router_data = gpayments::GpaymentsRouterData::try_from((0, req))?;
|
||||
let connector_router_data = gpayments::GpaymentsRouterData::from((MinorUnit::zero(), req));
|
||||
let req_obj =
|
||||
gpayments_types::GpaymentsAuthenticationRequest::try_from(&connector_router_data)?;
|
||||
Ok(RequestContent::Json(Box::new(req_obj)))
|
||||
@ -440,7 +451,7 @@ impl
|
||||
req: &types::authentication::PreAuthNRouterData,
|
||||
_connectors: &settings::Connectors,
|
||||
) -> CustomResult<RequestContent, errors::ConnectorError> {
|
||||
let connector_router_data = gpayments::GpaymentsRouterData::try_from((0, req))?;
|
||||
let connector_router_data = gpayments::GpaymentsRouterData::from((MinorUnit::zero(), req));
|
||||
let req_obj =
|
||||
gpayments_types::GpaymentsPreAuthenticationRequest::try_from(&connector_router_data)?;
|
||||
Ok(RequestContent::Json(Box::new(req_obj)))
|
||||
@ -537,7 +548,7 @@ impl
|
||||
req: &types::authentication::PreAuthNVersionCallRouterData,
|
||||
_connectors: &settings::Connectors,
|
||||
) -> CustomResult<RequestContent, errors::ConnectorError> {
|
||||
let connector_router_data = gpayments::GpaymentsRouterData::try_from((0, req))?;
|
||||
let connector_router_data = gpayments::GpaymentsRouterData::from((MinorUnit::zero(), req));
|
||||
let req_obj =
|
||||
gpayments_types::GpaymentsPreAuthVersionCallRequest::try_from(&connector_router_data)?;
|
||||
Ok(RequestContent::Json(Box::new(req_obj)))
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use api_models::payments::DeviceChannel;
|
||||
use base64::Engine;
|
||||
use common_utils::date_time;
|
||||
use common_utils::{date_time, types::MinorUnit};
|
||||
use error_stack::ResultExt;
|
||||
use masking::{ExposeInterface, Secret};
|
||||
use serde::Deserialize;
|
||||
@ -21,17 +21,16 @@ use crate::{
|
||||
};
|
||||
|
||||
pub struct GpaymentsRouterData<T> {
|
||||
pub amount: i64, // The type of amount that a connector accepts, for example, String, i64, f64, etc.
|
||||
pub amount: MinorUnit, // The type of amount that a connector accepts, for example, String, i64, f64, etc.
|
||||
pub router_data: T,
|
||||
}
|
||||
|
||||
impl<T> TryFrom<(i64, T)> for GpaymentsRouterData<T> {
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
fn try_from((amount, item): (i64, T)) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
impl<T> From<(MinorUnit, T)> for GpaymentsRouterData<T> {
|
||||
fn from((amount, item): (MinorUnit, T)) -> Self {
|
||||
Self {
|
||||
amount,
|
||||
router_data: item,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -148,7 +148,7 @@ impl AuthenticationConnectorData {
|
||||
Ok(ConnectorEnum::Old(Box::new(&connector::Netcetera)))
|
||||
}
|
||||
enums::AuthenticationConnectors::Gpayments => {
|
||||
Ok(ConnectorEnum::Old(Box::new(&connector::Gpayments)))
|
||||
Ok(ConnectorEnum::Old(Box::new(connector::Gpayments::new())))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ impl utils::Connector for GpaymentsTest {
|
||||
fn get_data(&self) -> types::api::ConnectorData {
|
||||
use router::connector::Gpayments;
|
||||
utils::construct_connector_data_old(
|
||||
Box::new(&Gpayments),
|
||||
Box::new(Gpayments::new()),
|
||||
types::Connector::Threedsecureio,
|
||||
// Added as Dummy connector as template code is added for future usage
|
||||
types::api::GetToken::Connector,
|
||||
|
||||
Reference in New Issue
Block a user