refactor(payment_methods): Enable deletion of default Payment Methods (#4942)

This commit is contained in:
Amisha Prabhat
2024-06-12 15:45:37 +05:30
committed by GitHub
parent 40a996e84c
commit cf3d039efd

View File

@ -3993,16 +3993,6 @@ pub async fn delete_payment_method(
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)?;
let payment_methods_count = db
.get_payment_method_count_by_customer_id_merchant_id_status(
&key.customer_id,
&merchant_account.merchant_id,
api_enums::PaymentMethodStatus::Active,
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to get a count of payment methods for a customer")?;
let customer = db
.find_customer_by_customer_id_merchant_id(
&key.customer_id,
@ -4014,12 +4004,6 @@ pub async fn delete_payment_method(
.to_not_found_response(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Customer not found for the payment method")?;
utils::when(
customer.default_payment_method_id.as_ref() == Some(&pm_id.payment_method_id)
&& payment_methods_count > 1,
|| Err(errors::ApiErrorResponse::PaymentMethodDeleteFailed),
)?;
if key.payment_method == Some(enums::PaymentMethod::Card) {
let response = delete_card_from_locker(
&state,