Rename contains to get_user_card_details

This commit is contained in:
PCoder 2017-10-29 21:31:11 +01:00
parent abe8c9efa5
commit 63eb7fc0e2
2 changed files with 7 additions and 6 deletions

View file

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

View file

@ -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: