diff --git a/crates/router/src/connector/cybersource.rs b/crates/router/src/connector/cybersource.rs index d1ad36b26d1e..0a13aa0cf141 100644 --- a/crates/router/src/connector/cybersource.rs +++ b/crates/router/src/connector/cybersource.rs @@ -93,6 +93,10 @@ impl ConnectorCommon for Cybersource { connectors.cybersource.base_url.as_ref() } + fn get_currency_unit(&self) -> api::CurrencyUnit { + api::CurrencyUnit::Minor + } + fn build_error_response( &self, res: types::Response, @@ -468,7 +472,14 @@ impl ConnectorIntegration CustomResult, errors::ConnectorError> { - let connector_request = cybersource::CybersourcePaymentsRequest::try_from(req)?; + let connector_router_data = cybersource::CybersourceRouterData::try_from(( + &self.get_currency_unit(), + req.request.currency, + req.request.amount, + req, + ))?; + let connector_request = + cybersource::CybersourcePaymentsRequest::try_from(&connector_router_data)?; let cybersource_payments_request = types::RequestBody::log_and_get_request_body( &connector_request, utils::Encode::::encode_to_string_of_json, diff --git a/crates/router/src/connector/cybersource/transformers.rs b/crates/router/src/connector/cybersource/transformers.rs index 5a3060f99ebd..55507e4f4903 100644 --- a/crates/router/src/connector/cybersource/transformers.rs +++ b/crates/router/src/connector/cybersource/transformers.rs @@ -15,6 +15,37 @@ use crate::{ }, }; +#[derive(Debug, Serialize)] +pub struct CybersourceRouterData { + pub amount: String, + pub router_data: T, +} + +impl + TryFrom<( + &types::api::CurrencyUnit, + types::storage::enums::Currency, + i64, + T, + )> for CybersourceRouterData +{ + 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, + }) + } +} + #[derive(Default, Debug, Serialize, Eq, PartialEq)] #[serde(rename_all = "camelCase")] pub struct CybersourcePaymentsRequest { @@ -109,27 +140,33 @@ fn build_bill_to( }) } -impl TryFrom<&types::PaymentsAuthorizeRouterData> for CybersourcePaymentsRequest { +impl TryFrom<&CybersourceRouterData<&types::PaymentsAuthorizeRouterData>> + for CybersourcePaymentsRequest +{ type Error = error_stack::Report; - fn try_from(item: &types::PaymentsAuthorizeRouterData) -> Result { - match item.request.payment_method_data.clone() { + fn try_from( + item: &CybersourceRouterData<&types::PaymentsAuthorizeRouterData>, + ) -> Result { + match item.router_data.request.payment_method_data.clone() { api::PaymentMethodData::Card(ccard) => { - let phone = item.get_billing_phone()?; + let phone = item.router_data.get_billing_phone()?; let phone_number = phone.get_number()?; let country_code = phone.get_country_code()?; let number_with_code = Secret::new(format!("{}{}", country_code, phone_number.peek())); let email = item + .router_data .request .email .clone() .ok_or_else(utils::missing_field_err("email"))?; - let bill_to = build_bill_to(item.get_billing()?, email, number_with_code)?; + let bill_to = + build_bill_to(item.router_data.get_billing()?, email, number_with_code)?; let order_information = OrderInformationWithBill { amount_details: Amount { - total_amount: item.request.amount.to_string(), - currency: item.request.currency.to_string().to_uppercase(), + total_amount: item.amount.to_owned(), + currency: item.router_data.request.currency.to_string().to_uppercase(), }, bill_to, }; @@ -145,14 +182,14 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for CybersourcePaymentsRequest let processing_information = ProcessingInformation { capture: matches!( - item.request.capture_method, + item.router_data.request.capture_method, Some(enums::CaptureMethod::Automatic) | None ), capture_options: None, }; let client_reference_information = ClientReferenceInformation { - code: Some(item.connector_request_reference_id.clone()), + code: Some(item.router_data.connector_request_reference_id.clone()), }; Ok(Self { diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rs index 3a8cae3a631e..6f1566a35b0d 100644 --- a/crates/router/src/connector/utils.rs +++ b/crates/router/src/connector/utils.rs @@ -1077,7 +1077,7 @@ pub fn get_amount_as_string( currency: diesel_models::enums::Currency, ) -> Result> { let amount = match currency_unit { - types::api::CurrencyUnit::Minor => amount.to_string(), + types::api::CurrencyUnit::Minor => to_currency_lower_unit(amount.to_string(), currency)?, types::api::CurrencyUnit::Base => to_currency_base_unit(amount, currency)?, }; Ok(amount)