Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
refactor(connector): added amount conversion framework for Gpayments (#4978)
Kiran Kumaraa036ce84d1e
diff --git a/crates/router/src/connector/gpayments.rs b/crates/router/src/connector/gpayments.rsindex e628779cd9..9f88e21513 100644--- a/crates/router/src/connector/gpayments.rs+++ b/crates/router/src/connector/gpayments.rs@@ -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 @@ implreq: &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 @@ implreq: &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 @@ implreq: &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)))diff --git a/crates/router/src/connector/gpayments/transformers.rs b/crates/router/src/connector/gpayments/transformers.rsindex 50c8c0f28c..572b6dfa0e 100644--- a/crates/router/src/connector/gpayments/transformers.rs+++ b/crates/router/src/connector/gpayments/transformers.rs@@ -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,- })+ }}}diff --git a/crates/router/src/types/api/authentication.rs b/crates/router/src/types/api/authentication.rsindex 9b2a69bfe0..7d35943dd7 100644--- a/crates/router/src/types/api/authentication.rs+++ b/crates/router/src/types/api/authentication.rs@@ -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())))}}}diff --git a/crates/router/tests/connectors/gpayments.rs b/crates/router/tests/connectors/gpayments.rsindex f0935a928a..851c0ee06f 100644--- a/crates/router/tests/connectors/gpayments.rs+++ b/crates/router/tests/connectors/gpayments.rs@@ -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 usagetypes::api::GetToken::Connector,