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(revenue-recovery): stream A/B algorithm type and standardised error code in v2 analytics events (#14594)

Rohan Malic2e2ec032f3d
diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs
index 6a9d27aa22..70e7942214 100644
--- a/crates/diesel_models/src/payment_attempt.rs
+++ b/crates/diesel_models/src/payment_attempt.rs
@@ -1090,6 +1090,7 @@ pub struct PaymentAttemptUpdateInternal {
pub network_error_message: Option<String>,
pub connector_request_reference_id: Option<String>,
pub amount_captured: Option<MinorUnit>,
+ pub error_details: Option<ErrorDetails>,
}
#[cfg(feature = "v1")]
#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]
@@ -1286,6 +1287,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
cancellation_reason: None,
amount_captured,
payment_method_data: None,
+ error_details: None,
}
}
PaymentAttemptUpdate::ErrorUpdate {
@@ -1338,6 +1340,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
cancellation_reason: None,
amount_captured,
payment_method_data: None,
+ error_details: None,
}
}
PaymentAttemptUpdate::UnresolvedResponseUpdate {
@@ -1386,6 +1389,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
cancellation_reason: None,
amount_captured: None,
payment_method_data: None,
+ error_details: None,
}
}
PaymentAttemptUpdate::PreprocessingUpdate {
@@ -1432,6 +1436,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
cancellation_reason: None,
amount_captured: None,
payment_method_data: None,
+ error_details: None,
}
}
PaymentAttemptUpdate::ConnectorResponse {
@@ -1474,6 +1479,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
cancellation_reason: None,
amount_captured: None,
payment_method_data: None,
+ error_details: None,
}
}
PaymentAttemptUpdate::ManualUpdate {
@@ -1522,6 +1528,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
cancellation_reason: None,
amount_captured: None,
payment_method_data: None,
+ error_details: None,
}
}
}
diff --git a/crates/hyperswitch_domain_models/src/lib.rs b/crates/hyperswitch_domain_models/src/lib.rs
index d552137437..58489d691a 100644
--- a/crates/hyperswitch_domain_models/src/lib.rs
+++ b/crates/hyperswitch_domain_models/src/lib.rs
@@ -1399,6 +1399,7 @@ impl From<&api_models::payments::RecordAttemptErrorDetails>
network_advice_code: error.network_advice_code.clone(),
network_decline_code: error.network_decline_code.clone(),
network_error_message: error.network_error_message.clone(),
+ standardised_code: None,
}
}
}
diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
index ad00f24e93..668aeea72c 100644
--- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
+++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
@@ -364,6 +364,49 @@ pub struct ErrorDetails {
pub network_decline_code: Option<String>,
/// A string indicating how to proceed with an network error if payment gateway provide one. This is used to understand the network error code better.
pub network_error_message: Option<String>,
+ /// The standardised code from the global status map record for this error.
+ /// Persisted in the `error_details` column, under `unified_details`.
+ pub standardised_code: Option<common_enums::StandardisedCode>,
+}
+
+/// The `error_details` column for a v2 attempt error: connector, issuer and unified (GSM) details.
+#[cfg(feature = "v2")]
+impl From<&ErrorDetails> for diesel_models::payment_attempt::ErrorDetails {
+ fn from(error: &ErrorDetails) -> Self {
+ let unified_details = (error.unified_message.is_some()
+ || error.standardised_code.is_some())
+ .then(|| diesel_models::payment_attempt::UnifiedErrorDetails {
+ category: None,
+ message: error.unified_message.clone(),
+ standardised_code: error.standardised_code,
+ description: None,
+ user_guidance_message: None,
+ recommended_action: None,
+ });
+ let issuer_details = (error.network_decline_code.is_some()
+ || error.network_error_message.is_some()
+ || error.network_advice_code.is_some())
+ .then(|| diesel_models::payment_attempt::IssuerErrorDetails {
+ code: error.network_decline_code.clone(),
+ message: error.network_error_message.clone(),
+ network_details: error.network_advice_code.clone().map(|advice_code| {
+ diesel_models::payment_attempt::NetworkErrorDetails {
+ name: None,
+ advice_code: Some(advice_code),
+ advice_message: None,
+ }
+ }),
+ });
+ Self {
+ unified_details,
+ issuer_details,
+ connector_details: Some(diesel_models::payment_attempt::ConnectorErrorDetails {
+ code: Some(error.code.clone()),
+ message: Some(error.message.clone()),
+ reason: error.reason.clone(),
+ }),
+ }
+ }
}
#[cfg(feature = "v2")]
diff --git a/crates/hyperswitch_domain_models/src/router_data.rs b/crates/hyperswitch_domain_models/src/router_data.rs
index 9e9978cea0..9ee51c8281 100644
--- a/crates/hyperswitch_domain_models/src/router_data.rs
+++ b/crates/hyperswitch_domain_models/src/router_data.rs
@@ -1120,6 +1120,7 @@ pub trait TrackerPostUpdateObjects<Flow, FlowRequest, D> {
&self,
payment_data: &D,
storage_scheme: common_enums::MerchantStorageScheme,
+ gsm_record: Option<&crate::gsm::GatewayStatusMap>,
) -> PaymentAttemptUpdate;
/// Get the amount that can be captured for the payment
@@ -1220,6 +1221,7 @@ impl
&self,
payment_data: &payments::PaymentConfirmData<router_flow_types::Authorize>,
storage_scheme: common_enums::MerchantStorageScheme,
+ gsm_record: Option<&crate::gsm::GatewayStatusMap>,
) -> PaymentAttemptUpdate {
let amount_capturable = self.get_amount_capturable(payment_data);
let amount_captured = self.get_captured_amount(payment_data);
@@ -1332,11 +1334,12 @@ impl
code,
message,
reason,
- unified_code: None,
- unified_message: None,
+ unified_code: gsm_record.and_then(|gsm| gsm.unified_code.clone()),
+ unified_message: gsm_record.and_then(|gsm| gsm.unified_message.clone()),
network_advice_code,
network_decline_code,
network_error_message,
+ standardised_code: gsm_record.and_then(|gsm| gsm.standardised_code),
};
PaymentAttemptUpdate::ErrorUpdate {
@@ -1589,6 +1592,7 @@ impl
&self,
payment_data: &payments::PaymentCaptureData<router_flow_types::Capture>,
storage_scheme: common_enums::MerchantStorageScheme,
+ gsm_record: Option<&crate::gsm::GatewayStatusMap>,
) -> PaymentAttemptUpdate {
let amount_capturable = self.get_amount_capturable(payment_data);
@@ -1659,11 +1663,12 @@ impl
code,
message,
reason,
- unified_code: None,
- unified_message: None,
+ unified_code: gsm_record.and_then(|gsm| gsm.unified_code.clone()),
+ unified_message: gsm_record.and_then(|gsm| gsm.unified_message.clone()),
network_advice_code,
network_decline_code,
network_error_message,
+ standardised_code: gsm_record.and_then(|gsm| gsm.standardised_code),
};
PaymentAttemptUpdate::ErrorUpdate {
@@ -1908,6 +1913,7 @@ impl
&self,
payment_data: &payments::PaymentStatusData<router_flow_types::PSync>,
storage_scheme: common_enums::MerchantStorageScheme,
+ gsm_record: Option<&crate::gsm::GatewayStatusMap>,
) -> PaymentAttemptUpdate {
let amount_capturable = self.get_amount_capturable(payment_data);
let amount_captured = self.get_captured_amount(payment_data);
@@ -1996,11 +2002,12 @@ impl
code,
message,
reason,
- unified_code: None,
- unified_message: None,
+ unified_code: gsm_record.and_then(|gsm| gsm.unified_code.clone()),
+ unified_message: gsm_record.and_then(|gsm| gsm.unified_message.clone()),
network_advice_code,
network_decline_code,
network_error_message,
+ standardised_code: gsm_record.and_then(|gsm| gsm.standardised_code),
};
PaymentAttemptUpdate::ErrorUpdate {
@@ -2180,6 +2187,7 @@ impl
&self,
payment_data: &payments::PaymentConfirmData<router_flow_types::ExternalVaultProxy>,
storage_scheme: common_enums::MerchantStorageScheme,
+ gsm_record: Option<&crate::gsm::GatewayStatusMap>,
) -> PaymentAttemptUpdate {
let amount_capturable = self.get_amount_capturable(payment_data);
let amount_captured = self.get_captured_amount(payment_data);
@@ -2292,11 +2300,12 @@ impl
code,
message,
reason,
- unified_code: None,
- unified_message: None,
+ unified_code: gsm_record.and_then(|gsm| gsm.unified_code.clone()),
+ unified_message: gsm_record.and_then(|gsm| gsm.unified_message.clone()),
network_advice_code,
network_decline_code,
network_error_message,
+ standardised_code: gsm_record.and_then(|gsm| gsm.standardised_code),
};
PaymentAttemptUpdate::ErrorUpdate {
@@ -2441,6 +2450,7 @@ impl
&self,
payment_data: &payments::PaymentConfirmData<router_flow_types::SetupMandate>,
storage_scheme: common_enums::MerchantStorageScheme,
+ gsm_record: Option<&crate::gsm::GatewayStatusMap>,
) -> PaymentAttemptUpdate {
let amount_capturable = self.get_amount_capturable(payment_data);
let amount_captured = self.get_captured_amount(payment_data);
@@ -2544,11 +2554,12 @@ impl
code,
message,
reason,
- unified_code: None,
- unified_message: None,
+ unified_code: gsm_record.and_then(|gsm| gsm.unified_code.clone()),
+ unified_message: gsm_record.and_then(|gsm| gsm.unified_message.clone()),
network_advice_code,
network_decline_code,
network_error_message,
+ standardised_code: gsm_record.and_then(|gsm| gsm.standardised_code),
};
PaymentAttemptUpdate::ErrorUpdate {
@@ -2698,6 +2709,7 @@ impl
&self,
payment_data: &payments::PaymentCancelData<router_flow_types::Void>,
storage_scheme: common_enums::MerchantStorageScheme,
+ gsm_record: Option<&crate::gsm::GatewayStatusMap>,
) -> PaymentAttemptUpdate {
match &self.response {
Err(ref error_response) => {
@@ -2729,11 +2741,12 @@ impl
code,
message,
reason,
- unified_code: None,
- unified_message: None,
+ unified_code: gsm_record.and_then(|gsm| gsm.unified_code.clone()),
+ unified_message: gsm_record.and_then(|gsm| gsm.unified_message.clone()),
network_advice_code,
network_decline_code,
network_error_message,
+ standardised_code: gsm_record.and_then(|gsm| gsm.standardised_code),
};
PaymentAttemptUpdate::ErrorUpdate {
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index ada1a2877f..5858dee3fe 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -8383,6 +8383,32 @@ pub async fn get_gsm_record(
}
}
+/// Looks up the global status map rule for a connector error response, so the attempt update built
+/// from it can carry the rule's standardised and unified codes. `None` when the response is not an
+/// error or no rule matches.
+#[cfg(feature = "v2")]
+pub async fn get_gsm_record_for_error_response<F, Req, Res>(
+ state: &SessionState,
+ router_data: &RouterData<F, Req, Res>,
+ payment_attempt: &PaymentAttempt,
+) -> Option<hyperswitch_domain_models::gsm::GatewayStatusMap> {
+ let error = router_data.response.as_ref().err()?;
+ let sub_flow = crate::core::utils::get_flow_name::<F>()
+ .inspect_err(|err| logger::error!(?err, "Failed to get flow name for GSM lookup"))
+ .ok()?;
+ get_gsm_record(
+ state,
+ router_data.connector.clone(),
+ consts::PAYMENT_FLOW_STR,
+ &sub_flow,
+ Some(error.code.clone()),
+ Some(error.message.clone()),
+ error.network_decline_code.clone(),
+ payment_attempt.extract_card_network(),
+ )
+ .await
+}
+
/// Perform GSM lookup with the given error code and message.
async fn perform_gsm_lookup(
state: &SessionState,
diff --git a/crates/router/src/core/payments/operations/external_vault_proxy_payment_intent.rs b/crates/router/src/core/payments/operations/external_vault_proxy_payment_intent.rs
index 794276614e..fec740dea3 100644
--- a/crates/router/src/core/payments/operations/external_vault_proxy_payment_intent.rs
+++ b/crates/router/src/core/payments/operations/external_vault_proxy_payment_intent.rs
@@ -608,8 +608,17 @@ impl<F: Clone> PostUpdateTracker<F, PaymentConfirmData<F>, types::PaymentsAuthor
let payment_intent_update = response_router_data
.get_payment_intent_update(&payment_data, processor.get_account().storage_scheme);
- let payment_attempt_update = response_router_data
- .get_payment_attempt_update(&payment_data, processor.get_account().storage_scheme);
+ let gsm_record = payments::helpers::get_gsm_record_for_error_response(
+ state,
+ &response_router_data,
+ &payment_data.payment_attempt,
+ )
+ .await;
+ let payment_attempt_update = response_router_data.get_payment_attempt_update(
+ &payment_data,
+ processor.get_account().storage_scheme,
+ gsm_record.as_ref(),
+ );
let updated_payment_intent = db
.update_payment_intent(
diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs
index 5bd5db622a..20151e0fde 100644
--- a/crates/router/src/core/payments/operations/payment_response.rs
+++ b/crates/router/src/core/payments/operations/payment_response.rs
@@ -4303,8 +4303,17 @@ impl<F: Clone>
let payment_intent_update = response_router_data
.get_payment_intent_update(&payment_data, processor.get_account().storage_scheme);
- let payment_attempt_update = response_router_data
- .get_payment_attempt_update(&payment_data, processor.get_account().storage_scheme);
+ let gsm_record = payments_helpers::get_gsm_record_for_error_response(
+ state,
+ &response_router_data,
+ &payment_data.payment_attempt,
+ )
+ .await;
+ let payment_attempt_update = response_router_data.get_payment_attempt_update(
+ &payment_data,
+ processor.get_account().storage_scheme,
+ gsm_record.as_ref(),
+ );
let updated_payment_intent = db
.update_payment_intent(
@@ -4365,8 +4374,17 @@ impl<F: Clone> PostUpdateTracker<F, PaymentConfirmData<F>, types::PaymentsAuthor
let payment_intent_update = response_router_data
.get_payment_intent_update(&payment_data, processor.get_account().storage_scheme);
- let payment_attempt_update = response_router_data
- .get_payment_attempt_update(&payment_data, processor.get_account().storage_scheme);
+ let gsm_record = payments_helpers::get_gsm_record_for_error_response(
+ state,
+ &response_router_data,
+ &payment_data.payment_attempt,
+ )
+ .await;
+ let payment_attempt_update = response_router_data.get_payment_attempt_update(
+ &payment_data,
+ processor.get_account().storage_scheme,
+ gsm_record.as_ref(),
+ );
let updated_payment_intent = db
.update_payment_intent(
@@ -4555,8 +4573,17 @@ impl<F: Clone> PostUpdateTracker<F, PaymentStatusData<F>, types::PaymentsSyncDat
let payment_intent_update = response_router_data
.get_payment_intent_update(&payment_data, processor.get_account().storage_scheme);
- let payment_attempt_update = response_router_data
- .get_payment_attempt_update(&payment_data, processor.get_account().storage_scheme);
+ let gsm_record = payments_helpers::get_gsm_record_for_error_response(
+ state,
+ &response_router_data,
+ &payment_data.payment_attempt,
+ )
+ .await;
+ let payment_attempt_update = response_router_data.get_payment_attempt_update(
+ &payment_data,
+ processor.get_account().storage_scheme,
+ gsm_record.as_ref(),
+ );
let payment_attempt = payment_data.payment_attempt;
@@ -4822,8 +4849,17 @@ impl
let payment_intent_update = response_router_data
.get_payment_intent_update(&payment_data, processor.get_account().storage_scheme);
- let payment_attempt_update = response_router_data
- .get_payment_attempt_update(&payment_data, processor.get_account().storage_scheme);
+ let gsm_record = payments_helpers::get_gsm_record_for_error_response(
+ state,
+ &response_router_data,
+ &payment_data.payment_attempt,
+ )
+ .await;
+ let payment_attempt_update = response_router_data.get_payment_attempt_update(
+ &payment_data,
+ processor.get_account().storage_scheme,
+ gsm_record.as_ref(),
+ );
let updated_payment_intent = db
.update_payment_intent(
@@ -4886,8 +4922,17 @@ impl<F: Clone> PostUpdateTracker<F, PaymentConfirmData<F>, types::SetupMandateRe
let payment_intent_update = response_router_data
.get_payment_intent_update(&payment_data, processor.get_account().storage_scheme);
- let payment_attempt_update = response_router_data
- .get_payment_attempt_update(&payment_data, processor.get_account().storage_scheme);
+ let gsm_record = payments_helpers::get_gsm_record_for_error_response(
+ state,
+ &response_router_data,
+ &payment_data.payment_attempt,
+ )
+ .await;
+ let payment_attempt_update = response_router_data.get_payment_attempt_update(
+ &payment_data,
+ processor.get_account().storage_scheme,
+ gsm_record.as_ref(),
+ );
let updated_payment_intent = db
.update_payment_intent(
@@ -5226,8 +5271,17 @@ impl<F: Clone + Send + Sync>
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
.attach_printable("Error while updating the payment_intent")?;
- let payment_attempt_update = router_data
- .get_payment_attempt_update(&payment_data, processor.get_account().storage_scheme);
+ let gsm_record = payments_helpers::get_gsm_record_for_error_response(
+ state,
+ &router_data,
+ &payment_data.payment_attempt,
+ )
+ .await;
+ let payment_attempt_update = router_data.get_payment_attempt_update(
+ &payment_data,
+ processor.get_account().storage_scheme,
+ gsm_record.as_ref(),
+ );
let updated_payment_attempt = db
.update_payment_attempt(
diff --git a/crates/router/src/core/payments/operations/proxy_payments_intent.rs b/crates/router/src/core/payments/operations/proxy_payments_intent.rs
index 77f2aba1a3..1d82fd8332 100644
--- a/crates/router/src/core/payments/operations/proxy_payments_intent.rs
+++ b/crates/router/src/core/payments/operations/proxy_payments_intent.rs
@@ -490,8 +490,17 @@ impl<F: Clone> PostUpdateTracker<F, PaymentConfirmData<F>, types::PaymentsAuthor
let payment_intent_update = response_router_data
.get_payment_intent_update(&payment_data, processor.get_account().storage_scheme);
- let payment_attempt_update = response_router_data
- .get_payment_attempt_update(&payment_data, processor.get_account().storage_scheme);
+ let gsm_record = crate::core::payments::helpers::get_gsm_record_for_error_response(
+ state,
+ &response_router_data,
+ &payment_data.payment_attempt,
+ )
+ .await;
+ let payment_attempt_update = response_router_data.get_payment_attempt_update(
+ &payment_data,
+ processor.get_account().storage_scheme,
+ gsm_record.as_ref(),
+ );
let updated_payment_intent = db
.update_payment_intent(
diff --git a/crates/router/src/core/revenue_recovery/types.rs b/crates/router/src/core/revenue_recovery/types.rs
index 7c81aaeb4a..fb7dc0019d 100644
--- a/crates/router/src/core/revenue_recovery/types.rs
+++ b/crates/router/src/core/revenue_recovery/types.rs
@@ -354,13 +354,12 @@ impl RevenueRecoveryPaymentIntentStatus {
)
.await;
- let reopened_standardised_error_code =
- retry_stats::events::resolve_standardised_error_code_from_attempt(
- state,
- &psync_response.payment_attempt,
- revenue_recovery_metadata.get_card_network(),
- )
- .await;
+ // Written with the failed status by the payments core.
+ let reopened_standardised_error_code = psync_response
+ .payment_attempt
+ .error
+ .as_ref()
+ .and_then(|error| error.standardised_code);
Box::pin(reopen_calculate_workflow_on_payment_failure(
state,
&process_tracker,
@@ -761,14 +760,13 @@ impl Action {
)
.await;
- // Reopen calculate workflow on payment failure
- let reopened_standardised_error_code =
- retry_stats::events::resolve_standardised_error_code_from_attempt(
- state,
- &payment_data.payment_attempt,
- revenue_recovery_metadata.get_card_network(),
- )
- .await;
+ // Reopen calculate workflow on payment failure. The code was written with
+ // the failed status by the payments core.
+ let reopened_standardised_error_code = payment_data
+ .payment_attempt
+ .error
+ .as_ref()
+ .and_then(|error| error.standardised_code);
Box::pin(reopen_calculate_workflow_on_payment_failure(
state,
process,
@@ -1010,7 +1008,7 @@ impl Action {
let used_token = get_payment_processor_token_id_from_payment_attempt(&payment_attempt);
match response {
- Ok(_payment_data) => match payment_intent.status.foreign_into() {
+ Ok(payment_data) => match payment_intent.status.foreign_into() {
RevenueRecoveryPaymentIntentStatus::Succeeded => {
let connector_customer_id = payment_intent
.extract_connector_customer_id_from_payment_intent()
@@ -1087,21 +1085,13 @@ impl Action {
.await;
// Reopen calculate workflow on payment failure
- let card_network = payment_intent
- .feature_metadata
+ // The synced attempt, not the `payment_attempt` passed in: that copy predates
+ // the sync, so it lacks the code written with the sync's status update.
+ let reopened_standardised_error_code = payment_data
+ .payment_attempt
+ .error
.as_ref()
- .and_then(|feature_metadata| {
- feature_metadata.payment_revenue_recovery_metadata.clone()
- })
- .and_then(|metadata| metadata.convert_back().get_card_network());
-
- let reopened_standardised_error_code =
- retry_stats::events::resolve_standardised_error_code_from_attempt(
- state,
- &payment_attempt,
- card_network,
- )
- .await;
+ .and_then(|error| error.standardised_code);
Box::pin(reopen_calculate_workflow_on_payment_failure(
state,
process,
diff --git a/crates/router/src/services/kafka/payment_attempt.rs b/crates/router/src/services/kafka/payment_attempt.rs
index 0c8fed750c..ff549b0b4f 100644
--- a/crates/router/src/services/kafka/payment_attempt.rs
+++ b/crates/router/src/services/kafka/payment_attempt.rs
@@ -222,6 +222,9 @@ pub struct KafkaPaymentAttempt<'a> {
pub network_decline_code: Option<String>,
pub network_error_message: Option<String>,
pub connector_request_reference_id: Option<String>,
+ /// Standardised error code of a failed revenue recovery attempt, lifted out of the
+ /// attempt's error details so that analytics can store it as its own column.
+ pub standardised_code: Option<common_enums::StandardisedCode>,
}
#[cfg(feature = "v2")]
@@ -294,6 +297,10 @@ impl<'a> KafkaPaymentAttempt<'a> {
.map(|(txn_id, txn_data)| (Some(txn_id), txn_data))
.unwrap_or((None, None));
+ let standardised_code = error
+ .as_ref()
+ .and_then(|error_details| error_details.standardised_code);
+
Self {
payment_id,
merchant_id,
@@ -382,6 +389,7 @@ impl<'a> KafkaPaymentAttempt<'a> {
.as_ref()
.and_then(|details| details.network_error_message.clone()),
connector_request_reference_id: connector_request_reference_id.clone(),
+ standardised_code,
}
}
}
diff --git a/crates/router/src/services/kafka/payment_attempt_event.rs b/crates/router/src/services/kafka/payment_attempt_event.rs
index 738b7f2fa5..f0b4f49581 100644
--- a/crates/router/src/services/kafka/payment_attempt_event.rs
+++ b/crates/router/src/services/kafka/payment_attempt_event.rs
@@ -224,6 +224,9 @@ pub struct KafkaPaymentAttemptEvent<'a> {
pub network_decline_code: Option<String>,
pub network_error_message: Option<String>,
pub connector_request_reference_id: Option<String>,
+ /// Standardised error code of a failed revenue recovery attempt, lifted out of the
+ /// attempt's error details so that the sessionizer can pass it on as its own field.
+ pub standardised_code: Option<common_enums::StandardisedCode>,
}
#[cfg(feature = "v2")]
@@ -296,6 +299,10 @@ impl<'a> KafkaPaymentAttemptEvent<'a> {
.map(|(txn_id, txn_data)| (Some(txn_id), txn_data))
.unwrap_or((None, None));
+ let standardised_code = error
+ .as_ref()
+ .and_then(|error_details| error_details.standardised_code);
+
Self {
payment_id,
merchant_id,
@@ -384,6 +391,7 @@ impl<'a> KafkaPaymentAttemptEvent<'a> {
.as_ref()
.and_then(|details| details.network_error_message.clone()),
connector_request_reference_id: connector_request_reference_id.clone(),
+ standardised_code,
}
}
}
diff --git a/crates/router/src/services/kafka/payment_intent.rs b/crates/router/src/services/kafka/payment_intent.rs
index 2f3090980f..6880b4f5ec 100644
--- a/crates/router/src/services/kafka/payment_intent.rs
+++ b/crates/router/src/services/kafka/payment_intent.rs
@@ -185,6 +185,9 @@ pub struct KafkaPaymentIntent<'a> {
pub routing_algorithm_id: Option<&'a id_type::RoutingId>,
pub payment_link_config: Option<&'a PaymentLinkConfigRequestForPayments>,
pub enable_partial_authorization: Option<EnablePartialAuthorizationBool>,
+ /// Revenue recovery A/B routing algorithm assigned to this invoice, lifted out of
+ /// `feature_metadata` so that analytics can store it as its own column.
+ pub revenue_recovery_algorithm_type: Option<common_enums::RevenueRecoveryABAlgorithm>,
#[serde(flatten)]
infra_values: Option<Value>,
@@ -254,6 +257,11 @@ impl<'a> KafkaPaymentIntent<'a> {
recipient_details: _,
} = intent;
+ let revenue_recovery_algorithm_type = feature_metadata
+ .as_ref()
+ .and_then(|metadata| metadata.payment_revenue_recovery_metadata.as_ref())
+ .and_then(|recovery_metadata| recovery_metadata.revenue_recovery_ab_routing);
+
Self {
payment_id: id,
merchant_id,
@@ -329,6 +337,7 @@ impl<'a> KafkaPaymentIntent<'a> {
payment_link_config: payment_link_config.as_ref(),
infra_values,
enable_partial_authorization: Some(*enable_partial_authorization),
+ revenue_recovery_algorithm_type,
}
}
}
diff --git a/crates/router/src/services/kafka/payment_intent_event.rs b/crates/router/src/services/kafka/payment_intent_event.rs
index e8fff4653d..ff1f011729 100644
--- a/crates/router/src/services/kafka/payment_intent_event.rs
+++ b/crates/router/src/services/kafka/payment_intent_event.rs
@@ -138,6 +138,9 @@ pub struct KafkaPaymentIntentEvent<'a> {
pub routing_algorithm_id: Option<&'a id_type::RoutingId>,
pub payment_link_config: Option<&'a PaymentLinkConfigRequestForPayments>,
pub enable_partial_authorization: Option<EnablePartialAuthorizationBool>,
+ /// Revenue recovery A/B routing algorithm assigned to this invoice, lifted out of
+ /// `feature_metadata` so that the sessionizer can pass it on as its own field.
+ pub revenue_recovery_algorithm_type: Option<common_enums::RevenueRecoveryABAlgorithm>,
#[serde(flatten)]
infra_values: Option<Value>,
@@ -268,6 +271,11 @@ impl<'a> KafkaPaymentIntentEvent<'a> {
recipient_details: _,
} = intent;
+ let revenue_recovery_algorithm_type = feature_metadata
+ .as_ref()
+ .and_then(|metadata| metadata.payment_revenue_recovery_metadata.as_ref())
+ .and_then(|recovery_metadata| recovery_metadata.revenue_recovery_ab_routing);
+
Self {
payment_id: id,
merchant_id,
@@ -343,6 +351,7 @@ impl<'a> KafkaPaymentIntentEvent<'a> {
payment_link_config: payment_link_config.as_ref(),
infra_values,
enable_partial_authorization: Some(*enable_partial_authorization),
+ revenue_recovery_algorithm_type,
}
}
}
diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs
index dd391c8d7c..43c8adf337 100644
--- a/crates/storage_impl/src/payments/payment_attempt.rs
+++ b/crates/storage_impl/src/payments/payment_attempt.rs
@@ -2546,7 +2546,9 @@ impl Conversion for PaymentAttempt {
tokenization: None,
amount_captured,
encrypted_payment_method_data: None,
- error_details: None,
+ error_details: error
+ .as_ref()
+ .map(diesel_models::payment_attempt::ErrorDetails::from),
retry_type: None,
installment_data: None,
external_surcharge_details: None,
@@ -2612,6 +2614,12 @@ impl Conversion for PaymentAttempt {
amount_captured: storage_model.amount_captured,
};
+ let standardised_code = storage_model
+ .error_details
+ .as_ref()
+ .and_then(|error_details| error_details.unified_details.as_ref())
+ .and_then(|unified_details| unified_details.standardised_code);
+
let error = storage_model
.error_code
.zip(storage_model.error_message)
@@ -2624,6 +2632,7 @@ impl Conversion for PaymentAttempt {
network_advice_code: storage_model.network_advice_code,
network_decline_code: storage_model.network_decline_code,
network_error_message: storage_model.network_error_message,
+ standardised_code,
});
Ok::<Self, error_stack::Report<common_utils::errors::CryptoError>>(Self {
@@ -2857,7 +2866,9 @@ impl Conversion for PaymentAttempt {
authorized_amount,
amount_captured: amount_details.get_amount_captured(),
encrypted_payment_method_data: None,
- error_details: None,
+ error_details: error_details
+ .as_ref()
+ .map(diesel_models::payment_attempt::ErrorDetails::from),
retry_type: None,
external_surcharge_details: None,
applied_offer_details: None,
@@ -2909,6 +2920,7 @@ impl ForeignFrom<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateIn
cancellation_reason: None,
amount_captured: None,
payment_method_data: None,
+ error_details: None,
},
PaymentAttemptUpdate::ErrorUpdate {
status,
@@ -2925,6 +2937,10 @@ impl ForeignFrom<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateIn
.map(|(txn_id, txn_data)| (Some(txn_id), txn_data))
.unwrap_or((None, None));
+ // Built before the fields below are moved out of `error`.
+ let error_details =
+ diesel_models::payment_attempt::ErrorDetails::from(error.as_ref());
+
Self {
status: Some(status),
payment_method_id: None,
@@ -2935,8 +2951,8 @@ impl ForeignFrom<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateIn
error_reason: error.reason,
updated_by,
merchant_connector_id: None,
- unified_code: None,
- unified_message: None,
+ unified_code: error.unified_code,
+ unified_message: error.unified_message,
connector_payment_id,
connector_payment_data,
connector: None,
@@ -2955,6 +2971,7 @@ impl ForeignFrom<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateIn
cancellation_reason: None,
amount_captured: None,
payment_method_data,
+ error_details: Some(error_details),
}
}
PaymentAttemptUpdate::ConfirmIntentResponse(confirm_intent_response_update) => {
@@ -3007,6 +3024,7 @@ impl ForeignFrom<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateIn
cancellation_reason: None,
amount_captured: None,
payment_method_data,
+ error_details: None,
}
}
PaymentAttemptUpdate::SyncUpdate {
@@ -3045,6 +3063,7 @@ impl ForeignFrom<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateIn
cancellation_reason: None,
amount_captured,
payment_method_data: payment_method_data.map(pii::SecretSerdeValue::new),
+ error_details: None,
},
PaymentAttemptUpdate::CaptureUpdate {
status,
@@ -3080,6 +3099,7 @@ impl ForeignFrom<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateIn
cancellation_reason: None,
amount_captured: None,
payment_method_data: None,
+ error_details: None,
},
PaymentAttemptUpdate::RecordBackUpdate {
feature_metadata,
@@ -3114,6 +3134,7 @@ impl ForeignFrom<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateIn
cancellation_reason: None,
amount_captured: None,
payment_method_data: None,
+ error_details: None,
},
PaymentAttemptUpdate::PreCaptureUpdate {
amount_to_capture,
@@ -3148,6 +3169,7 @@ impl ForeignFrom<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateIn
cancellation_reason: None,
amount_captured: None,
payment_method_data: None,
+ error_details: None,
},
PaymentAttemptUpdate::ConfirmIntentTokenized {
status,
@@ -3187,6 +3209,7 @@ impl ForeignFrom<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateIn
cancellation_reason: None,
amount_captured: None,
payment_method_data: None,
+ error_details: None,
},
PaymentAttemptUpdate::VoidUpdate {
status,
@@ -3222,6 +3245,7 @@ impl ForeignFrom<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateIn
payment_method_id: None,
amount_captured: None,
payment_method_data: None,
+ error_details: None,
},
}
}