diff --git a/crates/router/src/consts.rs b/crates/router/src/consts.rs index 3a94a4e76557..0c9e9443ac91 100644 --- a/crates/router/src/consts.rs +++ b/crates/router/src/consts.rs @@ -119,3 +119,6 @@ pub const DEFAULT_POLL_DELAY_IN_SECS: i8 = 2; pub const DEFAULT_POLL_FREQUENCY: i8 = 5; pub const CONNECTOR_CREDS_TOKEN_TTL: i64 = 900; + +//max_amount allowed is 999999999 in minor units +pub const MAX_ALLOWED_AMOUNT: i64 = 999999999; diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index 5723c7f8b9a6..24ac32db91b2 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -1370,6 +1370,24 @@ fn validate_options_for_inequality( ) } +pub fn validate_max_amount( + amount: api_models::payments::Amount, +) -> CustomResult<(), errors::ApiErrorResponse> { + match amount { + api_models::payments::Amount::Value(value) => { + utils::when(value.get() > consts::MAX_ALLOWED_AMOUNT, || { + Err(report!(errors::ApiErrorResponse::PreconditionFailed { + message: format!( + "amount should not be more than {}", + consts::MAX_ALLOWED_AMOUNT + ) + })) + }) + } + api_models::payments::Amount::Zero => Ok(()), + } +} + // Checks if the customer details are passed in both places // If so, raise an error pub fn validate_customer_details_in_request( diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs index f5ab92911e24..e48a6ce717f7 100644 --- a/crates/router/src/core/payments/operations/payment_confirm.rs +++ b/crates/router/src/core/payments/operations/payment_confirm.rs @@ -1249,6 +1249,9 @@ impl ValidateRequest for PaymentConfir operations::ValidateResult<'a>, )> { helpers::validate_customer_details_in_request(request)?; + if let Some(amount) = request.amount { + helpers::validate_max_amount(amount)?; + } let request_merchant_id = request.merchant_id.as_deref(); helpers::validate_merchant_id(&merchant_account.merchant_id, request_merchant_id) diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index f8ea54382332..7ad47deff4d8 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -661,6 +661,9 @@ impl ValidateRequest for PaymentCreate operations::ValidateResult<'a>, )> { helpers::validate_customer_details_in_request(request)?; + if let Some(amount) = request.amount { + helpers::validate_max_amount(amount)?; + } if let Some(session_expiry) = &request.session_expiry { helpers::validate_session_expiry(session_expiry.to_owned())?; } diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs index b52611e6f911..0809a810074f 100644 --- a/crates/router/src/core/payments/operations/payment_update.rs +++ b/crates/router/src/core/payments/operations/payment_update.rs @@ -743,6 +743,9 @@ impl ValidateRequest for PaymentUpdate operations::ValidateResult<'a>, )> { helpers::validate_customer_details_in_request(request)?; + if let Some(amount) = request.amount { + helpers::validate_max_amount(amount)?; + } if let Some(session_expiry) = &request.session_expiry { helpers::validate_session_expiry(session_expiry.to_owned())?; }