From 820a97aa7e043895a7d87db08569c84ef2a33304 Mon Sep 17 00:00:00 2001 From: "Julio C. Menendez" Date: Sat, 1 Jun 2013 10:41:00 -0600 Subject: [PATCH] Fixes ValueError exception when CC number contains non numeric chars --- billing/utils/credit_card.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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):