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): change error for payment session expiry (#12876)

Sakil Mostak6c307fc09d84
diff --git a/crates/hyperswitch_domain_models/src/errors/api_error_response.rs b/crates/hyperswitch_domain_models/src/errors/api_error_response.rs
index bdca4e6176..5bf493ed7b 100644
--- a/crates/hyperswitch_domain_models/src/errors/api_error_response.rs
+++ b/crates/hyperswitch_domain_models/src/errors/api_error_response.rs
@@ -312,6 +312,8 @@ pub enum ApiErrorResponse {
message = "Access forbidden, invalid Basic authentication credentials"
)]
InvalidBasicAuth,
+ #[error(error_type = ErrorType::InvalidRequestError, code = "IR_52", message = "Payment Session has expired")]
+ PaymentSessionExpired,
#[error(error_type = ErrorType::InvalidRequestError, code = "WE_01", message = "Failed to authenticate the webhook")]
WebhookAuthenticationFailed,
#[error(error_type = ErrorType::InvalidRequestError, code = "WE_02", message = "Bad request received in webhook")]
@@ -742,6 +744,11 @@ impl ErrorSwitch<api_models::errors::types::ApiErrorResponse> for ApiErrorRespon
AER::BadRequest(ApiError::new("CE", 9, format!("Subscription operation: {operation} failed with connector"), None))
}
Self::ExpiredJwtToken => AER::Unauthorized(ApiError::new("IR", 48, "Access forbidden, expired JWT token was used", None)),
+ Self::PaymentSessionExpired => AER::BadRequest(ApiError::new(
+ "IR",
+ 52,
+ "The provided payment session has expired", None
+ )),
}
}
}
diff --git a/crates/router/src/compatibility/stripe/errors.rs b/crates/router/src/compatibility/stripe/errors.rs
index 4fba447656..5f794b2697 100644
--- a/crates/router/src/compatibility/stripe/errors.rs
+++ b/crates/router/src/compatibility/stripe/errors.rs
@@ -713,6 +713,7 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
errors::ApiErrorResponse::SubscriptionError { operation } => {
Self::SubscriptionError { operation }
}
+ errors::ApiErrorResponse::PaymentSessionExpired => Self::PaymentNotFound,
}
}
}
diff --git a/crates/router/src/core/payments/client_session.rs b/crates/router/src/core/payments/client_session.rs
index 1bbac65a5a..dd9db9978b 100644
--- a/crates/router/src/core/payments/client_session.rs
+++ b/crates/router/src/core/payments/client_session.rs
@@ -87,9 +87,7 @@ impl ClientSessionManager {
let ttl_seconds = if ttl_seconds > 0 {
Ok(ttl_seconds)
} else {
- Err(errors::ApiErrorResponse::PreconditionFailed {
- message: "Session expiry is in the past".to_string(),
- })
+ Err(errors::ApiErrorResponse::PaymentSessionExpired)
}?;
// Create session data structure