Skip to content

Commit

Permalink
Merge pull request #75 from juliomenendez/master
Browse files Browse the repository at this point in the history
ValueError exception raised when CC number contains non numeric characters
  • Loading branch information
tuxcanfly committed Jun 4, 2013
2 parents 109870c + 820a97a commit 79a83f8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion billing/utils/credit_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 79a83f8

Please sign in to comment.