refactor(payment_methods): prevent deletion of default payment method for a customer (#3964)

This commit is contained in:
Chethan Rao
2024-03-06 19:05:28 +05:30
committed by GitHub
parent 3806cd35c7
commit db39bb0a3c
5 changed files with 29 additions and 2 deletions

View File

@ -251,6 +251,8 @@ pub enum StripeErrorCode {
InvalidConnectorConfiguration { config: String },
#[error(error_type = StripeErrorType::HyperswitchError, code = "HE_01", message = "Failed to convert currency to minor unit")]
CurrencyConversionFailed,
#[error(error_type = StripeErrorType::InvalidRequestError, code = "IR_25", message = "Cannot delete the default payment method")]
PaymentMethodDeleteFailed,
// [#216]: https://github.com/juspay/hyperswitch/issues/216
// Implement the remaining stripe error codes
@ -618,6 +620,7 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
Self::InvalidConnectorConfiguration { config }
}
errors::ApiErrorResponse::CurrencyConversionFailed => Self::CurrencyConversionFailed,
errors::ApiErrorResponse::PaymentMethodDeleteFailed => Self::PaymentMethodDeleteFailed,
}
}
}
@ -686,7 +689,8 @@ impl actix_web::ResponseError for StripeErrorCode {
| Self::DuplicateCustomer
| Self::PaymentMethodUnactivated
| Self::InvalidConnectorConfiguration { .. }
| Self::CurrencyConversionFailed => StatusCode::BAD_REQUEST,
| Self::CurrencyConversionFailed
| Self::PaymentMethodDeleteFailed => StatusCode::BAD_REQUEST,
Self::RefundFailed
| Self::PayoutFailed
| Self::PaymentLinkNotFound