Issue #2790551 by steveoliver, bojanz, borisson_: Implement a JS libr…#663
Issue #2790551 by steveoliver, bojanz, borisson_: Implement a JS libr…#663mglaman wants to merge 1 commit intodrupalcommerce:8.x-2.xfrom
Conversation
6be1d5c to
b8a7444
Compare
| '0604', | ||
| '6390' | ||
| ], | ||
| lenghts: [12, 13, 14, 15, 16, 17, 18, 19] |
| var MAESTRO = 'maestro'; | ||
|
|
||
| types[VISA] = { | ||
| niceType: 'Visa', |
There was a problem hiding this comment.
Why niceType and not label?
And why aren't the labels passed through Drupal.t()?
| niceType: 'Visa', | ||
| type: VISA, | ||
| pattern: ['4'], | ||
| gaps: [4, 8, 12], |
There was a problem hiding this comment.
Gaps are not used anywhere, and don't exist on the PHP side, let's remove them.
| types[MASTERCARD] = { | ||
| niceType: 'MasterCard', | ||
| type: MASTERCARD, | ||
| pattern: ['51-55', '222100-272099'], |
There was a problem hiding this comment.
"pattern" should be "prefixes" to match the PHP code.
| var AMEX = 'amex'; | ||
| var DINERSCLUB = 'dinersclub'; | ||
| var DISCOVER = 'discover'; | ||
| var MAESTRO = 'maestro'; |
There was a problem hiding this comment.
We're missing JCB and UnionPay.
| * @return {object|boolean} | ||
| */ | ||
| var detectType = function (number) { | ||
| // Loop over all available types. |
There was a problem hiding this comment.
Comments that retell what the code is doing ("Loop over all the available types") aren't useful, let's remove them.
|
|
||
| // Loop over all patterns in the type. | ||
| for (var i in type.pattern) { | ||
| var pattern = type.pattern[i]; |
There was a problem hiding this comment.
Why don't we introduce a matchPrefix() helper like we did in PHP?
On the other hand, validatePrefix() could probably be inlined.
| var range; | ||
| exploded_pattern = pattern.split('-'); | ||
|
|
||
| while (exploded_pattern[0] <= exploded_pattern[1]) { |
There was a problem hiding this comment.
This feels overly complex.
We reimplementing the following code:
list($start, $end) = explode('-', $prefix);
$number = substr($number, 0, strlen($start));
return $number >= $start && $number <= $end;
| } | ||
| } | ||
|
|
||
| ValidationDiv.append('CC is of type: ' + type.niceType); |
|
This PR needs work. We basically want a JS version of our CreditCard.php code. Compared to 11 months ago, we have a real world need for the code in Commerce AuthNet: https://www.drupal.org/project/commerce_authnet/issues/2932486 which should help us ensure that the merged code is solid. Also, ouch, we have no way to write JS unit tests yet. Issue to follow is https://www.drupal.org/project/drupal/issues/2815199 |
…ary for the credit card form
d324fa2 to
48e9208
Compare
…ary for the credit card form