fix(payment_methods): return appropriate error when basilisk locker token expires (#1517)

Co-authored-by: SamraatBansal <samraatbansal7@gmail.com>
This commit is contained in:
Shankar Singh C
2023-06-27 13:17:17 +05:30
committed by GitHub
parent 1a8f5ff225
commit 9969c930a9
3 changed files with 20 additions and 4 deletions

View File

@ -203,6 +203,8 @@ pub enum StripeErrorCode {
WebhookProcessingError,
#[error(error_type = StripeErrorType::InvalidRequestError, code = "payment_method_unactivated", message = "The operation cannot be performed as the payment method used has not been activated. Activate the payment method in the Dashboard, then try again.")]
PaymentMethodUnactivated,
#[error(error_type = StripeErrorType::HyperswitchError, code = "", message = "{entity} expired or invalid")]
HyperswitchUnprocessableEntity { entity: String },
// [#216]: https://github.com/juspay/hyperswitch/issues/216
// Implement the remaining stripe error codes
@ -379,6 +381,9 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
param: field_name.to_string(),
}
}
errors::ApiErrorResponse::UnprocessableEntity { entity } => {
Self::HyperswitchUnprocessableEntity { entity }
}
errors::ApiErrorResponse::MissingRequiredFields { field_names } => {
// Instead of creating a new error variant in StripeErrorCode for MissingRequiredFields, converted vec<&str> to String
Self::ParameterMissing {
@ -529,7 +534,9 @@ impl actix_web::ResponseError for StripeErrorCode {
match self {
Self::Unauthorized => StatusCode::UNAUTHORIZED,
Self::InvalidRequestUrl => StatusCode::NOT_FOUND,
Self::ParameterUnknown { .. } => StatusCode::UNPROCESSABLE_ENTITY,
Self::ParameterUnknown { .. } | Self::HyperswitchUnprocessableEntity { .. } => {
StatusCode::UNPROCESSABLE_ENTITY
}
Self::ParameterMissing { .. }
| Self::RefundAmountExceedsPaymentAmount { .. }
| Self::PaymentIntentAuthenticationFailure { .. }