diff --git a/billing/utils/credit_card.py b/billing/utils/credit_card.py index dc2207c4..850a2100 100644 --- a/billing/utils/credit_card.py +++ b/billing/utils/credit_card.py @@ -32,7 +32,10 @@ def __init__(self, **kwargs): def is_luhn_valid(self): """Checks the validity of card number by using Luhn Algorithm. Please see http://en.wikipedia.org/wiki/Luhn_algorithm for details.""" - num = [int(x) for x in str(self.number)] + try: + num = [int(x) for x in str(self.number)] + except ValueError: + return False return not sum(num[::-2] + [sum(divmod(d * 2, 10)) for d in num[-2::-2]]) % 10 def is_expired(self):