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(errors): populate error details in response (#10837)
Ayush Anandf4d5f0cabd6b
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.jsonindex 979c35eb36..cd59bdfe89 100644--- a/api-reference/v1/openapi_spec_v1.json+++ b/api-reference/v1/openapi_spec_v1.json@@ -24753,6 +24753,14 @@"type": "string","description": "Value passed in X-CLIENT-VERSION header during payments confirm request by the client","nullable": true+ },+ "error_details": {+ "allOf": [+ {+ "$ref": "#/components/schemas/PaymentErrorDetails"+ }+ ],+ "nullable": true}}},@@ -34263,13 +34271,13 @@"type": "string","enum": ["do_not_retry",- "retry_after10_days",- "retry_after1_hour",- "retry_after24_hours",- "retry_after2_days",- "retry_after4_days",- "retry_after6_days",- "retry_after8_days",+ "retry_after_10_days",+ "retry_after_1_hour",+ "retry_after_24_hours",+ "retry_after_2_days",+ "retry_after_4_days",+ "retry_after_6_days",+ "retry_after_8_days","retry_after_instrument_update","retry_later","retry_with_different_payment_method_data",diff --git a/config/deployments/integration_test.toml b/config/deployments/integration_test.tomlindex d455d61a05..88e5786cc7 100644--- a/config/deployments/integration_test.toml+++ b/config/deployments/integration_test.toml@@ -968,3 +968,27 @@ connector_list = "worldpayvantiv"[grpc_client.unified_connector_service]ucs_only_connectors = "paytm, phonepe" # Comma-separated list of connectors that use UCS onlyucs_psync_disabled_connectors = "cashtocode" # Comma-separated list of connectors to disable UCS PSync call++# Merchant Advice Code Configuration+[merchant_advice_codes.visa]+"01" = { description = "The issuer will never approve (do not reattempt with the same card)", recommended_action = "do_not_retry" }+"02" = { description = "The issuer cannot approve at this time (limit the reattempts with the same card to a maximum of 20 times within 30 days)", recommended_action = "retry_later" }+"03" = { description = "Data quality (monitor for fraud attacks, revalidate the customer data prior to reattempt for a maximum of 20 times within 30 days)", recommended_action = "retry_after_instrument_update" }+"04" = { description = "Generic response codes (limit the reattempts with the same card to a maximum of 20 times within 30 days)", recommended_action = "retry_later" }++[merchant_advice_codes.mastercard]+"01" = { description = "New account information available", recommended_action = "retry_after_instrument_update" }+"02" = { description = "Cannot approve at this time, try again later", recommended_action = "retry_later" }+"03" = { description = "Do not try again", recommended_action = "do_not_retry" }+"04" = { description = "Token not supported", recommended_action = "retry_with_different_payment_method_data" }+"05" = { description = "Negotiated value not approved", recommended_action = "do_not_retry" }+"21" = { description = "Stop recurring payment", recommended_action = "stop_recurring" }+"22" = { description = "Merchant does not qualify for product code", recommended_action = "do_not_retry" }+"24" = { description = "Retry after 1 hour", recommended_action = "retry_after_1_hour" }+"25" = { description = "Retry after 24 hours", recommended_action = "retry_after_24_hours" }+"26" = { description = "Retry after 2 days", recommended_action = "retry_after_2_days" }+"27" = { description = "Retry after 4 days", recommended_action = "retry_after_4_days" }+"28" = { description = "Retry after 6 days", recommended_action = "retry_after_6_days" }+"29" = { description = "Retry after 8 days", recommended_action = "retry_after_8_days" }+"30" = { description = "Retry after 10 days", recommended_action = "retry_after_10_days" }+diff --git a/config/deployments/production.toml b/config/deployments/production.tomlindex 8ece77c8f1..8ecb737a28 100644--- a/config/deployments/production.toml+++ b/config/deployments/production.toml@@ -973,3 +973,26 @@ connector_list = "juspaythreedsserver, ctp_mastercard, ctp_visa"[grpc_client.unified_connector_service]ucs_only_connectors = "paytm, phonepe" # Comma-separated list of connectors that use UCS onlyucs_psync_disabled_connectors = "cashtocode" # Comma-separated list of connectors to disable UCS PSync call++# Merchant Advice Code Configuration+[merchant_advice_codes.visa]+"01" = { description = "The issuer will never approve (do not reattempt with the same card)", recommended_action = "do_not_retry" }+"02" = { description = "The issuer cannot approve at this time (limit the reattempts with the same card to a maximum of 20 times within 30 days)", recommended_action = "retry_later" }+"03" = { description = "Data quality (monitor for fraud attacks, revalidate the customer data prior to reattempt for a maximum of 20 times within 30 days)", recommended_action = "retry_after_instrument_update" }+"04" = { description = "Generic response codes (limit the reattempts with the same card to a maximum of 20 times within 30 days)", recommended_action = "retry_later" }++[merchant_advice_codes.mastercard]+"01" = { description = "New account information available", recommended_action = "retry_after_instrument_update" }+"02" = { description = "Cannot approve at this time, try again later", recommended_action = "retry_later" }+"03" = { description = "Do not try again", recommended_action = "do_not_retry" }+"04" = { description = "Token not supported", recommended_action = "retry_with_different_payment_method_data" }+"05" = { description = "Negotiated value not approved", recommended_action = "do_not_retry" }+"21" = { description = "Stop recurring payment", recommended_action = "stop_recurring" }+"22" = { description = "Merchant does not qualify for product code", recommended_action = "do_not_retry" }+"24" = { description = "Retry after 1 hour", recommended_action = "retry_after_1_hour" }+"25" = { description = "Retry after 24 hours", recommended_action = "retry_after_24_hours" }+"26" = { description = "Retry after 2 days", recommended_action = "retry_after_2_days" }+"27" = { description = "Retry after 4 days", recommended_action = "retry_after_4_days" }+"28" = { description = "Retry after 6 days", recommended_action = "retry_after_6_days" }+"29" = { description = "Retry after 8 days", recommended_action = "retry_after_8_days" }+"30" = { description = "Retry after 10 days", recommended_action = "retry_after_10_days" }diff --git a/config/deployments/sandbox.toml b/config/deployments/sandbox.tomlindex 6d5a61ad5e..e140eb3f63 100644--- a/config/deployments/sandbox.toml+++ b/config/deployments/sandbox.toml@@ -983,3 +983,26 @@ connector_list = "worldpayvantiv"[grpc_client.unified_connector_service]ucs_only_connectors = "paytm, phonepe" # Comma-separated list of connectors that use UCS onlyucs_psync_disabled_connectors = "cashtocode" # Comma-separated list of connectors to disable UCS PSync call++# Merchant Advice Code Configuration+[merchant_advice_codes.visa]+"01" = { description = "The issuer will never approve (do not reattempt with the same card)", recommended_action = "do_not_retry" }+"02" = { description = "The issuer cannot approve at this time (limit the reattempts with the same card to a maximum of 20 times within 30 days)", recommended_action = "retry_later" }+"03" = { description = "Data quality (monitor for fraud attacks, revalidate the customer data prior to reattempt for a maximum of 20 times within 30 days)", recommended_action = "retry_after_instrument_update" }+"04" = { description = "Generic response codes (limit the reattempts with the same card to a maximum of 20 times within 30 days)", recommended_action = "retry_later" }++[merchant_advice_codes.mastercard]+"01" = { description = "New account information available", recommended_action = "retry_after_instrument_update" }+"02" = { description = "Cannot approve at this time, try again later", recommended_action = "retry_later" }+"03" = { description = "Do not try again", recommended_action = "do_not_retry" }+"04" = { description = "Token not supported", recommended_action = "retry_with_different_payment_method_data" }+"05" = { description = "Negotiated value not approved", recommended_action = "do_not_retry" }+"21" = { description = "Stop recurring payment", recommended_action = "stop_recurring" }+"22" = { description = "Merchant does not qualify for product code", recommended_action = "do_not_retry" }+"24" = { description = "Retry after 1 hour", recommended_action = "retry_after_1_hour" }+"25" = { description = "Retry after 24 hours", recommended_action = "retry_after_24_hours" }+"26" = { description = "Retry after 2 days", recommended_action = "retry_after_2_days" }+"27" = { description = "Retry after 4 days", recommended_action = "retry_after_4_days" }+"28" = { description = "Retry after 6 days", recommended_action = "retry_after_6_days" }+"29" = { description = "Retry after 8 days", recommended_action = "retry_after_8_days" }+"30" = { description = "Retry after 10 days", recommended_action = "retry_after_10_days" }diff --git a/config/development.toml b/config/development.tomlindex 5effab8604..75853964e7 100644--- a/config/development.toml+++ b/config/development.toml@@ -1481,5 +1481,28 @@ workspace_id = "dev" # Workspace ID in Superpositionpolling_interval = 15 # Polling interval in seconds for configuration updates# request_timeout = # Request timeout in seconds for Superposition API calls (optional, default: none)+# Merchant Advice Code Configuration+[merchant_advice_codes.visa]+"01" = { description = "The issuer will never approve (do not reattempt with the same card)", recommended_action = "do_not_retry" }+"02" = { description = "The issuer cannot approve at this time (limit the reattempts with the same card to a maximum of 20 times within 30 days)", recommended_action = "retry_later" }+"03" = { description = "Data quality (monitor for fraud attacks, revalidate the customer data prior to reattempt for a maximum of 20 times within 30 days)", recommended_action = "retry_after_instrument_update" }+"04" = { description = "Generic response codes (limit the reattempts with the same card to a maximum of 20 times within 30 days)", recommended_action = "retry_later" }++[merchant_advice_codes.mastercard]+"01" = { description = "New account information available", recommended_action = "retry_after_instrument_update" }+"02" = { description = "Cannot approve at this time, try again later", recommended_action = "retry_later" }+"03" = { description = "Do not try again", recommended_action = "do_not_retry" }+"04" = { description = "Token not supported", recommended_action = "retry_with_different_payment_method_data" }+"05" = { description = "Negotiated value not approved", recommended_action = "do_not_retry" }+"21" = { description = "Stop recurring payment", recommended_action = "stop_recurring" }+"22" = { description = "Merchant does not qualify for product code", recommended_action = "do_not_retry" }+"24" = { description = "Retry after 1 hour", recommended_action = "retry_after_1_hour" }+"25" = { description = "Retry after 24 hours", recommended_action = "retry_after_24_hours" }+"26" = { description = "Retry after 2 days", recommended_action = "retry_after_2_days" }+"27" = { description = "Retry after 4 days", recommended_action = "retry_after_4_days" }+"28" = { description = "Retry after 6 days", recommended_action = "retry_after_6_days" }+"29" = { description = "Retry after 8 days", recommended_action = "retry_after_8_days" }+"30" = { description = "Retry after 10 days", recommended_action = "retry_after_10_days" }+[micro_services]payment_methods_base_url = "http://localhost:8082"diff --git a/config/docker_compose.toml b/config/docker_compose.tomlindex 65326dd6d2..d8502d7198 100644--- a/config/docker_compose.toml+++ b/config/docker_compose.toml@@ -1364,3 +1364,26 @@ org_id = "localorg" # Organization ID in Superpositionworkspace_id = "dev" # Workspace ID in Superpositionpolling_interval = 15 # Polling interval in seconds for configuration updates# request_timeout = # Request timeout in seconds for Superposition API calls (optional, default: none)++# Merchant Advice Code Configuration+[merchant_advice_codes.visa]+"01" = { description = "The issuer will never approve (do not reattempt with the same card)", recommended_action = "do_not_retry" }+"02" = { description = "The issuer cannot approve at this time (limit the reattempts with the same card to a maximum of 20 times within 30 days)", recommended_action = "retry_later" }+"03" = { description = "Data quality (monitor for fraud attacks, revalidate the customer data prior to reattempt for a maximum of 20 times within 30 days)", recommended_action = "retry_after_instrument_update" }+"04" = { description = "Generic response codes (limit the reattempts with the same card to a maximum of 20 times within 30 days)", recommended_action = "retry_later" }++[merchant_advice_codes.mastercard]+"01" = { description = "New account information available", recommended_action = "retry_after_instrument_update" }+"02" = { description = "Cannot approve at this time, try again later", recommended_action = "retry_later" }+"03" = { description = "Do not try again", recommended_action = "do_not_retry" }+"04" = { description = "Token not supported", recommended_action = "retry_with_different_payment_method_data" }+"05" = { description = "Negotiated value not approved", recommended_action = "do_not_retry" }+"21" = { description = "Stop recurring payment", recommended_action = "stop_recurring" }+"22" = { description = "Merchant does not qualify for product code", recommended_action = "do_not_retry" }+"24" = { description = "Retry after 1 hour", recommended_action = "retry_after_1_hour" }+"25" = { description = "Retry after 24 hours", recommended_action = "retry_after_24_hours" }+"26" = { description = "Retry after 2 days", recommended_action = "retry_after_2_days" }+"27" = { description = "Retry after 4 days", recommended_action = "retry_after_4_days" }+"28" = { description = "Retry after 6 days", recommended_action = "retry_after_6_days" }+"29" = { description = "Retry after 8 days", recommended_action = "retry_after_8_days" }+"30" = { description = "Retry after 10 days", recommended_action = "retry_after_10_days" }diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rsindex 79a060f4a5..45bd2be5d7 100644--- a/crates/api_models/src/payments.rs+++ b/crates/api_models/src/payments.rs@@ -2021,6 +2021,10 @@ pub struct PaymentAttemptResponse {/// Value passed in X-CLIENT-VERSION header during payments confirm request by the client#[smithy(value_type = "Option<String>")]pub client_version: Option<String>,+ /// Complete error details containing unified, issuer, and connector-level error information+ #[schema(value_type = Option<PaymentErrorDetails>)]+ #[smithy(value_type = "Option<PaymentErrorDetails>")]+ pub error_details: Option<PaymentErrorDetails>,}#[cfg(feature = "v2")]diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rsindex 8053a96fee..a34f0422ef 100644--- a/crates/common_enums/src/enums.rs+++ b/crates/common_enums/src/enums.rs@@ -360,12 +360,19 @@ pub enum GsmDecision {#[router_derive::diesel_enum(storage_type = "text")]pub enum RecommendedAction {DoNotRetry,+ #[serde(rename = "retry_after_10_days")]RetryAfter10Days,+ #[serde(rename = "retry_after_1_hour")]RetryAfter1Hour,+ #[serde(rename = "retry_after_24_hours")]RetryAfter24Hours,+ #[serde(rename = "retry_after_2_days")]RetryAfter2Days,+ #[serde(rename = "retry_after_4_days")]RetryAfter4Days,+ #[serde(rename = "retry_after_6_days")]RetryAfter6Days,+ #[serde(rename = "retry_after_8_days")]RetryAfter8Days,RetryAfterInstrumentUpdate,RetryLater,diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rsindex 6edffec33d..02694a7717 100644--- a/crates/diesel_models/src/payment_attempt.rs+++ b/crates/diesel_models/src/payment_attempt.rs@@ -674,7 +674,7 @@ pub enum PaymentAttemptUpdate {setup_future_usage_applied: Option<storage_enums::FutureUsage>,is_overcapture_enabled: Option<OvercaptureEnabledBool>,authorized_amount: Option<MinorUnit>,- error_details: Box<Option<ErrorDetails>>,+ error_details: Box<Option<Option<ErrorDetails>>>,},UnresolvedResponseUpdate {status: storage_enums::AttemptStatus,@@ -686,7 +686,7 @@ pub enum PaymentAttemptUpdate {error_reason: Option<Option<String>>,connector_response_reference_id: Option<String>,updated_by: String,- error_details: Box<Option<ErrorDetails>>,+ error_details: Box<Option<Option<ErrorDetails>>>,},StatusUpdate {status: storage_enums::AttemptStatus,@@ -707,10 +707,10 @@ pub enum PaymentAttemptUpdate {payment_method_data: Option<serde_json::Value>,encrypted_payment_method_data: Option<common_utils::encryption::Encryption>,authentication_type: Option<storage_enums::AuthenticationType>,- issuer_error_code: Option<String>,- issuer_error_message: Option<String>,- network_details: Option<NetworkDetails>,- error_details: Box<Option<ErrorDetails>>,+ issuer_error_code: Option<Option<String>>,+ issuer_error_message: Option<Option<String>>,+ network_details: Option<Option<NetworkDetails>>,+ error_details: Box<Option<Option<ErrorDetails>>>,},CaptureUpdate {amount_to_capture: Option<MinorUnit>,@@ -1202,7 +1202,7 @@ pub struct PaymentAttemptUpdateInternal {pub is_stored_credential: Option<bool>,pub request_extended_authorization: Option<RequestExtendedAuthorizationBool>,pub authorized_amount: Option<MinorUnit>,- pub error_details: Option<ErrorDetails>,+ pub error_details: Option<Option<ErrorDetails>>,}#[cfg(feature = "v1")]@@ -1485,7 +1485,7 @@ impl PaymentAttemptUpdate {.or(source.request_extended_authorization),authorized_amount: authorized_amount.or(source.authorized_amount),tokenization: tokenization.or(source.tokenization),- error_details: error_details.or(source.error_details),+ error_details: error_details.unwrap_or(source.error_details),..source}}@@ -3559,8 +3559,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {payment_method_data,authentication_type,processor_transaction_data,- issuer_error_code,- issuer_error_message,+ issuer_error_code: issuer_error_code.flatten(),+ issuer_error_message: issuer_error_message.flatten(),amount: None,net_amount: None,currency: None,@@ -3608,7 +3608,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {connector_request_reference_id: None,network_transaction_id: None,is_overcapture_enabled: None,- network_details,+ network_details: network_details.flatten(),is_stored_credential: None,request_extended_authorization: None,authorized_amount: None,diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rsindex 3d607d89af..b07ce4cfb8 100644--- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs+++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs@@ -22,7 +22,8 @@ use common_utils::{};#[cfg(feature = "v1")]use diesel_models::{- ConnectorMandateReferenceId, NetworkDetails, PaymentAttemptUpdate as DieselPaymentAttemptUpdate,+ ConnectorMandateReferenceId, ErrorDetails as DieselErrorDetails, NetworkDetails,+ PaymentAttemptUpdate as DieselPaymentAttemptUpdate,};use diesel_models::{PaymentAttempt as DieselPaymentAttempt, PaymentAttemptNew as DieselPaymentAttemptNew,@@ -396,6 +397,323 @@ impl From<ErrorDetails> for api_models::payments::RecordAttemptErrorDetails {}}+#[cfg(feature = "v1")]+#[derive(Clone, Default, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]+pub struct PaymentAttemptErrorDetails {+ pub unified_details: Option<UnifiedErrorDetails>,+ pub issuer_details: Option<IssuerErrorDetails>,+ pub connector_details: Option<ConnectorErrorDetails>,+}++#[cfg(feature = "v1")]+impl PaymentAttemptErrorDetails {+ fn new(+ unified_details: Option<Option<UnifiedErrorDetails>>,+ issuer_details: Option<Option<IssuerErrorDetails>>,+ connector_details: Option<Option<ConnectorErrorDetails>>,+ ) -> Option<Option<Self>> {+ if connector_details.is_none() && unified_details.is_none() && issuer_details.is_none() {+ None+ } else {+ let unified_details_val = unified_details.flatten();+ let issuer_details_val = issuer_details.flatten();+ let connector_details_val = connector_details.flatten();++ if connector_details_val.is_some()+ || unified_details_val.is_some()+ || issuer_details_val.is_some()+ {+ Some(Some(Self {+ unified_details: unified_details_val,+ issuer_details: issuer_details_val,+ connector_details: connector_details_val,+ }))+ } else {+ Some(None)+ }+ }+ }+}++#[cfg(feature = "v1")]+#[derive(Clone, Default, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]+pub struct UnifiedErrorDetails {+ pub category: Option<String>,+ pub message: Option<String>,+ pub standardised_code: Option<storage_enums::StandardisedCode>,+ pub description: Option<String>,+ pub user_guidance_message: Option<String>,+ pub recommended_action: Option<storage_enums::RecommendedAction>,+}++#[cfg(feature = "v1")]+impl UnifiedErrorDetails {+ fn new(+ category: Option<Option<String>>,+ message: Option<Option<String>>,+ standardised_code: Option<Option<storage_enums::StandardisedCode>>,+ description: Option<Option<String>>,+ user_guidance_message: Option<Option<String>>,+ recommended_action: Option<Option<storage_enums::RecommendedAction>>,+ ) -> Option<Option<Self>> {+ if category.is_none()+ && message.is_none()+ && standardised_code.is_none()+ && description.is_none()+ && user_guidance_message.is_none()+ && recommended_action.is_none()+ {+ None+ } else {+ let category_val = category.flatten();+ let message_val = message.flatten();+ let standardised_code_val = standardised_code.flatten();+ let description_val = description.flatten();+ let user_guidance_message_val = user_guidance_message.flatten();+ let recommended_action_val = recommended_action.flatten();++ if category_val.is_some()+ || message_val.is_some()+ || standardised_code_val.is_some()+ || description_val.is_some()+ || user_guidance_message_val.is_some()+ || recommended_action_val.is_some()+ {+ Some(Some(Self {+ category: category_val,+ message: message_val,+ standardised_code: standardised_code_val,+ description: description_val,+ user_guidance_message: user_guidance_message_val,+ recommended_action: recommended_action_val,+ }))+ } else {+ Some(None)+ }+ }+ }+}++#[cfg(feature = "v1")]+#[derive(Clone, Default, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]+pub struct IssuerErrorDetails {+ pub code: Option<String>,+ pub message: Option<String>,+ pub network_details: Option<NetworkErrorDetails>,+}++#[cfg(feature = "v1")]+impl IssuerErrorDetails {+ fn new(+ code: Option<Option<String>>,+ message: Option<Option<String>>,+ network_details: Option<Option<NetworkErrorDetails>>,+ ) -> Option<Option<Self>> {+ if code.is_none() && message.is_none() && network_details.is_none() {+ None+ } else {+ let code_val = code.flatten();+ let message_val = message.flatten();+ let network_details_val = network_details.flatten();++ if code_val.is_some() || message_val.is_some() || network_details_val.is_some() {+ Some(Some(Self {+ code: code_val,+ message: message_val,+ network_details: network_details_val,+ }))+ } else {+ Some(None)+ }+ }+ }+}++#[cfg(feature = "v1")]+#[derive(Clone, Default, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]+pub struct NetworkErrorDetails {+ pub name: Option<storage_enums::CardNetwork>,+ pub advice_code: Option<String>,+ pub advice_message: Option<String>,+}++#[cfg(feature = "v1")]+impl NetworkErrorDetails {+ fn new(+ network_details: Option<Option<NetworkDetails>>,+ network_error_message: Option<Option<String>>,+ card_network: Option<storage_enums::CardNetwork>,+ ) -> Option<Option<Self>> {+ if network_details.is_none() && network_error_message.is_none() {+ None+ } else {+ let network_details_val = network_details.flatten();+ let network_error_message_val = network_error_message.flatten();++ if network_details_val.is_some() || network_error_message_val.is_some() {+ Some(Some(Self {+ name: card_network,+ advice_code: network_details_val.and_then(|n| n.network_advice_code),+ advice_message: network_error_message_val,+ }))+ } else {+ Some(None)+ }+ }+ }+}++#[cfg(feature = "v1")]+#[derive(Clone, Default, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]+pub struct ConnectorErrorDetails {+ pub code: Option<String>,+ pub message: Option<String>,+ pub reason: Option<String>,+}++#[cfg(feature = "v1")]+impl ConnectorErrorDetails {+ fn new(+ code: Option<Option<String>>,+ message: Option<Option<String>>,+ reason: Option<Option<String>>,+ ) -> Option<Option<Self>> {+ if code.is_none() && message.is_none() && reason.is_none() {+ None+ } else {+ let code_val = code.flatten();+ let message_val = message.flatten();+ let reason_val = reason.flatten();++ if code_val.is_some() || message_val.is_some() || reason_val.is_some() {+ Some(Some(Self {+ code: code_val,+ message: message_val,+ reason: reason_val,+ }))+ } else {+ Some(None)+ }+ }+ }+}++#[cfg(feature = "v1")]+impl From<PaymentAttemptErrorDetails> for DieselErrorDetails {+ fn from(domain: PaymentAttemptErrorDetails) -> Self {+ Self {+ unified_details: domain.unified_details.map(Into::into),+ issuer_details: domain.issuer_details.map(Into::into),+ connector_details: domain.connector_details.map(Into::into),+ }+ }+}++#[cfg(feature = "v1")]+impl From<DieselErrorDetails> for PaymentAttemptErrorDetails {+ fn from(diesel: DieselErrorDetails) -> Self {+ Self {+ unified_details: diesel.unified_details.map(Into::into),+ issuer_details: diesel.issuer_details.map(Into::into),+ connector_details: diesel.connector_details.map(Into::into),+ }+ }+}++#[cfg(feature = "v1")]+impl From<UnifiedErrorDetails> for diesel_models::UnifiedErrorDetails {+ fn from(domain: UnifiedErrorDetails) -> Self {+ Self {+ category: domain.category,+ message: domain.message,+ standardised_code: domain.standardised_code,+ description: domain.description,+ user_guidance_message: domain.user_guidance_message,+ recommended_action: domain.recommended_action,+ }+ }+}++#[cfg(feature = "v1")]+impl From<diesel_models::UnifiedErrorDetails> for UnifiedErrorDetails {+ fn from(diesel: diesel_models::UnifiedErrorDetails) -> Self {+ Self {+ category: diesel.category,+ message: diesel.message,+ standardised_code: diesel.standardised_code,+ description: diesel.description,+ user_guidance_message: diesel.user_guidance_message,+ recommended_action: diesel.recommended_action,+ }+ }+}++#[cfg(feature = "v1")]+impl From<IssuerErrorDetails> for diesel_models::IssuerErrorDetails {+ fn from(domain: IssuerErrorDetails) -> Self {+ Self {+ code: domain.code,+ message: domain.message,+ network_details: domain.network_details.map(Into::into),+ }+ }+}++#[cfg(feature = "v1")]+impl From<diesel_models::IssuerErrorDetails> for IssuerErrorDetails {+ fn from(diesel: diesel_models::IssuerErrorDetails) -> Self {+ Self {+ code: diesel.code,+ message: diesel.message,+ network_details: diesel.network_details.map(Into::into),+ }+ }+}++#[cfg(feature = "v1")]+impl From<NetworkErrorDetails> for diesel_models::NetworkErrorDetails {+ fn from(domain: NetworkErrorDetails) -> Self {+ Self {+ name: domain.name,+ advice_code: domain.advice_code,+ advice_message: domain.advice_message,+ }+ }+}++#[cfg(feature = "v1")]+impl From<diesel_models::NetworkErrorDetails> for NetworkErrorDetails {+ fn from(diesel: diesel_models::NetworkErrorDetails) -> Self {+ Self {+ name: diesel.name,+ advice_code: diesel.advice_code,+ advice_message: diesel.advice_message,+ }+ }+}++#[cfg(feature = "v1")]+impl From<ConnectorErrorDetails> for diesel_models::ConnectorErrorDetails {+ fn from(domain: ConnectorErrorDetails) -> Self {+ Self {+ code: domain.code,+ message: domain.message,+ reason: domain.reason,+ }+ }+}++#[cfg(feature = "v1")]+impl From<diesel_models::ConnectorErrorDetails> for ConnectorErrorDetails {+ fn from(diesel: diesel_models::ConnectorErrorDetails) -> Self {+ Self {+ code: diesel.code,+ message: diesel.message,+ reason: diesel.reason,+ }+ }+}+/// Domain model for the payment attempt./// Few fields which are related are grouped together for better readability and understandability./// These fields will be flattened and stored in the database in individual columns@@ -1063,7 +1381,7 @@ pub struct PaymentAttempt {#[encrypt(ty = Value)]pub encrypted_payment_method_data: Option<Encryptable<pii::SecretSerdeValue>>,/// Complete error details containing unified, issuer, and connector-level error information- pub error_details: Option<diesel_models::payment_attempt::ErrorDetails>,+ pub error_details: Option<PaymentAttemptErrorDetails>,}#[cfg(feature = "v1")]@@ -1585,18 +1903,27 @@ pub enum PaymentAttemptUpdate {encoded_data: Option<String>,unified_code: Option<Option<String>>,unified_message: Option<Option<String>>,+ standardised_code: Option<Option<storage_enums::StandardisedCode>>,+ description: Option<Option<String>>,+ user_guidance_message: Option<Option<String>>,capture_before: Option<PrimitiveDateTime>,extended_authorization_last_applied_at: Option<PrimitiveDateTime>,extended_authorization_applied: Option<ExtendedAuthorizationAppliedBool>,payment_method_data: Option<Value>,encrypted_payment_method_data: Option<Encryptable<pii::SecretSerdeValue>>,- connector_mandate_detail: Option<ConnectorMandateReferenceId>,+ connector_mandate_detail: Box<Option<ConnectorMandateReferenceId>>,tokenization: Option<common_enums::Tokenization>,charges: Option<common_types::payments::ConnectorChargeResponseData>,setup_future_usage_applied: Option<storage_enums::FutureUsage>,debit_routing_savings: Option<MinorUnit>,is_overcapture_enabled: Option<OvercaptureEnabledBool>,authorized_amount: Option<MinorUnit>,+ issuer_error_code: Option<Option<String>>,+ issuer_error_message: Option<Option<String>>,+ network_details: Option<Option<NetworkDetails>>,+ network_error_message: Option<Option<String>>,+ recommended_action: Option<Option<storage_enums::RecommendedAction>>,+ card_network: Option<storage_enums::CardNetwork>,},UnresolvedResponseUpdate {status: storage_enums::AttemptStatus,@@ -1623,14 +1950,20 @@ pub enum PaymentAttemptUpdate {updated_by: String,unified_code: Option<Option<String>>,unified_message: Option<Option<String>>,+ standardised_code: Option<Option<storage_enums::StandardisedCode>>,+ description: Option<Option<String>>,+ user_guidance_message: Option<Option<String>>,connector_transaction_id: Option<String>,connector_response_reference_id: Option<String>,payment_method_data: Option<Value>,encrypted_payment_method_data: Option<Encryptable<pii::SecretSerdeValue>>,authentication_type: Option<storage_enums::AuthenticationType>,- issuer_error_code: Option<String>,- issuer_error_message: Option<String>,- network_details: Option<NetworkDetails>,+ issuer_error_code: Option<Option<String>>,+ issuer_error_message: Option<Option<String>>,+ network_details: Option<Option<NetworkDetails>>,+ network_error_message: Option<Option<String>>,+ recommended_action: Option<Option<storage_enums::RecommendedAction>>,+ card_network: Option<storage_enums::CardNetwork>,},CaptureUpdate {amount_to_capture: Option<MinorUnit>,@@ -1908,6 +2241,9 @@ impl PaymentAttemptUpdate {encoded_data,unified_code,unified_message,+ standardised_code,+ description,+ user_guidance_message,capture_before,extended_authorization_applied,extended_authorization_last_applied_at,@@ -1921,39 +2257,79 @@ impl PaymentAttemptUpdate {debit_routing_savings: _,is_overcapture_enabled,authorized_amount,- } => DieselPaymentAttemptUpdate::ResponseUpdate {- status,- connector,- connector_transaction_id,- authentication_type,- payment_method_id,- mandate_id,- connector_metadata,- payment_token,- error_code,- error_message,- error_reason,- connector_response_reference_id,- amount_capturable,- updated_by,- authentication_data,- encoded_data,- unified_code,- unified_message,- capture_before,- extended_authorization_applied,- extended_authorization_last_applied_at,- payment_method_data,- connector_mandate_detail,- tokenization,- charges,- setup_future_usage_applied,- network_transaction_id,- is_overcapture_enabled,- authorized_amount,- encrypted_payment_method_data: encrypted_payment_method_data.map(Encryption::from),- error_details: Box::new(None),- },+ issuer_error_code,+ issuer_error_message,+ network_details,+ network_error_message,+ recommended_action,+ card_network,+ } => {+ let connector_details = ConnectorErrorDetails::new(+ error_code.clone(),+ error_message.clone(),+ error_reason.clone(),+ );+ let unified_details = UnifiedErrorDetails::new(+ unified_code.clone(),+ unified_message.clone(),+ standardised_code,+ description.clone(),+ user_guidance_message.clone(),+ recommended_action,+ );+ let network_error_details = NetworkErrorDetails::new(+ network_details,+ network_error_message.clone(),+ card_network,+ );+ let issuer_details = IssuerErrorDetails::new(+ issuer_error_code.clone(),+ issuer_error_message.clone(),+ network_error_details,+ );+ let error_details = Box::new(+ PaymentAttemptErrorDetails::new(+ unified_details,+ issuer_details,+ connector_details,+ )+ .map(|opt| opt.map(Into::into)),+ );+ DieselPaymentAttemptUpdate::ResponseUpdate {+ status,+ connector,+ connector_transaction_id,+ authentication_type,+ payment_method_id,+ mandate_id,+ connector_metadata,+ payment_token,+ error_code,+ error_message,+ error_reason,+ connector_response_reference_id,+ amount_capturable,+ updated_by,+ authentication_data,+ encoded_data,+ unified_code,+ unified_message,+ capture_before,+ extended_authorization_applied,+ extended_authorization_last_applied_at,+ payment_method_data,+ connector_mandate_detail: *connector_mandate_detail,+ tokenization,+ charges,+ setup_future_usage_applied,+ network_transaction_id,+ is_overcapture_enabled,+ authorized_amount,+ encrypted_payment_method_data: encrypted_payment_method_data+ .map(Encryption::from),+ error_details,+ }+ }Self::UnresolvedResponseUpdate {status,connector,@@ -1964,18 +2340,45 @@ impl PaymentAttemptUpdate {error_reason,connector_response_reference_id,updated_by,- } => DieselPaymentAttemptUpdate::UnresolvedResponseUpdate {- status,- connector,- connector_transaction_id,- payment_method_id,- error_code,- error_message,- error_reason,- connector_response_reference_id,- updated_by,- error_details: Box::new(None),- },+ } => {+ let connector_details = ConnectorErrorDetails::new(+ error_code.clone(),+ error_message.clone(),+ error_reason.clone(),+ );+ // This flow is used by crypto payment connectors (Coinbase, OpenNode) for ambiguous payment states+ // (e.g., underpayment, context issues) that require manual resolution in the connector's dashboard.+ // Since these are not standard payment failures, unified error details (GSM codes, user guidance) are not applicable.+ let unified_details = UnifiedErrorDetails::new(+ None, // unified_code+ None, // unified_message+ None, // standardised_code+ None, // description+ None, // user_guidance_message+ None, // recommended_action+ );+ let issuer_details = IssuerErrorDetails::new(None, None, None);+ let error_details = Box::new(+ PaymentAttemptErrorDetails::new(+ unified_details,+ issuer_details,+ connector_details,+ )+ .map(|opt| opt.map(Into::into)),+ );+ DieselPaymentAttemptUpdate::UnresolvedResponseUpdate {+ status,+ connector,+ connector_transaction_id,+ payment_method_id,+ error_code,+ error_message,+ error_reason,+ connector_response_reference_id,+ updated_by,+ error_details,+ }+ }Self::StatusUpdate { status, updated_by } => {DieselPaymentAttemptUpdate::StatusUpdate { status, updated_by }}@@ -1989,6 +2392,9 @@ impl PaymentAttemptUpdate {updated_by,unified_code,unified_message,+ standardised_code,+ description,+ user_guidance_message,connector_transaction_id,connector_response_reference_id,payment_method_data,@@ -1996,27 +2402,64 @@ impl PaymentAttemptUpdate {issuer_error_code,issuer_error_message,network_details,+ network_error_message,encrypted_payment_method_data,- } => DieselPaymentAttemptUpdate::ErrorUpdate {- connector,- status,- error_code,- error_message,- error_reason,- amount_capturable,- updated_by,- unified_code,- unified_message,- connector_transaction_id,- connector_response_reference_id,- payment_method_data,- authentication_type,- issuer_error_code,- issuer_error_message,- network_details,- encrypted_payment_method_data: encrypted_payment_method_data.map(Encryption::from),- error_details: Box::new(None),- },+ recommended_action,+ card_network,+ } => {+ let connector_details = ConnectorErrorDetails::new(+ error_code.clone(),+ error_message.clone(),+ error_reason.clone(),+ );+ let unified_details = UnifiedErrorDetails::new(+ unified_code.clone(),+ unified_message.clone(),+ standardised_code,+ description.clone(),+ user_guidance_message.clone(),+ recommended_action,+ );+ let network_error_details = NetworkErrorDetails::new(+ network_details.clone(),+ network_error_message.clone(),+ card_network,+ );+ let issuer_details = IssuerErrorDetails::new(+ issuer_error_code.clone(),+ issuer_error_message.clone(),+ network_error_details,+ );+ let error_details = Box::new(+ PaymentAttemptErrorDetails::new(+ unified_details,+ issuer_details,+ connector_details,+ )+ .map(|opt| opt.map(Into::into)),+ );+ DieselPaymentAttemptUpdate::ErrorUpdate {+ connector,+ status,+ error_code,+ error_message,+ error_reason,+ amount_capturable,+ updated_by,+ unified_code,+ unified_message,+ connector_transaction_id,+ connector_response_reference_id,+ payment_method_data,+ authentication_type,+ issuer_error_code,+ issuer_error_message,+ network_details,+ encrypted_payment_method_data: encrypted_payment_method_data+ .map(Encryption::from),+ error_details,+ }+ }Self::CaptureUpdate {multiple_capture_count,updated_by,@@ -2342,7 +2785,7 @@ impl behaviour::Conversion for PaymentAttempt {issuer_error_code: self.issuer_error_code,issuer_error_message: self.issuer_error_message,setup_future_usage_applied: self.setup_future_usage_applied,- error_details: self.error_details,+ error_details: self.error_details.map(Into::into),// Below fields are deprecated. Please add any new fields above this line.connector_transaction_data: None,processor_merchant_id: Some(self.processor_merchant_id),@@ -2481,7 +2924,7 @@ impl behaviour::Conversion for PaymentAttempt {is_stored_credential: storage_model.is_stored_credential,authorized_amount: storage_model.authorized_amount,encrypted_payment_method_data,- error_details: storage_model.error_details,+ error_details: storage_model.error_details.map(Into::into),})}.await@@ -2579,7 +3022,7 @@ impl behaviour::Conversion for PaymentAttempt {is_stored_credential: self.is_stored_credential,authorized_amount: self.authorized_amount,encrypted_payment_method_data: self.encrypted_payment_method_data.map(Encryption::from),- error_details: None,+ error_details: self.error_details.map(Into::into),})}}diff --git a/crates/router/src/configs/secrets_transformers.rs b/crates/router/src/configs/secrets_transformers.rsindex 2e71f1ee99..a8fa1f82ef 100644--- a/crates/router/src/configs/secrets_transformers.rs+++ b/crates/router/src/configs/secrets_transformers.rs@@ -627,6 +627,7 @@ pub(crate) async fn fetch_raw_secrets(open_router: conf.open_router,#[cfg(feature = "v2")]revenue_recovery: conf.revenue_recovery,+ merchant_advice_codes: conf.merchant_advice_codes,debit_routing_config: conf.debit_routing_config,clone_connector_allowlist: conf.clone_connector_allowlist,merchant_id_auth: conf.merchant_id_auth,diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rsindex 45200d9e05..066e0b47bd 100644--- a/crates/router/src/configs/settings.rs+++ b/crates/router/src/configs/settings.rs@@ -172,6 +172,7 @@ pub struct Settings<S: SecretState> {pub open_router: OpenRouter,#[cfg(feature = "v2")]pub revenue_recovery: revenue_recovery::RevenueRecoverySettings,+ pub merchant_advice_codes: MerchantAdviceCodeLookupConfig,pub clone_connector_allowlist: Option<CloneConnectorAllowlistConfig>,pub merchant_id_auth: MerchantIdAuthSettings,pub internal_merchant_id_profile_id_auth: InternalMerchantIdProfileIdAuthSettings,@@ -1043,6 +1044,63 @@ pub struct NetworkTokenizationSupportedConnectors {pub connector_list: HashSet<enums::Connector>,}+/// Configuration structure for individual merchant advice code+#[derive(Debug, Deserialize, Clone)]+pub struct MerchantAdviceCodeConfig {+ pub recommended_action: common_enums::RecommendedAction,+ pub description: Option<String>,+}++/// Domain type for merchant advice code mappings+#[derive(Debug, Clone, Default, Deserialize)]+#[serde(transparent)]+pub struct MerchantAdviceCodeMap(HashMap<String, MerchantAdviceCodeConfig>);++impl MerchantAdviceCodeMap {+ /// Get merchant advice code configuration for a specific advice code+ /// Pads single digit codes to double digit (e.g., "1" -> "01")+ pub fn get_config(&self, advice_code: &str) -> Option<&MerchantAdviceCodeConfig> {+ let padded_code = format!("{:0>2}", advice_code);+ self.0.get(&padded_code)+ }+}++/// Each network has its own field for direct lookup+#[derive(Debug, Clone, Default, Deserialize)]+pub struct MerchantAdviceCodeLookupConfig {+ pub visa: Option<MerchantAdviceCodeMap>,+ pub mastercard: Option<MerchantAdviceCodeMap>,+}++impl MerchantAdviceCodeLookupConfig {+ /// Get merchant advice code configuration for a specific network and advice code+ pub fn get_config(+ &self,+ network: &common_enums::CardNetwork,+ advice_code: &str,+ ) -> Option<&MerchantAdviceCodeConfig> {+ match network {+ common_enums::CardNetwork::Visa => self.visa.as_ref()?.get_config(advice_code),+ common_enums::CardNetwork::Mastercard => {+ self.mastercard.as_ref()?.get_config(advice_code)+ }+ common_enums::CardNetwork::AmericanExpress+ | common_enums::CardNetwork::JCB+ | common_enums::CardNetwork::DinersClub+ | common_enums::CardNetwork::Discover+ | common_enums::CardNetwork::CartesBancaires+ | common_enums::CardNetwork::UnionPay+ | common_enums::CardNetwork::Interac+ | common_enums::CardNetwork::RuPay+ | common_enums::CardNetwork::Maestro+ | common_enums::CardNetwork::Star+ | common_enums::CardNetwork::Pulse+ | common_enums::CardNetwork::Accel+ | common_enums::CardNetwork::Nyce => None,+ }+ }+}+impl Settings<SecuredSecret> {pub fn new() -> ApplicationResult<Self> {Self::with_config_path(None)diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rsindex b1d01300ca..c248db3662 100644--- a/crates/router/src/core/payments.rs+++ b/crates/router/src/core/payments.rs@@ -11128,14 +11128,17 @@ pub async fn payments_manual_update(.zip(error_message.as_ref()).zip(payment_attempt.connector.as_ref()){+ let card_network = payment_attempt.extract_card_network();helpers::get_gsm_record(&state,- Some(code.to_string()),- Some(message.to_string()),connector_name.to_string(),// We need to get the unified_code and unified_message of the Authorize flowconsts::PAYMENT_FLOW_STR,consts::AUTHORIZE_FLOW_STR,+ Some(code.to_string()),+ Some(message.to_string()),+ None, // issuer_error_code not available in manual update+ card_network,).await} else {diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rsindex 6d2a2cf41c..3bd8979140 100644--- a/crates/router/src/core/payments/helpers.rs+++ b/crates/router/src/core/payments/helpers.rs@@ -74,7 +74,9 @@ use crate::core::{utils as core_utils,};use crate::{- configs::settings::{ConnectorRequestReferenceIdConfig, TempLockerEnableConfig},+ configs::settings::{+ ConnectorRequestReferenceIdConfig, MerchantAdviceCodeLookupConfig, TempLockerEnableConfig,+ },connector,consts::{self, BASE64_ENGINE},core::{@@ -7058,7 +7060,59 @@ pub fn validate_payment_link_request(Ok(())}+/// Creates a lookup key for issuer error codes with network and code+/// Returns format: "Network:{network}|IssuerCode:{code:0>2}"+fn create_issuer_code_lookup_key(network: &common_enums::CardNetwork, issuer_code: &str) -> String {+ format!("Network:{}|IssuerCode:{:0>2}", network, issuer_code)+}++#[allow(clippy::too_many_arguments)]pub async fn get_gsm_record(+ state: &SessionState,+ connector_name: String,+ flow: &str,+ sub_flow: &str,+ connector_error_code: Option<String>,+ connector_error_message: Option<String>,+ issuer_error_code: Option<String>,+ card_network: Option<common_enums::CardNetwork>,+) -> Option<hyperswitch_domain_models::gsm::GatewayStatusMap> {+ // Priority 1: Try issuer_code lookup (requires both card_network and issuer_error_code)+ let issuer_result =+ if let (Some(network), Some(issuer_code)) = (&card_network, &issuer_error_code) {+ let issuer_lookup_key = create_issuer_code_lookup_key(network, issuer_code);+ perform_gsm_lookup(+ state,+ Some(issuer_lookup_key.clone()),+ Some(issuer_lookup_key),+ connector_name.clone(),+ flow,+ sub_flow,+ )+ .await+ } else {+ None+ };++ match issuer_result {+ Some(result) => Some(result),+ None => {+ // Priority 2: Fallback to connector_error_code lookup+ perform_gsm_lookup(+ state,+ connector_error_code,+ connector_error_message,+ connector_name,+ flow,+ sub_flow,+ )+ .await+ }+ }+}++/// Perform GSM lookup with the given error code and message.+async fn perform_gsm_lookup(state: &SessionState,error_code: Option<String>,error_message: Option<String>,@@ -7136,6 +7190,7 @@ pub async fn get_unified_translation(}).ok()}+pub fn validate_order_details_amount(order_details: Vec<api_models::payments::OrderDetailsWithAmount>,amount: MinorUnit,@@ -8372,3 +8427,33 @@ where.map(|profile_id| format!("{}_{}", connector_name, profile_id.get_string_repr()))}}++/// Lookup recommended action from merchant advice codes configuration.+pub fn get_merchant_advice_code_recommended_action(+ config: &MerchantAdviceCodeLookupConfig,+ off_session: Option<bool>,+ network: Option<&common_enums::CardNetwork>,+ advice_code: Option<&str>,+) -> Option<common_enums::RecommendedAction> {+ match (off_session, network, advice_code) {+ (Some(true), Some(network), Some(advice_code)) => config+ .get_config(network, advice_code)+ .map(|config| config.recommended_action)+ .or_else(|| {+ metrics::MERCHANT_ADVICE_CODE_CONFIG_MISS.add(+ 1,+ router_env::metric_attributes!(+ ("network", network.to_string()),+ ("advice_code", advice_code.to_owned()),+ ),+ );+ logger::warn!(+ network = %network,+ advice_code = %advice_code,+ "No merchant advice code config found"+ );+ None+ }),+ _ => None,+ }+}diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rsindex edccc97be4..01a535ba9d 100644--- a/crates/router/src/core/payments/operations/payment_response.rs+++ b/crates/router/src/core/payments/operations/payment_response.rs@@ -1546,22 +1546,44 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>()}None => {- let connector_name = router_data.connector.to_string();let sub_flow = core_utils::get_flow_name::<F>()?;++ let card_network = payment_data.payment_attempt.extract_card_network();++ // GSM lookup for error object constructionlet option_gsm = payments_helpers::get_gsm_record(state,+ router_data.connector.to_string(),+ consts::PAYMENT_FLOW_STR,+ &sub_flow,Some(err.code.clone()),Some(err.message.clone()),- connector_name,- consts::PAYMENT_FLOW_STR,- sub_flow.as_str(),+ err.network_decline_code.clone(),+ card_network.clone(),).await;let gsm_unified_code =option_gsm.as_ref().and_then(|gsm| gsm.unified_code.clone());- let gsm_unified_message =- option_gsm.clone().and_then(|gsm| gsm.unified_message);+ let gsm_unified_message = option_gsm+ .as_ref()+ .and_then(|gsm| gsm.unified_message.clone());+ let gsm_standardised_code =+ option_gsm.as_ref().and_then(|gsm| gsm.standardised_code);+ let gsm_description =+ option_gsm.as_ref().and_then(|gsm| gsm.description.clone());+ let gsm_user_guidance_message = option_gsm+ .as_ref()+ .and_then(|gsm| gsm.user_guidance_message.clone());++ // For MIT transactions, lookup recommended action from merchant_advice_codes config+ let recommended_action =+ payments_helpers::get_merchant_advice_code_recommended_action(+ &state.conf.merchant_advice_codes,+ payment_data.payment_intent.off_session,+ card_network.as_ref(),+ err.network_advice_code.as_deref(),+ );let (unified_code, unified_message) = if let Some((code, message)) =gsm_unified_code.as_ref().zip(gsm_unified_message.as_ref())@@ -1635,16 +1657,22 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(updated_by: processor.get_account().storage_scheme.to_string(),unified_code: Some(Some(unified_code)),unified_message: Some(unified_translated_message),+ standardised_code: Some(gsm_standardised_code),+ description: Some(gsm_description),+ user_guidance_message: Some(gsm_user_guidance_message),connector_transaction_id: err.connector_transaction_id.clone(),payment_method_data: additional_payment_method_data,encrypted_payment_method_data,authentication_type: auth_update,- issuer_error_code: err.network_decline_code.clone(),- issuer_error_message: err.network_error_message.clone(),- network_details: Some(ForeignFrom::foreign_from(&err)),+ issuer_error_code: Some(err.network_decline_code.clone()),+ issuer_error_message: Some(err.network_error_message.clone()),+ network_details: Some(Some(ForeignFrom::foreign_from(&err))),+ network_error_message: Some(err.network_error_message.clone()),connector_response_reference_id: err.connector_response_reference_id.clone(),+ recommended_action: Some(recommended_action),+ card_network: payment_data.payment_attempt.extract_card_network(),}),option_gsm.and_then(|option_gsm| option_gsm.error_category),)@@ -1680,6 +1708,9 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(updated_by: processor.get_account().storage_scheme.to_string(),unified_code: None,unified_message: None,+ standardised_code: None,+ description: None,+ user_guidance_message: None,connector_transaction_id,payment_method_data: None,encrypted_payment_method_data: None,@@ -1687,7 +1718,10 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(issuer_error_code: None,issuer_error_message: None,network_details: None,+ network_error_message: None,connector_response_reference_id: None,+ recommended_action: None,+ card_network: payment_data.payment_attempt.extract_card_network(),}),None,)@@ -1993,7 +2027,10 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(error_message: error_status.clone(),error_reason: error_status.clone(),unified_code: error_status.clone(),- unified_message: error_status,+ unified_message: error_status.clone(),+ standardised_code: error_status.clone().map(|_| None),+ description: error_status.clone(),+ user_guidance_message: error_status.clone(),connector_response_reference_id,updated_by: processor.get_account()@@ -2006,10 +2043,12 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(capture_before,extended_authorization_applied,extended_authorization_last_applied_at,- connector_mandate_detail: payment_data- .payment_attempt- .connector_mandate_detail- .clone(),+ connector_mandate_detail: Box::new(+ payment_data+ .payment_attempt+ .connector_mandate_detail+ .clone(),+ ),charges,setup_future_usage_applied: payment_data.payment_attempt@@ -2022,6 +2061,14 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(.payment_attempt.clone().get_tokenization_strategy(),+ issuer_error_code: error_status.clone(),+ issuer_error_message: error_status.clone(),+ network_details: error_status.clone().map(|_| None),+ network_error_message: error_status.clone(),+ recommended_action: error_status.map(|_| None),+ card_network: payment_data+ .payment_attempt+ .extract_card_network(),}),),};diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rsindex 5024412cbe..1d4a0c4bde 100644--- a/crates/router/src/core/payments/retry.rs+++ b/crates/router/src/core/payments/retry.rs@@ -16,7 +16,7 @@ use crate::{payments::{self, complete_connector_service,flows::{ConstructFlowSpecificData, Feature},- operations,+ helpers as payments_helpers, operations,},routing::helpers as routing_helpers,},@@ -65,7 +65,9 @@ wheremetrics::AUTO_RETRY_ELIGIBLE_REQUEST_COUNT.add(1, &[]);- let mut initial_gsm = get_gsm(state, &router_data).await?;+ let card_network = payment_data.get_payment_attempt().extract_card_network();++ let mut initial_gsm = get_gsm(state, &router_data, card_network.clone()).await?;let step_up_possible = initial_gsm.as_ref()@@ -113,6 +115,7 @@ wherebusiness_profile,false, //should_retry_with_pan is not applicable for step-upNone,+ initial_gsm.clone(),).await?;}@@ -122,10 +125,10 @@ where// Use initial_gsm for first time alonelet gsm = match initial_gsm.as_ref() {Some(gsm) => Some(gsm.clone()),- None => get_gsm(state, &router_data).await?,+ None => get_gsm(state, &router_data, card_network.clone()).await?,};- match get_gsm_decision(gsm) {+ match get_gsm_decision(gsm.clone()) {storage_enums::GsmDecision::Retry => {retries = get_retries(state,@@ -218,6 +221,7 @@ wherebusiness_profile,should_retry_with_pan,routing_decision,+ gsm.clone(),).await?;@@ -299,19 +303,24 @@ pub async fn get_retries(pub async fn get_gsm<F, FData>(state: &app::SessionState,router_data: &types::RouterData<F, FData, types::PaymentsResponseData>,+ card_network: Option<common_enums::CardNetwork>,) -> RouterResult<Option<hyperswitch_domain_models::gsm::GatewayStatusMap>> {let error_response = router_data.response.as_ref().err();- let error_code = error_response.map(|err| err.code.to_owned());- let error_message = error_response.map(|err| err.message.to_owned());- let connector_name = router_data.connector.to_string();let subflow = get_flow_name::<F>()?;+ let error_code = error_response.map(|err| err.code.to_owned());+ let err_message = error_response.map(|err| err.message.to_owned());+ let issuer_error_code = error_response.and_then(|err| err.network_decline_code.clone());+ let connector_str = router_data.connector.to_string();+Ok(payments::helpers::get_gsm_record(state,- error_code,- error_message,- connector_name,+ connector_str,consts::PAYMENT_FLOW_STR,- subflow.as_str(),+ &subflow,+ error_code,+ err_message,+ issuer_error_code,+ card_network,).await)}@@ -360,6 +369,7 @@ pub async fn do_retry<'a, F, ApiRequest, FData, D>(business_profile: &domain::Profile,should_retry_with_pan: bool,routing_decision: Option<routing_helpers::RoutingDecisionData>,+ initial_gsm: Option<hyperswitch_domain_models::gsm::GatewayStatusMap>,) -> RouterResult<types::RouterData<F, FData, types::PaymentsResponseData>>whereF: Clone + Send + Sync + std::fmt::Debug + 'static,@@ -384,6 +394,7 @@ whereplatform.get_processor().get_account().storage_scheme,router_data,is_step_up,+ initial_gsm,).await?;@@ -454,6 +465,7 @@ where}#[cfg(feature = "v2")]+#[allow(clippy::too_many_arguments)]#[instrument(skip_all)]pub async fn modify_trackers<F, FData, D>(state: &routes::SessionState,@@ -463,6 +475,7 @@ pub async fn modify_trackers<F, FData, D>(storage_scheme: storage_enums::MerchantStorageScheme,router_data: types::RouterData<F, FData, types::PaymentsResponseData>,is_step_up: bool,+ initial_gsm: Option<hyperswitch_domain_models::gsm::GatewayStatusMap>,) -> RouterResult<()>whereF: Clone + Send,@@ -473,6 +486,7 @@ where}#[cfg(feature = "v1")]+#[allow(clippy::too_many_arguments)]#[instrument(skip_all)]pub async fn modify_trackers<F, FData, D>(state: &routes::SessionState,@@ -482,6 +496,7 @@ pub async fn modify_trackers<F, FData, D>(storage_scheme: storage_enums::MerchantStorageScheme,router_data: types::RouterData<F, FData, types::PaymentsResponseData>,is_step_up: bool,+ initial_gsm: Option<hyperswitch_domain_models::gsm::GatewayStatusMap>,) -> RouterResult<()>whereF: Clone + Send,@@ -577,12 +592,15 @@ whereencoded_data,unified_code: None,unified_message: None,+ standardised_code: None,+ description: None,+ user_guidance_message: None,capture_before: None,extended_authorization_applied: None,extended_authorization_last_applied_at: None,payment_method_data: additional_payment_method_data,encrypted_payment_method_data,- connector_mandate_detail: None,+ connector_mandate_detail: Box::new(None),charges,setup_future_usage_applied: None,debit_routing_savings,@@ -593,6 +611,12 @@ whereis_overcapture_enabled: None,authorized_amount: router_data.authorized_amount,tokenization: None,+ issuer_error_code: None,+ issuer_error_message: None,+ network_details: None,+ network_error_message: None,+ recommended_action: None,+ card_network: payment_data.get_payment_attempt().extract_card_network(),};#[cfg(feature = "v1")]@@ -621,7 +645,7 @@ wherereturn Ok(());}Err(ref error_response) => {- let option_gsm = get_gsm(state, &router_data).await?;+ let card_network = payment_data.get_payment_attempt().extract_card_network();let auth_update = if Some(router_data.auth_type)!= payment_data.get_payment_attempt().authentication_type{@@ -630,6 +654,14 @@ whereNone};+ // For MIT transactions, lookup recommended action from merchant_advice_codes config+ let recommended_action = payments_helpers::get_merchant_advice_code_recommended_action(+ &state.conf.merchant_advice_codes,+ payment_data.get_payment_intent().off_session,+ card_network.as_ref(),+ error_response.network_advice_code.as_deref(),+ );+let payment_attempt_update = storage::PaymentAttemptUpdate::ErrorUpdate {connector: None,error_code: Some(Some(error_response.code.clone())),@@ -638,8 +670,11 @@ whereerror_reason: Some(error_response.reason.clone()),amount_capturable: Some(MinorUnit::new(0)),updated_by: storage_scheme.to_string(),- unified_code: option_gsm.clone().map(|gsm| gsm.unified_code),- unified_message: option_gsm.map(|gsm| gsm.unified_message),+ unified_code: initial_gsm.clone().map(|gsm| gsm.unified_code),+ unified_message: initial_gsm.clone().map(|gsm| gsm.unified_message),+ standardised_code: Some(initial_gsm.as_ref().and_then(|gsm| gsm.standardised_code)),+ description: initial_gsm.clone().map(|gsm| gsm.description),+ user_guidance_message: initial_gsm.clone().map(|gsm| gsm.user_guidance_message),connector_transaction_id: error_response.connector_transaction_id.clone(),connector_response_reference_id: error_response.connector_response_reference_id@@ -647,9 +682,12 @@ wherepayment_method_data: additional_payment_method_data,encrypted_payment_method_data,authentication_type: auth_update,- issuer_error_code: error_response.network_decline_code.clone(),- issuer_error_message: error_response.network_error_message.clone(),- network_details: Some(ForeignFrom::foreign_from(error_response)),+ issuer_error_code: Some(error_response.network_decline_code.clone()),+ issuer_error_message: Some(error_response.network_error_message.clone()),+ network_details: Some(Some(ForeignFrom::foreign_from(error_response))),+ network_error_message: Some(error_response.network_error_message.clone()),+ recommended_action: Some(recommended_action),+ card_network: payment_data.get_payment_attempt().extract_card_network(),};#[cfg(feature = "v1")]diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rsindex 1c402e3806..9150263d43 100644--- a/crates/router/src/core/refunds.rs+++ b/crates/router/src/core/refunds.rs@@ -314,24 +314,29 @@ pub async fn trigger_refund_to_gateway(Err(err) => {let option_gsm = helpers::get_gsm_record(state,- Some(err.code.clone()),- Some(err.message.clone()),connector.connector_name.to_string(),consts::REFUND_FLOW_STR,consts::DEFAULT_SUBFLOW_STR,+ Some(err.code.clone()),+ Some(err.message.clone()),+ err.network_decline_code.clone(),+ None, // card_network not available in refund context).await;+// Note: Some connectors do not have a separate list of refund errors// In such cases, the error codes and messages are stored under "Authorize" flow in GSM table// So we will have to fetch the GSM using Authorize flow in case GSM is not found using "refund_flow"let option_gsm = if option_gsm.is_none() {helpers::get_gsm_record(state,- Some(err.code.clone()),- Some(err.message.clone()),connector.connector_name.to_string(),consts::PAYMENT_FLOW_STR,consts::AUTHORIZE_FLOW_STR,+ Some(err.code.clone()),+ Some(err.message.clone()),+ err.network_decline_code.clone(),+ None, // card_network).await} else {diff --git a/crates/router/src/core/refunds_v2.rs b/crates/router/src/core/refunds_v2.rsindex 1302eb1fe3..b506d20d85 100644--- a/crates/router/src/core/refunds_v2.rs+++ b/crates/router/src/core/refunds_v2.rs@@ -454,24 +454,29 @@ async fn get_unified_error_and_message() -> (String, String) {let option_gsm = helpers::get_gsm_record(state,- Some(err.code.clone()),- Some(err.message.clone()),connector.connector_name.to_string(),consts::REFUND_FLOW_STR,consts::DEFAULT_SUBFLOW_STR,+ Some(err.code.clone()),+ Some(err.message.clone()),+ err.network_decline_code.clone(),+ None, // card_network not available in refund context).await;+// Note: Some connectors do not have a separate list of refund errors// In such cases, the error codes and messages are stored under "Authorize" flow in GSM table// So we will have to fetch the GSM using Authorize flow in case GSM is not found using "refund_flow"let option_gsm = if option_gsm.is_none() {helpers::get_gsm_record(state,- Some(err.code.clone()),- Some(err.message.clone()),connector.connector_name.to_string(),consts::PAYMENT_FLOW_STR,consts::AUTHORIZE_FLOW_STR,+ Some(err.code.clone()),+ Some(err.message.clone()),+ err.network_decline_code.clone(),+ None, // card_network not available in refund context).await} else {diff --git a/crates/router/src/core/revenue_recovery/types.rs b/crates/router/src/core/revenue_recovery/types.rsindex 3ad0a938ff..0036565b84 100644--- a/crates/router/src/core/revenue_recovery/types.rs+++ b/crates/router/src/core/revenue_recovery/types.rs@@ -1221,11 +1221,13 @@ impl Action {.attach_printable("unable to derive payment connector from payment attempt")?;let gsm_record = helpers::get_gsm_record(state,- error_code,- error_message,connector_name,REVENUE_RECOVERY,consts::DEFAULT_SUBFLOW_STR,+ error_code,+ error_message,+ None, // issuer_error_code not available in recovery context+ None, // card_network).await;let is_hard_decline = gsm_recorddiff --git a/crates/router/src/core/webhooks/recovery_incoming.rs b/crates/router/src/core/webhooks/recovery_incoming.rsindex 024348ab46..6f26018dfa 100644--- a/crates/router/src/core/webhooks/recovery_incoming.rs+++ b/crates/router/src/core/webhooks/recovery_incoming.rs@@ -918,11 +918,13 @@ impl RevenueRecoveryAttempt {let gsm_record = helpers::get_gsm_record(state,- error_code.clone(),- error_message,connector_name,REVENUE_RECOVERY,consts::DEFAULT_SUBFLOW_STR,+ error_code.clone(),+ error_message,+ None, // issuer_error_code+ None, // card_network).await;diff --git a/crates/router/src/routes/metrics.rs b/crates/router/src/routes/metrics.rsindex 7eb8116b47..904b2cb10c 100644--- a/crates/router/src/routes/metrics.rs+++ b/crates/router/src/routes/metrics.rs@@ -146,3 +146,6 @@ counter_metric!(PAYMENT_METHOD_TYPES_MISCONFIGURATION_METRIC, GLOBAL_METER);// AI chat metric to track number of chat requestcounter_metric!(CHAT_REQUEST_COUNT, GLOBAL_METER);++// Merchant advice code config lookup metrics+counter_metric!(MERCHANT_ADVICE_CODE_CONFIG_MISS, GLOBAL_METER);diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rsindex d964d04abf..a83e08aede 100644--- a/crates/router/src/types/transformers.rs+++ b/crates/router/src/types/transformers.rs@@ -803,10 +803,12 @@ impl ForeignFrom<diesel_models::cards_info::CardInfo> for api_models::cards_info}#[cfg(feature = "v1")]-impl ForeignFrom<diesel_models::payment_attempt::UnifiedErrorDetails>+impl ForeignFrom<hyperswitch_domain_models::payments::payment_attempt::UnifiedErrorDetails>for payments::ApiUnifiedErrorDetails{- fn foreign_from(unified: diesel_models::payment_attempt::UnifiedErrorDetails) -> Self {+ fn foreign_from(+ unified: hyperswitch_domain_models::payments::payment_attempt::UnifiedErrorDetails,+ ) -> Self {Self {category: unified.category,message: unified.message,@@ -819,10 +821,12 @@ impl ForeignFrom<diesel_models::payment_attempt::UnifiedErrorDetails>}#[cfg(feature = "v1")]-impl ForeignFrom<diesel_models::payment_attempt::NetworkErrorDetails>+impl ForeignFrom<hyperswitch_domain_models::payments::payment_attempt::NetworkErrorDetails>for payments::ApiNetworkErrorDetails{- fn foreign_from(network: diesel_models::payment_attempt::NetworkErrorDetails) -> Self {+ fn foreign_from(+ network: hyperswitch_domain_models::payments::payment_attempt::NetworkErrorDetails,+ ) -> Self {Self {name: network.name,advice_code: network.advice_code,@@ -832,10 +836,12 @@ impl ForeignFrom<diesel_models::payment_attempt::NetworkErrorDetails>}#[cfg(feature = "v1")]-impl ForeignFrom<diesel_models::payment_attempt::IssuerErrorDetails>+impl ForeignFrom<hyperswitch_domain_models::payments::payment_attempt::IssuerErrorDetails>for payments::ApiIssuerErrorDetails{- fn foreign_from(issuer: diesel_models::payment_attempt::IssuerErrorDetails) -> Self {+ fn foreign_from(+ issuer: hyperswitch_domain_models::payments::payment_attempt::IssuerErrorDetails,+ ) -> Self {Self {code: issuer.code,message: issuer.message,@@ -847,10 +853,12 @@ impl ForeignFrom<diesel_models::payment_attempt::IssuerErrorDetails>}#[cfg(feature = "v1")]-impl ForeignFrom<diesel_models::payment_attempt::ConnectorErrorDetails>+impl ForeignFrom<hyperswitch_domain_models::payments::payment_attempt::ConnectorErrorDetails>for payments::ApiConnectorErrorDetails{- fn foreign_from(connector: diesel_models::payment_attempt::ConnectorErrorDetails) -> Self {+ fn foreign_from(+ connector: hyperswitch_domain_models::payments::payment_attempt::ConnectorErrorDetails,+ ) -> Self {Self {code: connector.code,message: connector.message,@@ -860,8 +868,12 @@ impl ForeignFrom<diesel_models::payment_attempt::ConnectorErrorDetails>}#[cfg(feature = "v1")]-impl ForeignFrom<diesel_models::payment_attempt::ErrorDetails> for payments::PaymentErrorDetails {- fn foreign_from(details: diesel_models::payment_attempt::ErrorDetails) -> Self {+impl ForeignFrom<hyperswitch_domain_models::payments::payment_attempt::PaymentAttemptErrorDetails>+ for payments::PaymentErrorDetails+{+ fn foreign_from(+ details: hyperswitch_domain_models::payments::payment_attempt::PaymentAttemptErrorDetails,+ ) -> Self {Self {unified_details: details.unified_details@@ -1253,6 +1265,9 @@ impl ForeignFrom<storage::PaymentAttempt> for payments::PaymentAttemptResponse {unified_message: payment_attempt.unified_message,client_source: payment_attempt.client_source,client_version: payment_attempt.client_version,+ error_details: payment_attempt+ .error_details+ .map(payments::PaymentErrorDetails::foreign_from),}}}diff --git a/crates/router/src/workflows/payment_sync.rs b/crates/router/src/workflows/payment_sync.rsindex cbf59d3903..084f596740 100644--- a/crates/router/src/workflows/payment_sync.rs+++ b/crates/router/src/workflows/payment_sync.rs@@ -158,14 +158,20 @@ impl ProcessTrackerWorkflow<SessionState> for PaymentsSyncWorkflow {updated_by: merchant_account.storage_scheme.to_string(),unified_code: None,unified_message: None,+ standardised_code: None,+ description: None,+ user_guidance_message: None,connector_transaction_id: None,connector_response_reference_id: None,payment_method_data: None,authentication_type: None,issuer_error_code: None,issuer_error_message: None,- network_details:None,+ network_details: None,+ network_error_message: None,encrypted_payment_method_data: None,+ recommended_action: None,+ card_network: payment_data.payment_attempt.extract_card_network(),};payment_data.payment_attempt = dbdiff --git a/crates/router/src/workflows/revenue_recovery.rs b/crates/router/src/workflows/revenue_recovery.rsindex cc03c63d06..8fa837e8be 100644--- a/crates/router/src/workflows/revenue_recovery.rs+++ b/crates/router/src/workflows/revenue_recovery.rs@@ -1155,11 +1155,13 @@ pub async fn check_hard_decline(let gsm_record = payments::helpers::get_gsm_record(state,- error_code,- error_message,connector_name,REVENUE_RECOVERY,consts::DEFAULT_SUBFLOW_STR,+ error_code,+ error_message,+ None, // issuer_error_code not available in recovery context+ None, // card_network).await;