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

refactor(router): flagged order_details validation to skip validation (#3116)

Sahkal Poddar8626bda6d5aa
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index fed8357bc3..ec6371f310 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -3742,17 +3742,22 @@ pub async fn get_gsm_record(
pub fn validate_order_details_amount(
order_details: Vec<api_models::payments::OrderDetailsWithAmount>,
amount: i64,
+ should_validate: bool,
) -> Result<(), errors::ApiErrorResponse> {
- let total_order_details_amount: i64 = order_details
- .iter()
- .map(|order| order.amount * i64::from(order.quantity))
- .sum();
+ if should_validate {
+ let total_order_details_amount: i64 = order_details
+ .iter()
+ .map(|order| order.amount * i64::from(order.quantity))
+ .sum();
- if total_order_details_amount != amount {
- Err(errors::ApiErrorResponse::InvalidRequestData {
- message: "Total sum of order details doesn't match amount in payment request"
- .to_string(),
- })
+ if total_order_details_amount != amount {
+ Err(errors::ApiErrorResponse::InvalidRequestData {
+ message: "Total sum of order details doesn't match amount in payment request"
+ .to_string(),
+ })
+ } else {
+ Ok(())
+ }
} else {
Ok(())
}
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index 0970a952c8..00ae8da6ae 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -104,6 +104,7 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
helpers::validate_order_details_amount(
order_details.to_owned(),
payment_intent.amount,
+ false,
)?;
}
diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs
index 94436026dc..09ec436ed0 100644
--- a/crates/router/src/core/payments/operations/payment_create.rs
+++ b/crates/router/src/core/payments/operations/payment_create.rs
@@ -245,6 +245,7 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
helpers::validate_order_details_amount(
order_details.to_owned(),
payment_intent.amount,
+ false,
)?;
}
diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs
index 5ed0c45d4e..afb83d38dc 100644
--- a/crates/router/src/core/payments/operations/payment_update.rs
+++ b/crates/router/src/core/payments/operations/payment_update.rs
@@ -64,6 +64,7 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
helpers::validate_order_details_amount(
order_details.to_owned(),
payment_intent.amount,
+ false,
)?;
}