Wrong card number validations
See original GitHub issueThe first case is when passing an empty string, the resulting object asserts true
. It was supposed to return false, right?
import pagarme from 'pagarme'
...
console.log(pagarme.validate({card: {card_number: ""}})))
Another cases are bad errors handling for miscellaneous inputs:
This works and returns true, as it should be:
console.log(pagarme.validate({ card: { card_number: "4242424242424242" } }))
But sending the same input as integer:
console.log(pagarme.validate({ card: { card_number: 4242424242424242 } }))
Also, this returns true either:
console.log(pagarme.validate({ card: { card_number: "424242424242____" } }))
It took me a while to actually realize what wrong with my code, as the documentation here says nothing about this validate
method, and the documentation at https://docs.pagar.me/docs/obtendo-os-dados-do-cartao
is too simple.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:7
- Comments:12 (9 by maintainers)
Top GitHub Comments
@MarcoWorms Taking advantage of the issue.
When i try to create a card_hash sending just the number 1 in the card_number, the following exception was launched:
But when i send other number, like 4, the following ocorred:
With it, i guess the problem is with the BIN validations, cause the number 1 does not belong to anyone brand, and the number 4 belongs to Visa.
(Não sabe como sofri pra escrever tudo isso em inglês, e provavelmente em um inglês deplorável xD)
The problem with the validation is because of this:
https://github.com/pagarme/pagarme-js/blob/master/lib/validations/validate/card/cardNumber.js#L41
According to the documentation, the order should be
Notice the order of the digits and acc arguments.