Do a get on UserCardDetail only when fingerprint, exp_month and exp_year are known

This commit is contained in:
PCoder 2018-07-03 23:23:02 +02:00
parent 1c5ff1f9dd
commit d98a683b2a

View file

@ -272,12 +272,16 @@ class UserCardDetail(AssignPermissionsMixin, models.Model):
:return: UserCardDetail object
"""
try:
card_detail = UserCardDetail.objects.get(
stripe_customer=stripe_customer,
fingerprint=card_details['fingerprint'],
exp_month=card_details['exp_month'],
exp_year=card_details['exp_year']
)
if ('fingerprint' in card_details and 'exp_month' in card_details
and 'exp_year' in card_details):
card_detail = UserCardDetail.objects.get(
stripe_customer=stripe_customer,
fingerprint=card_details['fingerprint'],
exp_month=card_details['exp_month'],
exp_year=card_details['exp_year']
)
else:
raise UserCardDetail.DoesNotExist()
except UserCardDetail.DoesNotExist:
preferred = False
if 'preferred' in card_details: