From 63eb7fc0e2278721932adebe114e3cfe7236313e Mon Sep 17 00:00:00 2001 From: PCoder Date: Sun, 29 Oct 2017 21:31:11 +0100 Subject: [PATCH] Rename contains to get_user_card_details --- hosting/models.py | 9 +++++---- hosting/views.py | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/hosting/models.py b/hosting/models.py index 9486eae7..7a181fe1 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -312,21 +312,22 @@ class UserCardDetail(AssignPermissionsMixin, models.Model): user_card_detail.save() @staticmethod - def contains(stripe_customer, card_details): + def get_user_card_details(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: + :return: The UserCardDetails object if it exists, False otherwise """ try: - UserCardDetail.objects.get( + ucd = 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 + return ucd except UserCardDetail.DoesNotExist: return False diff --git a/hosting/views.py b/hosting/views.py index 6d5c9a78..5a9c2e2e 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -628,7 +628,7 @@ class SettingsView(LoginRequiredMixin, FormView): email=request.user.email, token=token ) card = card_details['response_object'] - if UserCardDetail.contains(stripe_customer, card): + if UserCardDetail.get_user_card_details(stripe_customer, card): msg = _('You seem to have already added this card') messages.add_message(request, messages.ERROR, msg) else: @@ -878,7 +878,7 @@ class OrdersHostingDetailView(LoginRequiredMixin, 'brand': card_details_response['brand'], 'card_id': card_details_response['card_id'] } - ucd = UserCardDetail.contains( + ucd = UserCardDetail.get_user_card_details( request.user.stripecustomer, card_details_response ) if not ucd: