This library is a clone of the original javascript implementation from Paylike.
/**
* Is the card number valid?
*/
val card = '6123451234567893'
val result = PaylikeLuhn.isValid(card) // true
/**
* Calculate check digit
* MII + IIN + "Individual account number"
*/
val checksum = PaylikeLuhn.calculateCheckDigit(card) // "3"
Implemented according to ISO/IEC 7812-1:2015(E) which goes:
-
Double the value of alternate digits beginning with the first right-hand digit (low order).
-
Add the individual digits comprising the products obtained in Step 1 to each of the unaffected digits in the original number.
-
Subtract the total obtained in Step 2 from the next higher number ending in 0 [this is the equivalent of calculating the “tens complement” of the low-order digit (unit digit) of the total]. If the total obtained in Step 2 is a number ending in zero (30, 40, etc.), the check digit is 0.umber ending in 0 [this is the equivalent of calculating the “tens complement” of the low-order digit (unit digit) of the total]. If the total obtained in Step 2 is a number ending in zero (30, 40, etc.), the check digit is 0.