Skip to content

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

feat(core): Consuming locale in PaymentsAuthorizeData from SessionState (#8731)

Sayak Bhattacharyabe03dd2ae9a4
diff --git a/crates/hyperswitch_connectors/src/connectors/adyen.rs b/crates/hyperswitch_connectors/src/connectors/adyen.rs
index 18ab4b876b..6ece7d16e0 100644
--- a/crates/hyperswitch_connectors/src/connectors/adyen.rs
+++ b/crates/hyperswitch_connectors/src/connectors/adyen.rs
@@ -1846,6 +1846,7 @@ impl IncomingWebhook for Adyen {
) -> CustomResult<api_models::webhooks::IncomingWebhookEvent, errors::ConnectorError> {
let notif = get_webhook_object_from_body(request.body)
.change_context(errors::ConnectorError::WebhookEventTypeNotFound)?;
+
Ok(transformers::get_adyen_webhook_event(
notif.event_code,
notif.success,
diff --git a/crates/hyperswitch_connectors/src/connectors/adyen/transformers.rs b/crates/hyperswitch_connectors/src/connectors/adyen/transformers.rs
index f8c8ed4d5a..6a0cc9c461 100644
--- a/crates/hyperswitch_connectors/src/connectors/adyen/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/adyen/transformers.rs
@@ -2912,7 +2912,7 @@ impl
telephone_number,
shopper_name: None,
shopper_email: None,
- shopper_locale: None,
+ shopper_locale: item.router_data.request.locale.clone(),
social_security_number: None,
billing_address,
delivery_address,
@@ -2996,7 +2996,7 @@ impl TryFrom<(&AdyenRouterData<&PaymentsAuthorizeRouterData>, &Card)> for AdyenP
telephone_number,
shopper_name,
shopper_email,
- shopper_locale: None,
+ shopper_locale: item.router_data.request.locale.clone(),
social_security_number: None,
billing_address,
delivery_address,
@@ -3082,7 +3082,7 @@ impl
additional_data,
mpi_data: None,
shopper_name: None,
- shopper_locale: None,
+ shopper_locale: item.router_data.request.locale.clone(),
shopper_email: item.router_data.get_optional_billing_email(),
social_security_number: None,
telephone_number,
@@ -3157,7 +3157,7 @@ impl TryFrom<(&AdyenRouterData<&PaymentsAuthorizeRouterData>, &VoucherData)>
recurring_processing_model,
additional_data,
shopper_name,
- shopper_locale: None,
+ shopper_locale: item.router_data.request.locale.clone(),
shopper_email: item.router_data.get_optional_billing_email(),
social_security_number,
mpi_data: None,
@@ -3276,7 +3276,7 @@ impl
additional_data: None,
mpi_data: None,
shopper_name: None,
- shopper_locale: None,
+ shopper_locale: item.router_data.request.locale.clone(),
shopper_email: item.router_data.get_optional_billing_email(),
social_security_number,
telephone_number,
@@ -3353,7 +3353,7 @@ impl
additional_data: None,
mpi_data: None,
shopper_name: None,
- shopper_locale: None,
+ shopper_locale: item.router_data.request.locale.clone(),
shopper_email: item.router_data.get_optional_billing_email(),
telephone_number,
billing_address,
@@ -3464,7 +3464,7 @@ fn get_redirect_extra_details(
BankRedirectData::Trustly { .. } | BankRedirectData::OpenBankingUk { .. },
) => {
let country = item.get_optional_billing_country();
- Ok((None, country))
+ Ok((item.request.locale.clone(), country))
}
_ => Ok((None, None)),
}
@@ -3567,7 +3567,7 @@ impl TryFrom<(&AdyenRouterData<&PaymentsAuthorizeRouterData>, &WalletData)>
telephone_number,
shopper_name: None,
shopper_email,
- shopper_locale: None,
+ shopper_locale: item.router_data.request.locale.clone(),
social_security_number: None,
billing_address,
delivery_address,
@@ -3657,7 +3657,7 @@ impl
shopper_name,
shopper_email,
mpi_data: None,
- shopper_locale: None,
+ shopper_locale: item.router_data.request.locale.clone(),
social_security_number: None,
billing_address,
delivery_address,
@@ -3739,7 +3739,7 @@ impl
telephone_number,
shopper_name,
shopper_email,
- shopper_locale: None,
+ shopper_locale: item.router_data.request.locale.clone(),
billing_address,
delivery_address,
country_code: None,
@@ -5985,7 +5985,7 @@ impl
telephone_number,
shopper_name,
shopper_email,
- shopper_locale: None,
+ shopper_locale: item.router_data.request.locale.clone(),
social_security_number: None,
billing_address,
delivery_address,
diff --git a/crates/hyperswitch_connectors/src/utils.rs b/crates/hyperswitch_connectors/src/utils.rs
index f210b01ff7..90a650a2b1 100644
--- a/crates/hyperswitch_connectors/src/utils.rs
+++ b/crates/hyperswitch_connectors/src/utils.rs
@@ -6202,6 +6202,7 @@ pub(crate) fn convert_setup_mandate_router_data_to_authorize_router_data(
merchant_config_currency: None,
connector_testing_data: data.request.connector_testing_data.clone(),
order_id: None,
+ locale: None,
}
}
diff --git a/crates/hyperswitch_domain_models/src/router_request_types.rs b/crates/hyperswitch_domain_models/src/router_request_types.rs
index b9e2e4a74a..c7ac366483 100644
--- a/crates/hyperswitch_domain_models/src/router_request_types.rs
+++ b/crates/hyperswitch_domain_models/src/router_request_types.rs
@@ -80,6 +80,7 @@ pub struct PaymentsAuthorizeData {
pub merchant_config_currency: Option<storage_enums::Currency>,
pub connector_testing_data: Option<pii::SecretSerdeValue>,
pub order_id: Option<String>,
+ pub locale: Option<String>,
}
#[derive(Debug, Clone)]
pub struct PaymentsPostSessionTokensData {
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index 4a023f7d8c..0b1758990a 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -2039,8 +2039,7 @@ pub fn decide_payment_method_retrieval_action(
pub async fn is_ucs_enabled(state: &SessionState, config_key: &str) -> bool {
let db = state.store.as_ref();
- let is_enabled = db
- .find_config_by_key_unwrap_or(config_key, Some("false".to_string()))
+ db.find_config_by_key_unwrap_or(config_key, Some("false".to_string()))
.await
.map_err(|error| {
logger::error!(
@@ -2053,9 +2052,7 @@ pub async fn is_ucs_enabled(state: &SessionState, config_key: &str) -> bool {
logger::error!(?error, "Failed to parse `{config_key}` UCS enabled config");
})
})
- .unwrap_or(false);
-
- is_enabled
+ .unwrap_or(false)
}
pub async fn should_execute_based_on_rollout(
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index 1974fd3e42..36db7dc1b8 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -270,6 +270,7 @@ pub async fn construct_payment_router_data_for_authorize<'a>(
.browser_info
.clone()
.map(types::BrowserInformation::from);
+
// TODO: few fields are repeated in both routerdata and request
let request = types::PaymentsAuthorizeData {
payment_method_data: payment_data
@@ -325,6 +326,7 @@ pub async fn construct_payment_router_data_for_authorize<'a>(
merchant_config_currency: None,
connector_testing_data: None,
order_id: None,
+ locale: None,
};
let connector_mandate_request_reference_id = payment_data
.payment_attempt
@@ -3588,6 +3590,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
merchant_config_currency: None,
connector_testing_data: None,
order_id: None,
+ locale: None,
})
}
}
@@ -3819,6 +3822,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
merchant_config_currency,
connector_testing_data,
order_id: None,
+ locale: Some(additional_data.state.locale.clone()),
})
}
}
diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs
index 57043bbcc0..717140cc0e 100644
--- a/crates/router/src/types.rs
+++ b/crates/router/src/types.rs
@@ -1091,6 +1091,7 @@ impl ForeignFrom<&SetupMandateRouterData> for PaymentsAuthorizeData {
merchant_config_currency: None,
connector_testing_data: data.request.connector_testing_data.clone(),
order_id: None,
+ locale: None,
}
}
}
diff --git a/crates/router/src/types/api/verify_connector.rs b/crates/router/src/types/api/verify_connector.rs
index 83066578d0..ba0413440a 100644
--- a/crates/router/src/types/api/verify_connector.rs
+++ b/crates/router/src/types/api/verify_connector.rs
@@ -65,6 +65,7 @@ impl VerifyConnectorData {
merchant_config_currency: None,
connector_testing_data: None,
order_id: None,
+ locale: None,
}
}
diff --git a/crates/router/tests/connectors/aci.rs b/crates/router/tests/connectors/aci.rs
index d2629fb4c2..3b5c0d5c2a 100644
--- a/crates/router/tests/connectors/aci.rs
+++ b/crates/router/tests/connectors/aci.rs
@@ -81,6 +81,7 @@ fn construct_payment_router_data() -> types::PaymentsAuthorizeRouterData {
metadata: None,
authentication_data: None,
customer_acceptance: None,
+ locale: None,
..utils::PaymentAuthorizeType::default().0
},
response: Err(types::ErrorResponse::default()),
diff --git a/crates/router/tests/connectors/adyen.rs b/crates/router/tests/connectors/adyen.rs
index 3737be3a1b..beca1c2df7 100644
--- a/crates/router/tests/connectors/adyen.rs
+++ b/crates/router/tests/connectors/adyen.rs
@@ -183,6 +183,7 @@ impl AdyenTest {
metadata: None,
authentication_data: None,
customer_acceptance: None,
+ locale: None,
..utils::PaymentAuthorizeType::default().0
})
}
diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rs
index e3884894b3..65ca7fc70b 100644
--- a/crates/router/tests/connectors/utils.rs
+++ b/crates/router/tests/connectors/utils.rs
@@ -997,6 +997,7 @@ impl Default for PaymentAuthorizeType {
merchant_config_currency: None,
connector_testing_data: None,
order_id: None,
+ locale: None,
};
Self(data)
}