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

fix(router): send error_reason as error_message in payments and refund flows (#1878)

Sai Harsha Vardhan69821948c0a3
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index 1565f69bfe..04a0848aba 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -491,7 +491,11 @@ where
auth_flow == services::AuthFlow::Merchant,
)
.set_payment_token(payment_attempt.payment_token)
- .set_error_message(payment_attempt.error_reason)
+ .set_error_message(
+ payment_attempt
+ .error_reason
+ .or(payment_attempt.error_message),
+ )
.set_error_code(payment_attempt.error_code)
.set_shipping(address.shipping)
.set_billing(address.billing)
@@ -547,7 +551,9 @@ where
attempts: attempts_response,
payment_method: payment_attempt.payment_method,
capture_method: payment_attempt.capture_method,
- error_message: payment_attempt.error_message,
+ error_message: payment_attempt
+ .error_reason
+ .or(payment_attempt.error_message),
error_code: payment_attempt.error_code,
payment_method_data: payment_method_data_response,
email: customer
diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs
index b0dc979b7c..a61b662f46 100644
--- a/crates/router/src/core/refunds.rs
+++ b/crates/router/src/core/refunds.rs
@@ -203,7 +203,7 @@ pub async fn trigger_refund_to_gateway(
let refund_update = match router_data_res.response {
Err(err) => storage::RefundUpdate::ErrorUpdate {
refund_status: Some(enums::RefundStatus::Failure),
- refund_error_message: Some(err.message),
+ refund_error_message: err.reason.or(Some(err.message)),
refund_error_code: Some(err.code),
},
Ok(response) => {
@@ -430,7 +430,7 @@ pub async fn sync_refund_with_gateway(
let refund_update = match router_data_res.response {
Err(error_message) => storage::RefundUpdate::ErrorUpdate {
refund_status: None,
- refund_error_message: Some(error_message.message),
+ refund_error_message: error_message.reason.or(Some(error_message.message)),
refund_error_code: Some(error_message.code),
},
Ok(response) => storage::RefundUpdate::Update {