mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-11-01 02:57:02 +08:00 
			
		
		
		
	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:
		| @ -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(()) | ||||
|     } | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Sahkal Poddar
					Sahkal Poddar