Add contains utility method
This commit is contained in:
parent
4be105a0a9
commit
06a5cba50e
1 changed files with 20 additions and 0 deletions
|
@ -302,3 +302,23 @@ class UserCardDetail(AssignPermissionsMixin, models.Model):
|
||||||
card.save()
|
card.save()
|
||||||
user_card_detail.preferred = True
|
user_card_detail.preferred = True
|
||||||
user_card_detail.save()
|
user_card_detail.save()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def contains(stripe_customer, card_details):
|
||||||
|
"""
|
||||||
|
A utility function to check whether a StripeCustomer is already
|
||||||
|
associated with the card having given details
|
||||||
|
:param stripe_customer:
|
||||||
|
:param card_details:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
UserCardDetail.objects.get(
|
||||||
|
stripe_customer=stripe_customer,
|
||||||
|
fingerprint=card_details['fingerprint'],
|
||||||
|
exp_month=card_details['exp_month'],
|
||||||
|
exp_year=card_details['exp_year']
|
||||||
|
)
|
||||||
|
return True
|
||||||
|
except UserCardDetail.DoesNotExist:
|
||||||
|
return False
|
||||||
|
|
Loading…
Reference in a new issue