Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixing isValid method #152

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

davidalves1
Copy link

What is the change?

Fix isValid method when an invalid card number is passed with a valid checksum

Why make this change?

In order to fix this issue: #139

Test plan

@@ -47,7 +48,7 @@ function validateCards(number, cards) {
}

function hasCorrectLength(number) {
return number && number.length <= 19;
return number && number.length === CARD_NUMBER_LENGTH;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot define that the card number must have 16 digits. For example AMEX has 15 digits, and some others up to 19, and sometimes 13.

https://www.pcidssguide.com/what-do-the-credit-card-numbers-mean/

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, so following this article and the others bellow, the range of credit card number length is 12 to 19, right?!
In this way, I believe it is possible to define this range to avoid errors like the one described in the issue. What do you think?

https://www.discoverglobalnetwork.com/content/dam/discover/en_us/dgn/docs/IPP-VAR-Enabler-Compliance.pdf
https://www.forbes.com/advisor/credit-cards/what-does-your-credit-card-number-mean/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I evaluated the list of supported cards and added the number of digits for each one:

American Express (15 digits)
Aura (19 digits)
Banescard (16 digits)
Cabal (16 digits)
Diners (14 digits)
Discover (16 digits)
Elo (16 digits)
Goodcard (16 digits)
Hipercard (16 digits)
Mastercard (16 digits)
Maxxvan (16 digits)
Visa (16 digits)

With this we can conclude that the cards must have between 14 and 19 digits.

What do you think of we add a "cardNumberLenght" property to each card in cards.js and create a method to check the minimum and maximum number of digits for a valid card? This way we avoid adding the number manually in the isValid method.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree, looks like a good way. I can close this PR and open another one with this implementation.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is exactly why i did in another version :) and why in the public release i don't validate by length

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants