From 41de724904ef7089255dbcf9690ed82339c5b9d9 Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 31 Dec 2020 15:24:47 +0530 Subject: [PATCH] Handle PaymentMethod type in set_default_card --- hosting/models.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hosting/models.py b/hosting/models.py index ac44cc9e..fe0d824c 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -673,7 +673,11 @@ class UserCardDetail(AssignPermissionsMixin, models.Model): stripe_utils = StripeUtils() cus_response = stripe_utils.get_customer(stripe_api_cus_id) cu = cus_response['response_object'] - cu.default_source = stripe_source_id + if stripe_source_id.startswith("pm"): + # card is a payment method + cu.invoice_settings.default_payment_method = stripe_source_id + else: + cu.default_source = stripe_source_id cu.save() UserCardDetail.save_default_card_local( stripe_api_cus_id, stripe_source_id