From 06a5cba50ed134699caf74a378f8de2af78a3c41 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 28 Oct 2017 18:28:14 +0200 Subject: [PATCH] Add contains utility method --- hosting/models.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/hosting/models.py b/hosting/models.py index 78743edc..d6367301 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -302,3 +302,23 @@ class UserCardDetail(AssignPermissionsMixin, models.Model): card.save() user_card_detail.preferred = True 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