mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 09:07:09 +08:00
refactor(payment_methods): Enable deletion of default Payment Methods (#4942)
This commit is contained in:
@ -3993,16 +3993,6 @@ pub async fn delete_payment_method(
|
|||||||
.await
|
.await
|
||||||
.to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)?;
|
.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
|
let customer = db
|
||||||
.find_customer_by_customer_id_merchant_id(
|
.find_customer_by_customer_id_merchant_id(
|
||||||
&key.customer_id,
|
&key.customer_id,
|
||||||
@ -4014,12 +4004,6 @@ pub async fn delete_payment_method(
|
|||||||
.to_not_found_response(errors::ApiErrorResponse::InternalServerError)
|
.to_not_found_response(errors::ApiErrorResponse::InternalServerError)
|
||||||
.attach_printable("Customer not found for the payment method")?;
|
.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) {
|
if key.payment_method == Some(enums::PaymentMethod::Card) {
|
||||||
let response = delete_card_from_locker(
|
let response = delete_card_from_locker(
|
||||||
&state,
|
&state,
|
||||||
|
|||||||
Reference in New Issue
Block a user