fix(router): added validation to check total orderDetails amount equal to amount in request (#2965)

Co-authored-by: Sahkal Poddar <sahkal.poddar@juspay.in>
This commit is contained in:
Sahkal Poddar
2023-11-27 10:43:59 +05:30
committed by GitHub
parent 04b7c0384d
commit 37532d46f5
4 changed files with 40 additions and 0 deletions

View File

@ -3686,3 +3686,22 @@ pub async fn get_gsm_record(
})
.ok()
}
pub fn validate_order_details_amount(
order_details: Vec<api_models::payments::OrderDetailsWithAmount>,
amount: i64,
) -> Result<(), errors::ApiErrorResponse> {
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(),
})
} else {
Ok(())
}
}