Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

feat(payments): change lookup for find gsm code and message (#10585)

Ayush Anand1c016657e514
diff --git a/crates/router/src/consts.rs b/crates/router/src/consts.rs
index 22d35c4947..1b6c2323e4 100644
--- a/crates/router/src/consts.rs
+++ b/crates/router/src/consts.rs
@@ -227,6 +227,12 @@ pub const CLICK_TO_PAY: &str = "click_to_pay";
pub const AUTHENTICATION_SERVICE_ELIGIBLE_CONFIG: &str =
"merchants_eligible_for_authentication_service";
+/// Payment flow identifier used for performing GSM operations
+pub const PAYMENT_FLOW_STR: &str = "Payment";
+
+/// Default subflow identifier used for performing GSM operations
+pub const DEFAULT_SUBFLOW_STR: &str = "sub_flow";
+
/// Refund flow identifier used for performing GSM operations
pub const REFUND_FLOW_STR: &str = "refund_flow";
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 18a47505e9..bb3ebbba58 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -11194,7 +11194,8 @@ pub async fn payments_manual_update(
Some(message.to_string()),
connector_name.to_string(),
// We need to get the unified_code and unified_message of the Authorize flow
- "Authorize".to_string(),
+ consts::PAYMENT_FLOW_STR,
+ consts::AUTHORIZE_FLOW_STR,
)
.await
} else {
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index 1461a1f156..4f1d6966cb 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -6814,13 +6814,14 @@ pub async fn get_gsm_record(
error_code: Option<String>,
error_message: Option<String>,
connector_name: String,
- flow: String,
+ flow: &str,
+ sub_flow: &str,
) -> Option<hyperswitch_domain_models::gsm::GatewayStatusMap> {
let get_gsm = || async {
state.store.find_gsm_rule(
connector_name.clone(),
- flow.clone(),
- "sub_flow".to_string(),
+ flow.to_string(),
+ sub_flow.to_string(),
error_code.clone().unwrap_or_default(), // TODO: make changes in connector to get a mandatory code in case of success or error response
error_message.clone().unwrap_or_default(),
)
@@ -6828,9 +6829,10 @@ pub async fn get_gsm_record(
.map_err(|err| {
if err.current_context().is_db_not_found() {
logger::warn!(
- "GSM miss for connector - {}, flow - {}, error_code - {:?}, error_message - {:?}",
+ "GSM miss for connector - {}, flow - {}, sub_flow - {}, error_code - {:?}, error_message - {:?}",
connector_name,
flow,
+ sub_flow,
error_code,
error_message
);
diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs
index 38524ad26d..7081946e07 100644
--- a/crates/router/src/core/payments/operations/payment_response.rs
+++ b/crates/router/src/core/payments/operations/payment_response.rs
@@ -1553,13 +1553,14 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
}
None => {
let connector_name = router_data.connector.to_string();
- let flow_name = core_utils::get_flow_name::<F>()?;
+ let sub_flow = core_utils::get_flow_name::<F>()?;
let option_gsm = payments_helpers::get_gsm_record(
state,
Some(err.code.clone()),
Some(err.message.clone()),
connector_name,
- flow_name.clone(),
+ consts::PAYMENT_FLOW_STR,
+ sub_flow.as_str(),
)
.await;
@@ -1598,13 +1599,13 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
None =>
// mark previous attempt status for technical failures in PSync and ExtendAuthorization flow
{
- if flow_name == "PSync" || flow_name == "ExtendAuthorization" {
+ if sub_flow == "PSync" || sub_flow == "ExtendAuthorization" {
match err.status_code {
// marking failure for 2xx because this is genuine payment failure
200..=299 => enums::AttemptStatus::Failure,
_ => router_data.status,
}
- } else if flow_name == "Capture" {
+ } else if sub_flow == "Capture" {
match err.status_code {
500..=511 => enums::AttemptStatus::Pending,
// don't update the status for 429 error status
diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs
index 6f1802c932..22bf4dcca2 100644
--- a/crates/router/src/core/payments/retry.rs
+++ b/crates/router/src/core/payments/retry.rs
@@ -10,6 +10,7 @@ use router_env::{
};
use crate::{
+ consts,
core::{
errors::{self, RouterResult, StorageErrorExt},
payments::{
@@ -303,11 +304,16 @@ pub async fn get_gsm<F, FData>(
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 flow = get_flow_name::<F>()?;
- Ok(
- payments::helpers::get_gsm_record(state, error_code, error_message, connector_name, flow)
- .await,
+ let subflow = get_flow_name::<F>()?;
+ Ok(payments::helpers::get_gsm_record(
+ state,
+ error_code,
+ error_message,
+ connector_name,
+ consts::PAYMENT_FLOW_STR,
+ subflow.as_str(),
)
+ .await)
}
#[instrument(skip_all)]
diff --git a/crates/router/src/core/payouts.rs b/crates/router/src/core/payouts.rs
index 2f2bacf9e3..0a905d4794 100644
--- a/crates/router/src/core/payouts.rs
+++ b/crates/router/src/core/payouts.rs
@@ -1390,6 +1390,7 @@ pub async fn create_recipient(
error_message.clone(),
payout_data.payout_attempt.connector.clone(),
consts::PAYOUT_FLOW_STR,
+ crate::consts::DEFAULT_SUBFLOW_STR,
)
.await
.map_or(
@@ -1576,6 +1577,7 @@ pub async fn check_payout_eligibility(
error_message.clone(),
payout_data.payout_attempt.connector.clone(),
consts::PAYOUT_FLOW_STR,
+ crate::consts::DEFAULT_SUBFLOW_STR,
)
.await
.map_or(
@@ -1799,6 +1801,7 @@ pub async fn create_payout(
error_message.clone(),
payout_data.payout_attempt.connector.clone(),
consts::PAYOUT_FLOW_STR,
+ crate::consts::DEFAULT_SUBFLOW_STR,
)
.await
.map_or(
@@ -2006,6 +2009,7 @@ pub async fn update_retrieve_payout_tracker<F, T>(
error_message.clone(),
payout_data.payout_attempt.connector.clone(),
consts::PAYOUT_FLOW_STR,
+ crate::consts::DEFAULT_SUBFLOW_STR,
)
.await
.map_or(
@@ -2260,6 +2264,7 @@ pub async fn create_recipient_disburse_account(
error_message.clone(),
payout_data.payout_attempt.connector.clone(),
consts::PAYOUT_FLOW_STR,
+ crate::consts::DEFAULT_SUBFLOW_STR,
)
.await
.map_or(
@@ -2385,6 +2390,7 @@ pub async fn cancel_payout(
error_message.clone(),
payout_data.payout_attempt.connector.clone(),
consts::PAYOUT_FLOW_STR,
+ crate::consts::DEFAULT_SUBFLOW_STR,
)
.await
.map_or(
@@ -2561,6 +2567,7 @@ pub async fn fulfill_payout(
error_message.clone(),
payout_data.payout_attempt.connector.clone(),
consts::PAYOUT_FLOW_STR,
+ crate::consts::DEFAULT_SUBFLOW_STR,
)
.await
.map_or(
diff --git a/crates/router/src/core/payouts/helpers.rs b/crates/router/src/core/payouts/helpers.rs
index 86a3dca794..3f3177b83a 100644
--- a/crates/router/src/core/payouts/helpers.rs
+++ b/crates/router/src/core/payouts/helpers.rs
@@ -1108,13 +1108,14 @@ pub async fn get_gsm_record(
error_message: Option<String>,
connector_name: Option<String>,
flow: &str,
+ sub_flow: &str,
) -> Option<hyperswitch_domain_models::gsm::GatewayStatusMap> {
let connector_name = connector_name.unwrap_or_default();
let get_gsm = || async {
state.store.find_gsm_rule(
connector_name.clone(),
flow.to_string(),
- "sub_flow".to_string(),
+ sub_flow.to_string(),
error_code.clone().unwrap_or_default(), // TODO: make changes in connector to get a mandatory code in case of success or error response
error_message.clone().unwrap_or_default(),
)
@@ -1122,9 +1123,10 @@ pub async fn get_gsm_record(
.map_err(|err| {
if err.current_context().is_db_not_found() {
logger::warn!(
- "GSM miss for connector - {}, flow - {}, error_code - {:?}, error_message - {:?}",
+ "GSM miss for connector - {}, flow - {}, sub_flow - {}, error_code - {:?}, error_message - {:?}",
connector_name,
flow,
+ sub_flow,
error_code,
error_message
);
diff --git a/crates/router/src/core/payouts/retry.rs b/crates/router/src/core/payouts/retry.rs
index 0cbee078e6..3e39283ce0 100644
--- a/crates/router/src/core/payouts/retry.rs
+++ b/crates/router/src/core/payouts/retry.rs
@@ -9,6 +9,7 @@ use router_env::{
use super::{call_connector_payout, PayoutData};
use crate::{
+ consts,
core::{
errors::{self, RouterResult, StorageErrorExt},
payouts,
@@ -179,6 +180,7 @@ pub async fn get_gsm(
error_message,
connector_name,
common_utils::consts::PAYOUT_FLOW_STR,
+ consts::DEFAULT_SUBFLOW_STR,
)
.await)
}
diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs
index 83cd220fb9..9895121351 100644
--- a/crates/router/src/core/refunds.rs
+++ b/crates/router/src/core/refunds.rs
@@ -312,7 +312,8 @@ pub async fn trigger_refund_to_gateway(
Some(err.code.clone()),
Some(err.message.clone()),
connector.connector_name.to_string(),
- consts::REFUND_FLOW_STR.to_string(),
+ consts::REFUND_FLOW_STR,
+ consts::DEFAULT_SUBFLOW_STR,
)
.await;
// Note: Some connectors do not have a separate list of refund errors
@@ -324,7 +325,8 @@ pub async fn trigger_refund_to_gateway(
Some(err.code.clone()),
Some(err.message.clone()),
connector.connector_name.to_string(),
- consts::AUTHORIZE_FLOW_STR.to_string(),
+ consts::PAYMENT_FLOW_STR,
+ consts::AUTHORIZE_FLOW_STR,
)
.await
} else {
diff --git a/crates/router/src/core/refunds_v2.rs b/crates/router/src/core/refunds_v2.rs
index 1759f80649..c4b9369c60 100644
--- a/crates/router/src/core/refunds_v2.rs
+++ b/crates/router/src/core/refunds_v2.rs
@@ -457,7 +457,8 @@ async fn get_unified_error_and_message(
Some(err.code.clone()),
Some(err.message.clone()),
connector.connector_name.to_string(),
- consts::REFUND_FLOW_STR.to_string(),
+ consts::REFUND_FLOW_STR,
+ consts::DEFAULT_SUBFLOW_STR,
)
.await;
// Note: Some connectors do not have a separate list of refund errors
@@ -469,7 +470,8 @@ async fn get_unified_error_and_message(
Some(err.code.clone()),
Some(err.message.clone()),
connector.connector_name.to_string(),
- consts::AUTHORIZE_FLOW_STR.to_string(),
+ consts::PAYMENT_FLOW_STR,
+ consts::AUTHORIZE_FLOW_STR,
)
.await
} else {
diff --git a/crates/router/src/core/revenue_recovery/types.rs b/crates/router/src/core/revenue_recovery/types.rs
index 28272e79d4..3ad0a938ff 100644
--- a/crates/router/src/core/revenue_recovery/types.rs
+++ b/crates/router/src/core/revenue_recovery/types.rs
@@ -34,6 +34,7 @@ use time::PrimitiveDateTime;
use super::errors::StorageErrorExt;
use crate::{
+ consts,
core::{
errors::{self, RouterResult},
payments::{self, helpers, operations::Operation, transformers::GenerateResponse},
@@ -1223,7 +1224,8 @@ impl Action {
error_code,
error_message,
connector_name,
- REVENUE_RECOVERY.to_string(),
+ REVENUE_RECOVERY,
+ consts::DEFAULT_SUBFLOW_STR,
)
.await;
let is_hard_decline = gsm_record
diff --git a/crates/router/src/core/webhooks/recovery_incoming.rs b/crates/router/src/core/webhooks/recovery_incoming.rs
index 1956c9774d..024348ab46 100644
--- a/crates/router/src/core/webhooks/recovery_incoming.rs
+++ b/crates/router/src/core/webhooks/recovery_incoming.rs
@@ -24,6 +24,7 @@ use services::kafka;
use storage::business_status;
use crate::{
+ consts,
core::{
self, admin,
errors::{self, CustomResult},
@@ -920,7 +921,8 @@ impl RevenueRecoveryAttempt {
error_code.clone(),
error_message,
connector_name,
- REVENUE_RECOVERY.to_string(),
+ REVENUE_RECOVERY,
+ consts::DEFAULT_SUBFLOW_STR,
)
.await;
diff --git a/crates/router/src/workflows/revenue_recovery.rs b/crates/router/src/workflows/revenue_recovery.rs
index eb8402ead6..56f63dcb26 100644
--- a/crates/router/src/workflows/revenue_recovery.rs
+++ b/crates/router/src/workflows/revenue_recovery.rs
@@ -65,6 +65,7 @@ use crate::types::storage::{
use crate::workflows::revenue_recovery::pcr::api;
#[cfg(feature = "v2")]
use crate::{
+ consts,
core::{
payments,
revenue_recovery::{self as pcr},
@@ -1156,7 +1157,8 @@ pub async fn check_hard_decline(
error_code,
error_message,
connector_name,
- REVENUE_RECOVERY.to_string(),
+ REVENUE_RECOVERY,
+ consts::DEFAULT_SUBFLOW_STR,
)
.await;