From 89cc605652d8f63ed589386605ae451e0940cbd6 Mon Sep 17 00:00:00 2001 From: Soubhik Gon <119437069+zakhaev26@users.noreply.github.com> Date: Tue, 31 Oct 2023 14:05:59 +0530 Subject: [PATCH 1/6] (feat)router: created connector_router_data --- crates/router/src/connector/tsys.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/router/src/connector/tsys.rs b/crates/router/src/connector/tsys.rs index 869aa5356364..89cfe53e8e50 100644 --- a/crates/router/src/connector/tsys.rs +++ b/crates/router/src/connector/tsys.rs @@ -71,6 +71,10 @@ impl ConnectorCommon for Tsys { "tsys" } + fn get_currency_unit(&self) -> api::CurrencyUnit { + api::CurrencyUnit::Base + } + fn common_get_content_type(&self) -> &'static str { "application/json" } @@ -227,7 +231,16 @@ impl ConnectorIntegration CustomResult, errors::ConnectorError> { - let req_obj = tsys::TsysSyncRequest::try_from(req)?; + + let connector_router_data = tsys::TsysRouterData::try_from(( + &self.get_currency_unit(), + req.request.currency, + req.request.amount, + req, + ))?; + + let req_obj = tsys::TsysPaymentsRequest::try_from(&connector_router_data)?; + let tsys_req = types::RequestBody::log_and_get_request_body( &req_obj, utils::Encode::::encode_to_string_of_json, From d9b6e7d303716004c9a57fdadcdc7d96ffa45341 Mon Sep 17 00:00:00 2001 From: Soubhik Gon <119437069+zakhaev26@users.noreply.github.com> Date: Tue, 31 Oct 2023 19:50:34 +0530 Subject: [PATCH 2/6] feat(router): implement `TsysRouterData` with accordance to pull/#2196 --- .../router/src/connector/tsys/transformers.rs | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/crates/router/src/connector/tsys/transformers.rs b/crates/router/src/connector/tsys/transformers.rs index a3bd1c4a0740..34908d092f8c 100644 --- a/crates/router/src/connector/tsys/transformers.rs +++ b/crates/router/src/connector/tsys/transformers.rs @@ -17,7 +17,37 @@ pub enum TsysPaymentsRequest { Sale(TsysPaymentAuthSaleRequest), } -#[derive(Default, Debug, Serialize)] +#[derive(Debug, Serialize)] +pub struct TsysRouterData { + pub amount: String, + pub router_data: T, +} + +impl + TryFrom<( + &types::api::CurrencyUnit, + types::storage::enums::Currency, + i64, + T, + )> for TsysRouterData +{ + type Error = error_stack::Report; + fn try_from( + (currency_unit, currency, amount, item): ( + &types::api::CurrencyUnit, + types::storage::enums::Currency, + i64, + T, + ), + ) -> Result { + let amount = utils::get_amount_as_string(currency_unit, amount, currency)?; + Ok(Self { + amount, + router_data: item, + }) + } +} + #[serde(rename_all = "camelCase")] pub struct TsysPaymentAuthSaleRequest { #[serde(rename = "deviceID")] From 287b5f8a58c9427d72f2c232e1abaf44292fe120 Mon Sep 17 00:00:00 2001 From: Soubhik Gon <119437069+zakhaev26@users.noreply.github.com> Date: Tue, 31 Oct 2023 21:51:24 +0530 Subject: [PATCH 3/6] feat(connector) : implements router data struct and functionality and modifies impl --- crates/router/src/connector/tsys/transformers.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/router/src/connector/tsys/transformers.rs b/crates/router/src/connector/tsys/transformers.rs index 34908d092f8c..38f91f190661 100644 --- a/crates/router/src/connector/tsys/transformers.rs +++ b/crates/router/src/connector/tsys/transformers.rs @@ -67,9 +67,9 @@ pub struct TsysPaymentAuthSaleRequest { order_number: String, } -impl TryFrom<&types::PaymentsAuthorizeRouterData> for TsysPaymentsRequest { +impl TryFrom<&TsysRouterData<&types::PaymentsAuthorizeRouterData> for TsysPaymentsRequest { type Error = error_stack::Report; - fn try_from(item: &types::PaymentsAuthorizeRouterData) -> Result { + fn try_from(item: &TsysRouterData<&types::PaymentsAuthorizeRouterData>>) -> Result { match item.request.payment_method_data.clone() { api::PaymentMethodData::Card(ccard) => { let connector_auth: TsysAuthType = @@ -489,9 +489,9 @@ pub struct TsysRefundRequest { return_request: TsysReturnRequest, } -impl TryFrom<&types::RefundsRouterData> for TsysRefundRequest { +impl TryFrom<&TsysRouterData::RefundsRouterData> for TsysRefundRequest { type Error = error_stack::Report; - fn try_from(item: &types::RefundsRouterData) -> Result { + fn try_from(item:&TsysRouterData<&types::RefundsRouterData>) -> Result { let connector_auth: TsysAuthType = TsysAuthType::try_from(&item.connector_auth_type)?; let return_request = TsysReturnRequest { device_id: connector_auth.device_id, From 1a50fd15572fcfd5665035ea8ddcc9976855e57d Mon Sep 17 00:00:00 2001 From: Soubhik Gon <119437069+zakhaev26@users.noreply.github.com> Date: Sun, 5 Nov 2023 01:35:17 +0530 Subject: [PATCH 4/6] implements `connector_router_data` in refund processing --- crates/router/src/connector/tsys.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/router/src/connector/tsys.rs b/crates/router/src/connector/tsys.rs index 89cfe53e8e50..0725891453eb 100644 --- a/crates/router/src/connector/tsys.rs +++ b/crates/router/src/connector/tsys.rs @@ -474,6 +474,12 @@ impl ConnectorIntegration, ) -> CustomResult, errors::ConnectorError> { + let connector_router_data = tsys::TsysRouterData::try_from(( + &self.get_currency_unit(), + req.request.currency, + req.request.refund_amount, + req, + ))?; let req_obj = tsys::TsysRefundRequest::try_from(req)?; let tsys_req = types::RequestBody::log_and_get_request_body( &req_obj, From 4e269d0fe50a8bfadaee18bd6930ad27682dcded Mon Sep 17 00:00:00 2001 From: Soubhik Gon <119437069+zakhaev26@users.noreply.github.com> Date: Sun, 5 Nov 2023 01:59:24 +0530 Subject: [PATCH 5/6] fixes errors in `connector/tsys/transformers.rs` --- crates/router/src/connector/tsys/transformers.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/router/src/connector/tsys/transformers.rs b/crates/router/src/connector/tsys/transformers.rs index 38f91f190661..857e5c064605 100644 --- a/crates/router/src/connector/tsys/transformers.rs +++ b/crates/router/src/connector/tsys/transformers.rs @@ -67,9 +67,11 @@ pub struct TsysPaymentAuthSaleRequest { order_number: String, } -impl TryFrom<&TsysRouterData<&types::PaymentsAuthorizeRouterData> for TsysPaymentsRequest { +impl TryFrom<&TsysRouterData<&types::PaymentsAuthorizeRouterData>> for TsysPaymentsRequest { type Error = error_stack::Report; - fn try_from(item: &TsysRouterData<&types::PaymentsAuthorizeRouterData>>) -> Result { + fn try_from( + item: &TsysRouterData<&types::PaymentsAuthorizeRouterData>, + ) -> Result { match item.request.payment_method_data.clone() { api::PaymentMethodData::Card(ccard) => { let connector_auth: TsysAuthType = @@ -491,7 +493,7 @@ pub struct TsysRefundRequest { impl TryFrom<&TsysRouterData::RefundsRouterData> for TsysRefundRequest { type Error = error_stack::Report; - fn try_from(item:&TsysRouterData<&types::RefundsRouterData>) -> Result { + fn try_from(item: &TsysRouterData<&types::RefundsRouterData>) -> Result { let connector_auth: TsysAuthType = TsysAuthType::try_from(&item.connector_auth_type)?; let return_request = TsysReturnRequest { device_id: connector_auth.device_id, From e1b04a6530537990ede90189a4f86413395cae4a Mon Sep 17 00:00:00 2001 From: Soubhik Gon <119437069+zakhaev26@users.noreply.github.com> Date: Wed, 8 Nov 2023 14:13:50 +0530 Subject: [PATCH 6/6] fixes `TsysRefundRequest`'s `try_from` --- crates/router/src/connector/tsys.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/router/src/connector/tsys.rs b/crates/router/src/connector/tsys.rs index 0725891453eb..e7e818062e2b 100644 --- a/crates/router/src/connector/tsys.rs +++ b/crates/router/src/connector/tsys.rs @@ -480,7 +480,7 @@ impl ConnectorIntegration::encode_to_string_of_json,