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
feat(business_profile): added merchant country code in business profile (#8529)
Sahkal Poddar44f8964a05dc
diff --git a/Cargo.lock b/Cargo.lockindex f3ab37bbb5..f65a0fd4be 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -1861,6 +1861,7 @@ dependencies = ["common_enums","common_utils","diesel",+ "error-stack 0.4.1","euclid","masking","serde",diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.jsonindex 5656a7f887..d457ec798d 100644--- a/api-reference/v1/openapi_spec_v1.json+++ b/api-reference/v1/openapi_spec_v1.json@@ -6708,7 +6708,6 @@"required": ["acquirer_assigned_merchant_id","merchant_name",- "merchant_country_code","network","acquirer_bin","acquirer_fraud_rate"@@ -6724,11 +6723,6 @@"description": "merchant name","example": "NewAge Retailer"},- "merchant_country_code": {- "type": "string",- "description": "Merchant country code assigned by acquirer",- "example": "US"- },"network": {"type": "string","description": "Network provider",@@ -17462,6 +17456,10 @@},"additionalProperties": false},+ "MerchantCountryCode": {+ "type": "string",+ "description": "A wrapper type for merchant country codes that provides validation and conversion functionality.\n\nThis type stores a country code as a string and provides methods to validate it\nand convert it to a `Country` enum variant."+ },"MerchantDetails": {"type": "object","properties": {@@ -26089,7 +26087,6 @@"required": ["acquirer_assigned_merchant_id","merchant_name",- "merchant_country_code","network","acquirer_bin","acquirer_fraud_rate",@@ -26106,11 +26103,6 @@"description": "merchant name","example": "NewAge Retailer"},- "merchant_country_code": {- "type": "string",- "description": "Merchant country code assigned by acquirer",- "example": "US"- },"network": {"type": "string","description": "Network provider",@@ -26146,7 +26138,6 @@"profile_acquirer_id","acquirer_assigned_merchant_id","merchant_name",- "merchant_country_code","network","acquirer_bin","acquirer_fraud_rate",@@ -26168,11 +26159,6 @@"description": "Merchant name","example": "NewAge Retailer"},- "merchant_country_code": {- "type": "string",- "description": "Merchant country code assigned by acquirer",- "example": "US"- },"network": {"type": "string","description": "Network provider",@@ -26215,11 +26201,6 @@"example": "Updated Retailer Name","nullable": true},- "merchant_country_code": {- "type": "string",- "example": "CA",- "nullable": true- },"network": {"type": "string","example": "MASTERCARD",@@ -26489,6 +26470,14 @@}],"nullable": true+ },+ "merchant_country_code": {+ "allOf": [+ {+ "$ref": "#/components/schemas/MerchantCountryCode"+ }+ ],+ "nullable": true}},"additionalProperties": false@@ -26795,6 +26784,14 @@}],"nullable": true+ },+ "merchant_country_code": {+ "allOf": [+ {+ "$ref": "#/components/schemas/MerchantCountryCode"+ }+ ],+ "nullable": true}}},diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.jsonindex ecd899a372..4820c944dc 100644--- a/api-reference/v2/openapi_spec_v2.json+++ b/api-reference/v2/openapi_spec_v2.json@@ -13824,6 +13824,10 @@},"additionalProperties": false},+ "MerchantCountryCode": {+ "type": "string",+ "description": "A wrapper type for merchant country codes that provides validation and conversion functionality.\n\nThis type stores a country code as a string and provides methods to validate it\nand convert it to a `Country` enum variant."+ },"MerchantDetails": {"type": "object","properties": {@@ -21238,6 +21242,14 @@}],"nullable": true+ },+ "merchant_country_code": {+ "allOf": [+ {+ "$ref": "#/components/schemas/MerchantCountryCode"+ }+ ],+ "nullable": true}},"additionalProperties": false@@ -21515,6 +21527,14 @@}],"nullable": true+ },+ "merchant_country_code": {+ "allOf": [+ {+ "$ref": "#/components/schemas/MerchantCountryCode"+ }+ ],+ "nullable": true}}},diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rsindex f264c94370..22c1868f6a 100644--- a/crates/api_models/src/admin.rs+++ b/crates/api_models/src/admin.rs@@ -2176,6 +2176,13 @@ pub struct ProfileCreate {/// Four-digit code assigned based on business type to determine processing fees and risk level#[schema(value_type = Option<MerchantCategoryCode>, example = "5411")]pub merchant_category_code: Option<api_enums::MerchantCategoryCode>,++ /// Merchant country code.+ /// This is a 3-digit ISO 3166-1 numeric country code that represents the country in which the merchant is registered or operates.+ /// Merchants typically receive this value based on their business registration information or during onboarding via payment processors or acquiring banks.+ /// It is used in payment processing, fraud detection, and regulatory compliance to determine regional rules and routing behavior.+ #[schema(value_type = Option<MerchantCountryCode>, example = "840")]+ pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,}#[nutype::nutype(@@ -2322,6 +2329,13 @@ pub struct ProfileCreate {/// Four-digit code assigned based on business type to determine processing fees and risk level#[schema(value_type = Option<MerchantCategoryCode>, example = "5411")]pub merchant_category_code: Option<api_enums::MerchantCategoryCode>,++ /// Merchant country code.+ /// This is a 3-digit ISO 3166-1 numeric country code that represents the country in which the merchant is registered or operates.+ /// Merchants typically receive this value based on their business registration information or during onboarding via payment processors or acquiring banks.+ /// It is used in payment processing, fraud detection, and regulatory compliance to determine regional rules and routing behavior.+ #[schema(value_type = Option<MerchantCountryCode>, example = "840")]+ pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,}#[cfg(feature = "v1")]@@ -2497,6 +2511,13 @@ pub struct ProfileResponse {/// Four-digit code assigned based on business type to determine processing fees and risk level#[schema(value_type = Option<MerchantCategoryCode>, example = "5411")]pub merchant_category_code: Option<api_enums::MerchantCategoryCode>,++ /// Merchant country code.+ /// This is a 3-digit ISO 3166-1 numeric country code that represents the country in which the merchant is registered or operates.+ /// Merchants typically receive this value based on their business registration information or during onboarding via payment processors or acquiring banks.+ /// It is used in payment processing, fraud detection, and regulatory compliance to determine regional rules and routing behavior.+ #[schema(value_type = Option<MerchantCountryCode>, example = "840")]+ pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,}#[cfg(feature = "v2")]@@ -2651,6 +2672,13 @@ pub struct ProfileResponse {/// Four-digit code assigned based on business type to determine processing fees and risk level#[schema(value_type = Option<MerchantCategoryCode>, example = "5411")]pub merchant_category_code: Option<api_enums::MerchantCategoryCode>,++ /// Merchant country code.+ /// This is a 3-digit ISO 3166-1 numeric country code that represents the country in which the merchant is registered or operates.+ /// Merchants typically receive this value based on their business registration information or during onboarding via payment processors or acquiring banks.+ /// It is used in payment processing, fraud detection, and regulatory compliance to determine regional rules and routing behavior.+ #[schema(value_type = Option<MerchantCountryCode>, example = "840")]+ pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,}#[cfg(feature = "v1")]@@ -2811,6 +2839,13 @@ pub struct ProfileUpdate {/// Four-digit code assigned based on business type to determine processing fees and risk level#[schema(value_type = Option<MerchantCategoryCode>, example = "5411")]pub merchant_category_code: Option<api_enums::MerchantCategoryCode>,++ /// Merchant country code.+ /// This is a 3-digit ISO 3166-1 numeric country code that represents the country in which the merchant is registered or operates.+ /// Merchants typically receive this value based on their business registration information or during onboarding via payment processors or acquiring banks.+ /// It is used in payment processing, fraud detection, and regulatory compliance to determine regional rules and routing behavior.+ #[schema(value_type = Option<MerchantCountryCode>, example = "840")]+ pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,}#[cfg(feature = "v2")]@@ -2947,6 +2982,13 @@ pub struct ProfileUpdate {/// Four-digit code assigned based on business type to determine processing fees and risk level#[schema(value_type = Option<MerchantCategoryCode>, example = "5411")]pub merchant_category_code: Option<api_enums::MerchantCategoryCode>,++ /// Merchant country code.+ /// This is a 3-digit ISO 3166-1 numeric country code that represents the country in which the merchant is registered or operates.+ /// Merchants typically receive this value based on their business registration information or during onboarding via payment processors or acquiring banks.+ /// It is used in payment processing, fraud detection, and regulatory compliance to determine regional rules and routing behavior.+ #[schema(value_type = Option<MerchantCountryCode>, example = "840")]+ pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,}#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)]diff --git a/crates/api_models/src/profile_acquirer.rs b/crates/api_models/src/profile_acquirer.rsindex 9b53c1844b..9689be7d99 100644--- a/crates/api_models/src/profile_acquirer.rs+++ b/crates/api_models/src/profile_acquirer.rs@@ -1,8 +1,6 @@use serde::{Deserialize, Serialize};use utoipa::ToSchema;-use crate::enums;-#[derive(Debug, Serialize, Deserialize, ToSchema)]pub struct ProfileAcquirerCreate {/// The merchant id assigned by the acquirer@@ -11,9 +9,6 @@ pub struct ProfileAcquirerCreate {/// merchant name#[schema(value_type= String,example = "NewAge Retailer")]pub merchant_name: String,- /// Merchant country code assigned by acquirer- #[schema(value_type= String,example = "US")]- pub merchant_country_code: enums::CountryAlpha2,/// Network provider#[schema(value_type= String,example = "VISA")]pub network: common_enums::enums::CardNetwork,@@ -42,9 +37,6 @@ pub struct ProfileAcquirerResponse {/// Merchant name#[schema(value_type= String,example = "NewAge Retailer")]pub merchant_name: String,- /// Merchant country code assigned by acquirer- #[schema(value_type= String,example = "US")]- pub merchant_country_code: enums::CountryAlpha2,/// Network provider#[schema(value_type= String,example = "VISA")]pub network: common_enums::enums::CardNetwork,@@ -84,7 +76,6 @@ implprofile_id: profile_id.clone(),acquirer_assigned_merchant_id: acquirer_config.acquirer_assigned_merchant_id.clone(),merchant_name: acquirer_config.merchant_name.clone(),- merchant_country_code: acquirer_config.merchant_country_code,network: acquirer_config.network.clone(),acquirer_bin: acquirer_config.acquirer_bin.clone(),acquirer_ica: acquirer_config.acquirer_ica.clone(),@@ -100,8 +91,6 @@ pub struct ProfileAcquirerUpdate {pub acquirer_assigned_merchant_id: Option<String>,#[schema(value_type = Option<String>, example = "Updated Retailer Name")]pub merchant_name: Option<String>,- #[schema(value_type = Option<String>, example = "CA")]- pub merchant_country_code: Option<enums::CountryAlpha2>,#[schema(value_type = Option<String>, example = "MASTERCARD")]pub network: Option<common_enums::enums::CardNetwork>,#[schema(value_type = Option<String>, example = "987654")]diff --git a/crates/common_types/Cargo.toml b/crates/common_types/Cargo.tomlindex 7aec031470..e989426be2 100644--- a/crates/common_types/Cargo.toml+++ b/crates/common_types/Cargo.toml@@ -18,6 +18,7 @@ serde = { version = "1.0.219", features = ["derive"] }serde_json = "1.0.140"utoipa = { version = "4.2.3", features = ["preserve_order", "preserve_path_order"] }time = { version = "0.3.35", features = ["serde", "serde-well-known", "std"] }+error-stack = "0.4.1"common_enums = { version = "0.1.0", path = "../common_enums" }common_utils = { version = "0.1.0", path = "../common_utils"}diff --git a/crates/common_types/src/domain.rs b/crates/common_types/src/domain.rsindex 66ffa6029d..6b5d1cf835 100644--- a/crates/common_types/src/domain.rs+++ b/crates/common_types/src/domain.rs@@ -65,9 +65,6 @@ pub struct AcquirerConfig {/// merchant name#[schema(value_type= String,example = "NewAge Retailer")]pub merchant_name: String,- /// Merchant country code assigned by acquirer- #[schema(value_type= String,example = "US")]- pub merchant_country_code: common_enums::CountryAlpha2,/// Network provider#[schema(value_type= String,example = "VISA")]pub network: common_enums::CardNetwork,diff --git a/crates/common_types/src/payments.rs b/crates/common_types/src/payments.rsindex e0ea52abc7..625f626268 100644--- a/crates/common_types/src/payments.rs+++ b/crates/common_types/src/payments.rs@@ -4,7 +4,11 @@ use std::collections::HashMap;use common_enums::enums;use common_utils::{date_time, errors, events, impl_to_sql_from_sql_json, pii, types::MinorUnit};-use diesel::{sql_types::Jsonb, AsExpression, FromSqlRow};+use diesel::{+ sql_types::{Jsonb, Text},+ AsExpression, FromSqlRow,+};+use error_stack::{Report, Result, ResultExt};use euclid::frontend::{ast::Program,dir::{DirKeyKind, EuclidDirFilter},@@ -73,10 +77,70 @@ impl AuthenticationConnectorAccountMap {.ok_or(errors::ValidationError::MissingRequiredField {field_name: "authentication_product_id.click_to_pay".to_string(),})+ .map_err(Report::from).cloned()}}+/// A wrapper type for merchant country codes that provides validation and conversion functionality.+///+/// This type stores a country code as a string and provides methods to validate it+/// and convert it to a `Country` enum variant.+#[derive(+ Serialize, Deserialize, Debug, Clone, PartialEq, Eq, FromSqlRow, AsExpression, ToSchema,+)]+#[diesel(sql_type = Text)]+#[serde(deny_unknown_fields)]+pub struct MerchantCountryCode(String);++impl MerchantCountryCode {+ /// Returns the country code as a string.+ pub fn get_country_code(&self) -> String {+ self.0.clone()+ }++ /// Validates the country code and returns a `Country` enum variant.+ ///+ /// This method attempts to parse the country code as a u32 and convert it to a `Country` enum variant.+ /// If the country code is invalid, it returns a `ValidationError` with the appropriate error message.+ pub fn validate_and_get_country_from_merchant_country_code(+ &self,+ ) -> errors::CustomResult<common_enums::Country, errors::ValidationError> {+ let country_code = self.get_country_code();+ let code = country_code+ .parse::<u32>()+ .map_err(Report::from)+ .change_context(errors::ValidationError::IncorrectValueProvided {+ field_name: "merchant_country_code",+ })+ .attach_printable_lazy(|| {+ format!("Country code {country_code} is negative or too large")+ })?;++ common_enums::Country::from_numeric(code)+ .map_err(|_| errors::ValidationError::IncorrectValueProvided {+ field_name: "merchant_country_code",+ })+ .attach_printable_lazy(|| format!("Invalid country code {code}"))+ }+}++impl diesel::serialize::ToSql<Text, diesel::pg::Pg> for MerchantCountryCode {+ fn to_sql<'b>(+ &'b self,+ out: &mut diesel::serialize::Output<'b, '_, diesel::pg::Pg>,+ ) -> diesel::serialize::Result {+ <String as diesel::serialize::ToSql<Text, diesel::pg::Pg>>::to_sql(&self.0, out)+ }+}++impl diesel::deserialize::FromSql<Text, diesel::pg::Pg> for MerchantCountryCode {+ fn from_sql(bytes: diesel::pg::PgValue<'_>) -> diesel::deserialize::Result<Self> {+ let s = <String as diesel::deserialize::FromSql<Text, diesel::pg::Pg>>::from_sql(bytes)?;+ Ok(Self(s))+ }+}+#[derive(Serialize, Default, Deserialize, Debug, Clone, PartialEq, Eq, FromSqlRow, AsExpression, ToSchema,)]diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rsindex 2c887e7f7c..bbb76b53f4 100644--- a/crates/diesel_models/src/business_profile.rs+++ b/crates/diesel_models/src/business_profile.rs@@ -76,6 +76,7 @@ pub struct Profile {pub three_ds_decision_rule_algorithm: Option<serde_json::Value>,pub acquirer_config_map: Option<common_types::domain::AcquirerConfigMap>,pub merchant_category_code: Option<common_enums::MerchantCategoryCode>,+ pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,}#[cfg(feature = "v1")]@@ -132,6 +133,7 @@ pub struct ProfileNew {pub is_iframe_redirection_enabled: Option<bool>,pub is_pre_network_tokenization_enabled: Option<bool>,pub merchant_category_code: Option<common_enums::MerchantCategoryCode>,+ pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,}#[cfg(feature = "v1")]@@ -188,6 +190,7 @@ pub struct ProfileUpdateInternal {pub three_ds_decision_rule_algorithm: Option<serde_json::Value>,pub acquirer_config_map: Option<common_types::domain::AcquirerConfigMap>,pub merchant_category_code: Option<common_enums::MerchantCategoryCode>,+ pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,}#[cfg(feature = "v1")]@@ -241,6 +244,7 @@ impl ProfileUpdateInternal {three_ds_decision_rule_algorithm,acquirer_config_map,merchant_category_code,+ merchant_country_code,} = self;Profile {profile_id: source.profile_id,@@ -325,6 +329,7 @@ impl ProfileUpdateInternal {.or(source.three_ds_decision_rule_algorithm),acquirer_config_map: acquirer_config_map.or(source.acquirer_config_map),merchant_category_code: merchant_category_code.or(source.merchant_category_code),+ merchant_country_code: merchant_country_code.or(source.merchant_country_code),}}}@@ -387,6 +392,7 @@ pub struct Profile {pub three_ds_decision_rule_algorithm: Option<serde_json::Value>,pub acquirer_config_map: Option<common_types::domain::AcquirerConfigMap>,pub merchant_category_code: Option<common_enums::MerchantCategoryCode>,+ pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,pub routing_algorithm_id: Option<common_utils::id_type::RoutingId>,pub order_fulfillment_time: Option<i64>,pub order_fulfillment_time_origin: Option<common_enums::OrderFulfillmentTimeOrigin>,@@ -459,6 +465,7 @@ pub struct ProfileNew {pub is_debit_routing_enabled: bool,pub merchant_business_country: Option<common_enums::CountryAlpha2>,pub merchant_category_code: Option<common_enums::MerchantCategoryCode>,+ pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,pub routing_algorithm_id: Option<common_utils::id_type::RoutingId>,pub order_fulfillment_time: Option<i64>,pub order_fulfillment_time_origin: Option<common_enums::OrderFulfillmentTimeOrigin>,@@ -518,6 +525,7 @@ pub struct ProfileUpdateInternal {pub is_debit_routing_enabled: Option<bool>,pub merchant_business_country: Option<common_enums::CountryAlpha2>,pub merchant_category_code: Option<common_enums::MerchantCategoryCode>,+ pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,pub routing_algorithm_id: Option<common_utils::id_type::RoutingId>,pub order_fulfillment_time: Option<i64>,pub order_fulfillment_time_origin: Option<common_enums::OrderFulfillmentTimeOrigin>,@@ -587,6 +595,7 @@ impl ProfileUpdateInternal {is_external_vault_enabled,external_vault_connector_details,merchant_category_code,+ merchant_country_code,} = self;Profile {id: source.id,@@ -681,6 +690,7 @@ impl ProfileUpdateInternal {three_ds_decision_rule_algorithm: None,acquirer_config_map: None,merchant_category_code: merchant_category_code.or(source.merchant_category_code),+ merchant_country_code: merchant_country_code.or(source.merchant_country_code),}}}diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rsindex 7d5d7c95cb..d0cd33228f 100644--- a/crates/diesel_models/src/schema.rs+++ b/crates/diesel_models/src/schema.rs@@ -239,6 +239,8 @@ diesel::table! {acquirer_config_map -> Nullable<Jsonb>,#[max_length = 16]merchant_category_code -> Nullable<Varchar>,+ #[max_length = 32]+ merchant_country_code -> Nullable<Varchar>,}}diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rsindex f41585eca3..d8a3728d64 100644--- a/crates/diesel_models/src/schema_v2.rs+++ b/crates/diesel_models/src/schema_v2.rs@@ -234,6 +234,8 @@ diesel::table! {acquirer_config_map -> Nullable<Jsonb>,#[max_length = 16]merchant_category_code -> Nullable<Varchar>,+ #[max_length = 32]+ merchant_country_code -> Nullable<Varchar>,#[max_length = 64]routing_algorithm_id -> Nullable<Varchar>,order_fulfillment_time -> Nullable<Int8>,diff --git a/crates/hyperswitch_domain_models/src/business_profile.rs b/crates/hyperswitch_domain_models/src/business_profile.rsindex 2a70f00c7f..c5a78c6f39 100644--- a/crates/hyperswitch_domain_models/src/business_profile.rs+++ b/crates/hyperswitch_domain_models/src/business_profile.rs@@ -82,6 +82,7 @@ pub struct Profile {pub three_ds_decision_rule_algorithm: Option<serde_json::Value>,pub acquirer_config_map: Option<common_types::domain::AcquirerConfigMap>,pub merchant_category_code: Option<api_enums::MerchantCategoryCode>,+ pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,}#[cfg(feature = "v1")]@@ -136,6 +137,7 @@ pub struct ProfileSetter {pub is_iframe_redirection_enabled: Option<bool>,pub is_pre_network_tokenization_enabled: bool,pub merchant_category_code: Option<api_enums::MerchantCategoryCode>,+ pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,}#[cfg(feature = "v1")]@@ -197,6 +199,7 @@ impl From<ProfileSetter> for Profile {three_ds_decision_rule_algorithm: None, // three_ds_decision_rule_algorithm is not yet created during profile creationacquirer_config_map: None,merchant_category_code: value.merchant_category_code,+ merchant_country_code: value.merchant_country_code,}}}@@ -258,6 +261,7 @@ pub struct ProfileGeneralUpdate {pub is_iframe_redirection_enabled: Option<bool>,pub is_pre_network_tokenization_enabled: Option<bool>,pub merchant_category_code: Option<api_enums::MerchantCategoryCode>,+ pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,}#[cfg(feature = "v1")]@@ -338,6 +342,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {is_iframe_redirection_enabled,is_pre_network_tokenization_enabled,merchant_category_code,+ merchant_country_code,} = *update;Self {@@ -389,6 +394,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {three_ds_decision_rule_algorithm: None,acquirer_config_map: None,merchant_category_code,+ merchant_country_code,}}ProfileUpdate::RoutingAlgorithmUpdate {@@ -443,6 +449,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {three_ds_decision_rule_algorithm,acquirer_config_map: None,merchant_category_code: None,+ merchant_country_code: None,},ProfileUpdate::DynamicRoutingAlgorithmUpdate {dynamic_routing_algorithm,@@ -494,6 +501,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {three_ds_decision_rule_algorithm: None,acquirer_config_map: None,merchant_category_code: None,+ merchant_country_code: None,},ProfileUpdate::ExtendedCardInfoUpdate {is_extended_card_info_enabled,@@ -545,6 +553,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {three_ds_decision_rule_algorithm: None,acquirer_config_map: None,merchant_category_code: None,+ merchant_country_code: None,},ProfileUpdate::ConnectorAgnosticMitUpdate {is_connector_agnostic_mit_enabled,@@ -596,6 +605,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {three_ds_decision_rule_algorithm: None,acquirer_config_map: None,merchant_category_code: None,+ merchant_country_code: None,},ProfileUpdate::NetworkTokenizationUpdate {is_network_tokenization_enabled,@@ -647,6 +657,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {three_ds_decision_rule_algorithm: None,acquirer_config_map: None,merchant_category_code: None,+ merchant_country_code: None,},ProfileUpdate::CardTestingSecretKeyUpdate {card_testing_secret_key,@@ -698,6 +709,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {three_ds_decision_rule_algorithm: None,acquirer_config_map: None,merchant_category_code: None,+ merchant_country_code: None,},ProfileUpdate::AcquirerConfigMapUpdate {acquirer_config_map,@@ -749,6 +761,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {three_ds_decision_rule_algorithm: None,acquirer_config_map,merchant_category_code: None,+ merchant_country_code: None,},}}@@ -820,6 +833,7 @@ impl super::behaviour::Conversion for Profile {three_ds_decision_rule_algorithm: self.three_ds_decision_rule_algorithm,acquirer_config_map: self.acquirer_config_map,merchant_category_code: self.merchant_category_code,+ merchant_country_code: self.merchant_country_code,})}@@ -917,6 +931,7 @@ impl super::behaviour::Conversion for Profile {three_ds_decision_rule_algorithm: item.three_ds_decision_rule_algorithm,acquirer_config_map: item.acquirer_config_map,merchant_category_code: item.merchant_category_code,+ merchant_country_code: item.merchant_country_code,})}.await@@ -981,6 +996,7 @@ impl super::behaviour::Conversion for Profile {is_iframe_redirection_enabled: self.is_iframe_redirection_enabled,is_pre_network_tokenization_enabled: Some(self.is_pre_network_tokenization_enabled),merchant_category_code: self.merchant_category_code,+ merchant_country_code: self.merchant_country_code,})}}@@ -1041,6 +1057,7 @@ pub struct Profile {pub is_external_vault_enabled: Option<bool>,pub external_vault_connector_details: Option<ExternalVaultConnectorDetails>,pub merchant_category_code: Option<api_enums::MerchantCategoryCode>,+ pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,}#[cfg(feature = "v2")]@@ -1097,6 +1114,7 @@ pub struct ProfileSetter {pub is_external_vault_enabled: Option<bool>,pub external_vault_connector_details: Option<ExternalVaultConnectorDetails>,pub merchant_category_code: Option<api_enums::MerchantCategoryCode>,+ pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,}#[cfg(feature = "v2")]@@ -1158,6 +1176,7 @@ impl From<ProfileSetter> for Profile {is_external_vault_enabled: value.is_external_vault_enabled,external_vault_connector_details: value.external_vault_connector_details,merchant_category_code: value.merchant_category_code,+ merchant_country_code: value.merchant_country_code,}}}@@ -1343,6 +1362,7 @@ pub struct ProfileGeneralUpdate {pub is_external_vault_enabled: Option<bool>,pub external_vault_connector_details: Option<ExternalVaultConnectorDetails>,pub merchant_category_code: Option<api_enums::MerchantCategoryCode>,+ pub merchant_country_code: Option<common_types::payments::MerchantCountryCode>,}#[cfg(feature = "v2")]@@ -1422,6 +1442,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {is_external_vault_enabled,external_vault_connector_details,merchant_category_code,+ merchant_country_code,} = *update;Self {profile_name,@@ -1474,6 +1495,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {is_external_vault_enabled,external_vault_connector_details,merchant_category_code,+ merchant_country_code,}}ProfileUpdate::RoutingAlgorithmUpdate {@@ -1529,6 +1551,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {is_external_vault_enabled: None,external_vault_connector_details: None,merchant_category_code: None,+ merchant_country_code: None,},ProfileUpdate::ExtendedCardInfoUpdate {is_extended_card_info_enabled,@@ -1582,6 +1605,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {is_external_vault_enabled: None,external_vault_connector_details: None,merchant_category_code: None,+ merchant_country_code: None,},ProfileUpdate::ConnectorAgnosticMitUpdate {is_connector_agnostic_mit_enabled,@@ -1635,6 +1659,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {is_external_vault_enabled: None,external_vault_connector_details: None,merchant_category_code: None,+ merchant_country_code: None,},ProfileUpdate::DefaultRoutingFallbackUpdate {default_fallback_routing,@@ -1688,6 +1713,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {is_external_vault_enabled: None,external_vault_connector_details: None,merchant_category_code: None,+ merchant_country_code: None,},ProfileUpdate::NetworkTokenizationUpdate {is_network_tokenization_enabled,@@ -1741,6 +1767,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {is_external_vault_enabled: None,external_vault_connector_details: None,merchant_category_code: None,+ merchant_country_code: None,},ProfileUpdate::CollectCvvDuringPaymentUpdate {should_collect_cvv_during_payment,@@ -1794,6 +1821,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {is_external_vault_enabled: None,external_vault_connector_details: None,merchant_category_code: None,+ merchant_country_code: None,},ProfileUpdate::DecisionManagerRecordUpdate {three_ds_decision_manager_config,@@ -1847,6 +1875,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {is_external_vault_enabled: None,external_vault_connector_details: None,merchant_category_code: None,+ merchant_country_code: None,},ProfileUpdate::CardTestingSecretKeyUpdate {card_testing_secret_key,@@ -1900,6 +1929,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {is_external_vault_enabled: None,external_vault_connector_details: None,merchant_category_code: None,+ merchant_country_code: None,},ProfileUpdate::RevenueRecoveryAlgorithmUpdate {revenue_recovery_retry_algorithm_type,@@ -1954,6 +1984,7 @@ impl From<ProfileUpdate> for ProfileUpdateInternal {is_external_vault_enabled: None,external_vault_connector_details: None,merchant_category_code: None,+ merchant_country_code: None,},}}@@ -2031,6 +2062,7 @@ impl super::behaviour::Conversion for Profile {three_ds_decision_rule_algorithm: None,acquirer_config_map: None,merchant_category_code: self.merchant_category_code,+ merchant_country_code: self.merchant_country_code,})}@@ -2125,6 +2157,7 @@ impl super::behaviour::Conversion for Profile {is_external_vault_enabled: item.is_external_vault_enabled,external_vault_connector_details: item.external_vault_connector_details,merchant_category_code: item.merchant_category_code,+ merchant_country_code: item.merchant_country_code,})}.await@@ -2194,6 +2227,7 @@ impl super::behaviour::Conversion for Profile {is_external_vault_enabled: self.is_external_vault_enabled,external_vault_connector_details: self.external_vault_connector_details,merchant_category_code: self.merchant_category_code,+ merchant_country_code: self.merchant_country_code,})}}diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rsindex 11fb349a33..0ec6f42319 100644--- a/crates/openapi/src/openapi.rs+++ b/crates/openapi/src/openapi.rs@@ -250,6 +250,7 @@ Never share your secret api keys. Keep them guarded and secure.common_types::payments::StripeChargeResponseData,common_types::three_ds_decision_rule_engine::ThreeDSDecisionRule,common_types::three_ds_decision_rule_engine::ThreeDSDecision,+ common_types::payments::MerchantCountryCode,api_models::three_ds_decision_rule::ThreeDsDecisionRuleExecuteRequest,api_models::three_ds_decision_rule::ThreeDsDecisionRuleExecuteResponse,api_models::three_ds_decision_rule::PaymentData,diff --git a/crates/openapi/src/openapi_v2.rs b/crates/openapi/src/openapi_v2.rsindex 11dae0588a..ac8d5d728a 100644--- a/crates/openapi/src/openapi_v2.rs+++ b/crates/openapi/src/openapi_v2.rs@@ -202,6 +202,7 @@ Never share your secret api keys. Keep them guarded and secure.common_types::payments::StripeChargeResponseData,common_types::three_ds_decision_rule_engine::ThreeDSDecisionRule,common_types::three_ds_decision_rule_engine::ThreeDSDecision,+ common_types::payments::MerchantCountryCode,common_utils::request::Method,api_models::refunds::RefundsCreateRequest,api_models::refunds::RefundErrorDetails,diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rsindex 18772bd710..d5827c843c 100644--- a/crates/router/src/core/admin.rs+++ b/crates/router/src/core/admin.rs@@ -3375,6 +3375,13 @@ impl ProfileCreateBridge for api::ProfileCreate {.change_context(errors::ApiErrorResponse::InternalServerError).attach_printable("error serializing dynamic_routing_algorithm_ref to JSON Value")?;+ self.merchant_country_code+ .as_ref()+ .map(|country_code| country_code.validate_and_get_country_from_merchant_country_code())+ .transpose()+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("Error while parsing country from merchant country code")?;+Ok(domain::Profile::from(domain::ProfileSetter {profile_id,merchant_id: merchant_context.get_merchant_account().get_id().clone(),@@ -3489,6 +3496,7 @@ impl ProfileCreateBridge for api::ProfileCreate {.is_pre_network_tokenization_enabled.unwrap_or_default(),merchant_category_code: self.merchant_category_code,+ merchant_country_code: self.merchant_country_code,}))}@@ -3638,6 +3646,7 @@ impl ProfileCreateBridge for api::ProfileCreate {.external_vault_connector_details.map(ForeignInto::foreign_into),merchant_category_code: self.merchant_category_code,+ merchant_country_code: self.merchant_country_code,}))}}@@ -3918,6 +3927,13 @@ impl ProfileUpdateBridge for api::ProfileUpdate {self.dynamic_routing_algorithm};+ self.merchant_country_code+ .as_ref()+ .map(|country_code| country_code.validate_and_get_country_from_merchant_country_code())+ .transpose()+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("Error while parsing country from merchant country code")?;+Ok(domain::ProfileUpdate::Update(Box::new(domain::ProfileGeneralUpdate {profile_name: self.profile_name,@@ -3972,6 +3988,7 @@ impl ProfileUpdateBridge for api::ProfileUpdate {is_iframe_redirection_enabled: self.is_iframe_redirection_enabled,is_pre_network_tokenization_enabled: self.is_pre_network_tokenization_enabled,merchant_category_code: self.merchant_category_code,+ merchant_country_code: self.merchant_country_code,},)))}@@ -4112,6 +4129,7 @@ impl ProfileUpdateBridge for api::ProfileUpdate {.external_vault_connector_details.map(ForeignInto::foreign_into),merchant_category_code: self.merchant_category_code,+ merchant_country_code: self.merchant_country_code,},)))}diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rsindex 31a910a494..2aa1a72e73 100644--- a/crates/router/src/core/payments/operations/payment_confirm.rs+++ b/crates/router/src/core/payments/operations/payment_confirm.rs@@ -1145,6 +1145,15 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for.clone().and_then(|network| business_profile.get_acquirer_details_from_network(network))});+ let country = business_profile+ .merchant_country_code+ .as_ref()+ .map(|country_code| {+ country_code.validate_and_get_country_from_merchant_country_code()+ })+ .transpose()+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("Error while parsing country from merchant country code")?;// get three_ds_decision_rule_output using algorithm_id and payment datalet decision = three_ds_decision_rule::get_three_ds_decision_rule_output(state,@@ -1182,9 +1191,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> forcustomer_device: None,acquirer: acquirer_config.as_ref().map(|acquirer| {api_models::three_ds_decision_rule::AcquirerData {- country: Some(common_enums::Country::from_alpha2(- acquirer.merchant_country_code,- )),+ country,fraud_rate: Some(acquirer.acquirer_fraud_rate),}}),diff --git a/crates/router/src/core/profile_acquirer.rs b/crates/router/src/core/profile_acquirer.rsindex 2e8424c1b2..dbe0beb54b 100644--- a/crates/router/src/core/profile_acquirer.rs+++ b/crates/router/src/core/profile_acquirer.rs@@ -34,7 +34,6 @@ pub async fn create_profile_acquirer(let incoming_acquirer_config = common_types::domain::AcquirerConfig {acquirer_assigned_merchant_id: request.acquirer_assigned_merchant_id.clone(),merchant_name: request.merchant_name.clone(),- merchant_country_code: request.merchant_country_code,network: request.network.clone(),acquirer_bin: request.acquirer_bin.clone(),acquirer_ica: request.acquirer_ica.clone(),@@ -149,9 +148,6 @@ pub async fn update_profile_acquirer_config(request.merchant_name.map(|val| potential_updated_config.merchant_name = val);- request- .merchant_country_code- .map(|val| potential_updated_config.merchant_country_code = val);request.network.map(|val| potential_updated_config.network = val);diff --git a/crates/router/src/types/api/admin.rs b/crates/router/src/types/api/admin.rsindex 17dca9947f..dea8cc0d77 100644--- a/crates/router/src/types/api/admin.rs+++ b/crates/router/src/types/api/admin.rs@@ -230,6 +230,7 @@ impl ForeignTryFrom<domain::Profile> for ProfileResponse {.into(),is_iframe_redirection_enabled: item.is_iframe_redirection_enabled,merchant_category_code: item.merchant_category_code,+ merchant_country_code: item.merchant_country_code,})}}@@ -315,6 +316,7 @@ impl ForeignTryFrom<domain::Profile> for ProfileResponse {.external_vault_connector_details.map(ForeignInto::foreign_into),merchant_category_code: item.merchant_category_code,+ merchant_country_code: item.merchant_country_code,})}}@@ -483,5 +485,6 @@ pub async fn create_profile_from_merchant_account(.is_pre_network_tokenization_enabled.unwrap_or_default(),merchant_category_code: request.merchant_category_code,+ merchant_country_code: request.merchant_country_code,}))}diff --git a/migrations/2025-07-02-071146_add-merchant-country-code-in-business-profile/down.sql b/migrations/2025-07-02-071146_add-merchant-country-code-in-business-profile/down.sqlnew file mode 100644index 0000000000..4edd407e3f--- /dev/null+++ b/migrations/2025-07-02-071146_add-merchant-country-code-in-business-profile/down.sql@@ -0,0 +1,2 @@+-- This file should undo anything in `up.sql`+ALTER TABLE business_profile DROP COLUMN IF EXISTS merchant_country_code;diff --git a/migrations/2025-07-02-071146_add-merchant-country-code-in-business-profile/up.sql b/migrations/2025-07-02-071146_add-merchant-country-code-in-business-profile/up.sqlnew file mode 100644index 0000000000..84f708b59d--- /dev/null+++ b/migrations/2025-07-02-071146_add-merchant-country-code-in-business-profile/up.sql@@ -0,0 +1,3 @@+-- Your SQL goes here+ALTER TABLE business_profile ADD COLUMN IF NOT EXISTS merchant_country_code Varchar(32);+