Set preferred = False for cards that are not preferred

This commit is contained in:
PCoder 2017-10-28 16:47:10 +02:00
parent b6d1e8df6b
commit a17a5f66bc

View file

@ -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()