diff --git a/crates/router/src/connector/worldpay.rs b/crates/router/src/connector/worldpay.rs index 0c69cd981bb3..60a5fc830453 100644 --- a/crates/router/src/connector/worldpay.rs +++ b/crates/router/src/connector/worldpay.rs @@ -56,6 +56,10 @@ impl ConnectorCommon for Worldpay { "worldpay" } + fn get_currency_unit(&self) -> api::CurrencyUnit { + api::CurrencyUnit::Minor + } + fn common_get_content_type(&self) -> &'static str { "application/vnd.worldpay.payments-v6+json" } @@ -428,7 +432,13 @@ impl ConnectorIntegration CustomResult, errors::ConnectorError> { - let connector_request = WorldpayPaymentsRequest::try_from(req)?; + let connector_router_data = worldpay::WorldpayRouterData::try_from(( + &self.get_currency_unit(), + req.request.currency, + req.request.amount, + req, + ))?; + let connector_request = WorldpayPaymentsRequest::try_from(&connector_router_data)?; let worldpay_payment_request = types::RequestBody::log_and_get_request_body( &connector_request, ext_traits::Encode::::encode_to_string_of_json, diff --git a/crates/router/src/connector/worldpay/transformers.rs b/crates/router/src/connector/worldpay/transformers.rs index 3d467f4198f7..aabe27fc4eb1 100644 --- a/crates/router/src/connector/worldpay/transformers.rs +++ b/crates/router/src/connector/worldpay/transformers.rs @@ -3,15 +3,44 @@ use common_utils::errors::CustomResult; use diesel_models::enums; use error_stack::{IntoReport, ResultExt}; use masking::{PeekInterface, Secret}; +use serde::Serialize; use super::{requests::*, response::*}; use crate::{ connector::utils, consts, core::errors, - types::{self, api}, + types::{self, api, PaymentsAuthorizeData, PaymentsResponseData}, }; +#[derive(Debug, Serialize)] +pub struct WorldpayRouterData { + amount: i64, + router_data: T, +} +impl + TryFrom<( + &types::api::CurrencyUnit, + types::storage::enums::Currency, + i64, + T, + )> for WorldpayRouterData +{ + type Error = error_stack::Report; + fn try_from( + (_currency_unit, _currency, amount, item): ( + &types::api::CurrencyUnit, + types::storage::enums::Currency, + i64, + T, + ), + ) -> Result { + Ok(Self { + amount, + router_data: item, + }) + } +} fn fetch_payment_instrument( payment_method: api::PaymentMethodData, ) -> CustomResult { @@ -100,29 +129,48 @@ fn fetch_payment_instrument( } } -impl TryFrom<&types::PaymentsAuthorizeRouterData> for WorldpayPaymentsRequest { +impl + TryFrom< + &WorldpayRouterData< + &types::RouterData< + types::api::payments::Authorize, + PaymentsAuthorizeData, + PaymentsResponseData, + >, + >, + > for WorldpayPaymentsRequest +{ type Error = error_stack::Report; - fn try_from(item: &types::PaymentsAuthorizeRouterData) -> Result { + + fn try_from( + item: &WorldpayRouterData< + &types::RouterData< + types::api::payments::Authorize, + PaymentsAuthorizeData, + PaymentsResponseData, + >, + >, + ) -> Result { Ok(Self { instruction: Instruction { value: PaymentValue { - amount: item.request.amount, - currency: item.request.currency.to_string(), + amount: item.amount, + currency: item.router_data.request.currency.to_string(), }, narrative: InstructionNarrative { - line1: item.merchant_id.clone().replace('_', "-"), + line1: item.router_data.merchant_id.clone().replace('_', "-"), ..Default::default() }, payment_instrument: fetch_payment_instrument( - item.request.payment_method_data.clone(), + item.router_data.request.payment_method_data.clone(), )?, debt_repayment: None, }, merchant: Merchant { - entity: item.attempt_id.clone().replace('_', "-"), + entity: item.router_data.attempt_id.clone().replace('_', "-"), ..Default::default() }, - transaction_reference: item.attempt_id.clone(), + transaction_reference: item.router_data.attempt_id.clone(), channel: None, customer: None, }) diff --git a/package.json b/package.json index 0766efdcc17a..45d2be3153b1 100644 --- a/package.json +++ b/package.json @@ -6,4 +6,4 @@ "devDependencies": { "newman": "git+ssh://git@github.com:knutties/newman.git#7106e194c15d49d066fa09d9a2f18b2238f3dba8" } -} +} \ No newline at end of file