From a17a5f66bc1e89636b779a35a81e230876f2fe75 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 28 Oct 2017 16:47:10 +0200 Subject: [PATCH] Set preferred = False for cards that are not preferred --- hosting/models.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/hosting/models.py b/hosting/models.py index d95adf13..78743edc 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -282,7 +282,7 @@ class UserCardDetail(AssignPermissionsMixin, models.Model): cu = cus_response['response_object'] cu.default_source = stripe_source_id cu.save() - self._save_default_card(stripe_api_cus_id, stripe_source_id) + self.save_default_card(stripe_api_cus_id, stripe_source_id) def set_default_card_from_stripe(self, stripe_api_cus_id): stripe_utils = StripeUtils() @@ -290,12 +290,15 @@ class UserCardDetail(AssignPermissionsMixin, models.Model): cu = cus_response['response_object'] default_source = cu.default_source if default_source is not None: - self._save_default_card(stripe_api_cus_id, default_source) + self.save_default_card(stripe_api_cus_id, default_source) - def _save_default_card(self, stripe_api_cus_id, card_id): + def save_default_card(self, stripe_api_cus_id, card_id): stripe_cust = StripeCustomer.objects.get(stripe_id=stripe_api_cus_id) user_card_detail = UserCardDetail.objects.get( stripe_customer=stripe_cust, card_id=card_id ) + for card in stripe_cust.usercarddetail_set.all(): + card.preferred = False + card.save() user_card_detail.preferred = True - user_card_detail.save() \ No newline at end of file + user_card_detail.save()