question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong card number validations

See original GitHub issue

The 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: ""}})))
screenshot 2017-08-14 15 45 07

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 } })) screenshot 2017-08-14 15 48 28

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:open
  • Created 6 years ago
  • Reactions:7
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
murilohnscommented, Aug 15, 2017

@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:

image image

But when i send other number, like 4, the following ocorred:

image image

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)

1reaction
thalesmellocommented, Sep 14, 2017

The problem with the validation is because of this:

https://github.com/pagarme/pagarme-js/blob/master/lib/validations/validate/card/cardNumber.js#L41

const reduFinalSum = withoutLastDigit => (acc, digit, index, digits) => {

According to the documentation, the order should be

const reduFinalSum = withoutLastDigit => (digit, acc, index, digits) => {

Notice the order of the digits and acc arguments.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Card Validation Error - PCI Booking API Documentation
Once the card data is submitted to PCI Booking, the data is validated. Card validation can fail due to specific card data errors,...
Read more >
Credit Card Validation Errors
This means that we were unable to verify your credit card. The error code number may vary, as there can be several different...
Read more >
What are the response codes for Credit Card Updater
This message indicates that the credit card information was not updated because the card number failed a check digit validation, such as due...
Read more >
The 'Credit Card Number' Field Must Allow and Auto-Format ...
Consequently, the subjects experienced fewer payment validation issues on sites that auto-formatted their card number input with spaces compared ...
Read more >
How does a website instantly know if a certain credit card ...
When I pressed the submit button, the website automatically gave me an error that the card number I entered was invalid.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found