Skip to content
Snippets Groups Projects
Commit 0020e804 authored by Carlos Vega's avatar Carlos Vega
Browse files

added method calculate_luhn_checksum

parent 34ce8645
No related branches found
No related tags found
1 merge request!178Feature/import data pdp
def digits_of(n):
return [int(d) for d in str(n)]
class LuhnAlgorithm(object):
def __init__(self):
pass
@staticmethod
def luhn_checksum(card_number):
def digits_of(n):
return [int(d) for d in str(n)]
digits = digits_of(card_number)
odd_digits = digits[-1::-2]
even_digits = digits[-2::-2]
......@@ -19,3 +21,7 @@ class LuhnAlgorithm(object):
@staticmethod
def is_luhn_valid(card_number):
return LuhnAlgorithm.luhn_checksum(card_number) == 0
@staticmethod
def calculate_luhn_checksum(card_number):
return (10 - LuhnAlgorithm.luhn_checksum(card_number + '0')) % 10
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment