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): [CyberSource] Enhance currency Mapping with ConnectorCurrencyCommon Trait (#2626)
mdrokzf2f8170ae1bc
diff --git a/crates/router/src/connector/cybersource.rs b/crates/router/src/connector/cybersource.rsindex d1ad36b26d..0a13aa0cf1 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<api::Authorize, types::PaymentsAuthorizeData, types::P&self,req: &types::PaymentsAuthorizeRouterData,) -> CustomResult<Option<types::RequestBody>, 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::<cybersource::CybersourcePaymentsRequest>::encode_to_string_of_json,diff --git a/crates/router/src/connector/cybersource/transformers.rs b/crates/router/src/connector/cybersource/transformers.rsindex 5a3060f99e..55507e4f49 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<T> {+ pub amount: String,+ pub router_data: T,+}++impl<T>+ TryFrom<(+ &types::api::CurrencyUnit,+ types::storage::enums::Currency,+ i64,+ T,+ )> for CybersourceRouterData<T>+{+ type Error = error_stack::Report<errors::ConnectorError>;+ fn try_from(+ (currency_unit, currency, amount, item): (+ &types::api::CurrencyUnit,+ types::storage::enums::Currency,+ i64,+ T,+ ),+ ) -> Result<Self, Self::Error> {+ 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<errors::ConnectorError>;- fn try_from(item: &types::PaymentsAuthorizeRouterData) -> Result<Self, Self::Error> {- match item.request.payment_method_data.clone() {+ fn try_from(+ item: &CybersourceRouterData<&types::PaymentsAuthorizeRouterData>,+ ) -> Result<Self, Self::Error> {+ 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.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 CybersourcePaymentsRequestlet 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.rsindex 3a8cae3a63..6f1566a35b 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<String, error_stack::Report<errors::ConnectorError>> {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)