diff --git a/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/credit-card-number-validator.js b/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/credit-card-number-validator.js index 018c0cbb6b1d62c3be1f7317fc9a67ae1dbc0193..1f13a5af7c60a297dd13867daa9e1ba4694fbe5d 100644 --- a/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/credit-card-number-validator.js +++ b/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/credit-card-number-validator.js @@ -13,7 +13,7 @@ define( function (utils, luhn10, creditCardTypes) { 'use strict'; - function result(card, isPotentiallyValid, isValid) { + function resultWrapper(card, isPotentiallyValid, isValid) { return { card: card, isValid: isValid, @@ -29,21 +29,21 @@ define( maxLength; if (utils.isEmpty(value)) { - return result(null, false, false); + return resultWrapper(null, false, false); } value = value.replace(/\-|\s/g, ''); if (!/^\d*$/.test(value)) { - return result(null, false, false); + return resultWrapper(null, false, false); } potentialTypes = creditCardTypes.getCardTypes(value); if (potentialTypes.length === 0) { - return result(null, false, false); + return resultWrapper(null, false, false); } else if (potentialTypes.length !== 1) { - return result(null, true, false); + return resultWrapper(null, true, false); } cardType = potentialTypes[0]; @@ -56,17 +56,17 @@ define( for (i = 0; i < cardType.lengths.length; i++) { if (cardType.lengths[i] === value.length) { - return result(cardType, valid, valid); + return resultWrapper(cardType, valid, valid); } } maxLength = Math.max.apply(null, cardType.lengths); if (value.length < maxLength) { - return result(cardType, true, false); + return resultWrapper(cardType, true, false); } - return result(cardType, false, false); + return resultWrapper(cardType, false, false); }; } ); diff --git a/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/credit-card-number-validator/credit-card-type.js b/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/credit-card-number-validator/credit-card-type.js index f0685c6d67cd95efe8a857d2f49cdf24ad65cba3..71e0e57c5c16e71a394d1fa948f35ed807c75495 100644 --- a/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/credit-card-number-validator/credit-card-type.js +++ b/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/credit-card-number-validator/credit-card-type.js @@ -13,7 +13,7 @@ define( 'use strict'; var types = [ { - niceType: 'Visa', + title: 'Visa', type: 'VI', pattern: '^4\\d*$', gaps: [4, 8, 12], @@ -24,7 +24,7 @@ define( } }, { - niceType: 'MasterCard', + title: 'MasterCard', type: 'MC', pattern: '^5([1-5]\\d*)?$', gaps: [4, 8, 12], @@ -35,7 +35,7 @@ define( } }, { - niceType: 'American Express', + title: 'American Express', type: 'AE', pattern: '^3([47]\\d*)?$', isAmex: true, @@ -47,7 +47,7 @@ define( } }, { - niceType: 'Diners', + title: 'Diners', type: 'DN', pattern: '^3((0([0-5]\\d*)?)|[689]\\d*)?$', gaps: [4, 10], @@ -58,7 +58,7 @@ define( } }, { - niceType: 'Discover', + title: 'Discover', type: 'DI', pattern: '^6(0|01|011\\d*|5\\d*|4|4[4-9]\\d*)?$', gaps: [4, 8, 12], @@ -69,7 +69,7 @@ define( } }, { - niceType: 'JCB', + title: 'JCB', type: 'JC', pattern: '^((2|21|213|2131\\d*)|(1|18|180|1800\\d*)|(3|35\\d*))$', gaps: [4, 8, 12], @@ -80,7 +80,7 @@ define( } }, { - niceType: 'UnionPay', + title: 'UnionPay', type: 'UN', pattern: '^6(2\\d*)?$', gaps: [4, 8, 12], @@ -91,9 +91,24 @@ define( } }, { - niceType: 'Maestro', + title: 'Maestro', type: 'SM', - pattern: '(^(5[0678])[0-9]{11,18}$)|(^(6[^05])[0-9]{11,18}$)|(^(601)[^1][0-9]{9,16}$)|(^(6011)[0-9]{9,11}$)|(^(6011)[0-9]{13,16}$)|(^(65)[0-9]{11,13}$)|(^(65)[0-9]{15,18}$)|(^(49030)[2-9]([0-9]{10}$|[0-9]{12,13}$))|(^(49033)[5-9]([0-9]{10}$|[0-9]{12,13}$))|(^(49110)[1-2]([0-9]{10}$|[0-9]{12,13}$))|(^(49117)[4-9]([0-9]{10}$|[0-9]{12,13}$))|(^(49118)[0-2]([0-9]{10}$|[0-9]{12,13}$))|(^(4936)([0-9]{12}$|[0-9]{14,15}$))', + pattern: '(^(5[0678])[0-9]{11,18}$)' + + '|(^(6[^05])[0-9]{11,18}$)' + + '|(^(601)[^1][0-9]{9,16}$)' + + '|(^(6011)[0-9]{9,11}$)' + + '|(^(6011)[0-9]{13,16}$)' + + '|(^(65)[0-9]{11,13}$)' + + '|(^(65)[0-9]{15,18}$)' + + '|(^(49030)[2-9]([0-9]{10}$' + + '|[0-9]{12,13}$))' + + '|(^(49033)[5-9]([0-9]{10}$' + + '|[0-9]{12,13}$))' + + '|(^(49110)[1-2]([0-9]{10}$' + + '|[0-9]{12,13}$))' + + '|(^(49117)[4-9]([0-9]{10}$|[0-9]{12,13}$))' + + '|(^(49118)[0-2]([0-9]{10}$|[0-9]{12,13}$))' + + '|(^(4936)([0-9]{12}$|[0-9]{14,15}$))', gaps: [4, 8, 12], lengths: [12, 13, 14, 15, 16, 17, 18, 19], code: { diff --git a/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/credit-card-number-validator/luhn10-validator.js b/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/credit-card-number-validator/luhn10-validator.js index 22d5f8acdd93a33419abdf644dbbf4b563c853aa..38e93f084a25c72c8be813e52fa4f75b44c46622 100644 --- a/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/credit-card-number-validator/luhn10-validator.js +++ b/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/credit-card-number-validator/luhn10-validator.js @@ -8,8 +8,11 @@ define( [], function() { 'use strict'; - return function(a,b,c,d,e) { - for(d = +a[b = a.length-1], e=0; b--;) { + /** + * Luhn algorithm verification + */ + return function(a, b, c, d, e) { + for(d = +a[b = a.length-1], e = 0; b--;) { c = +a[b]; d += ++e % 2 ? 2 * c % 10 + (c > 4) : c; } diff --git a/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/cvv-validator.js b/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/cvv-validator.js index 812ee62b363aa58e857db7df4a6c8e23be8e6471..45733c9f8ff4623727ba757c88f0cd92ad346f21 100644 --- a/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/cvv-validator.js +++ b/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/cvv-validator.js @@ -9,31 +9,33 @@ define( function() { 'use strict'; - function result(isValid, isPotentiallyValid) { + function resultWrapper(isValid, isPotentiallyValid) { return { isValid: isValid, isPotentiallyValid: isPotentiallyValid }; } + /** + * CVV number validation + * validate digit count fot CVV code + */ return function(value, maxLength) { var DEFAULT_LENGTH = 3; maxLength = maxLength || DEFAULT_LENGTH; if (!/^\d*$/.test(value)) { - return result(false, false); + return resultWrapper(false, false); } if (value.length === maxLength) { - return result(true, true); + return resultWrapper(true, true); } if (value.length < maxLength) { - return result(false, true); + return resultWrapper(false, true); } if (value.length > maxLength) { - return result(false, false); + return resultWrapper(false, false); } - - return result(true, true); }; } ); diff --git a/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/expiration-date-validator.js b/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/expiration-date-validator.js index 1dda53d0721e1aa1b10dd022c2aa32c4e43553e8..f7266a282740c6eb258839a7746bf57dbb1b329b 100644 --- a/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/expiration-date-validator.js +++ b/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/expiration-date-validator.js @@ -14,7 +14,7 @@ define( function(utils, parseDate, expirationMonth, expirationYear) { 'use strict'; - function result(isValid, isPotentiallyValid, month, year) { + function resultWrapper(isValid, isPotentiallyValid, month, year) { return { isValid: isValid, isPotentiallyValid: isPotentiallyValid, @@ -29,7 +29,7 @@ define( yearValid; if (utils.isEmpty(value)) { - return result(false, false, null, null); + return resultWrapper(false, false, null, null); } value = value.replace(/^(\d\d) (\d\d(\d\d)?)$/, '$1/$2'); @@ -38,14 +38,14 @@ define( yearValid = expirationYear(date.year); if (monthValid.isValid && yearValid.isValid) { - return result(true, true, date.month, date.year); + return resultWrapper(true, true, date.month, date.year); } if (monthValid.isPotentiallyValid && yearValid.isPotentiallyValid) { - return result(false, true, null, null); + return resultWrapper(false, true, null, null); } - return result(false, false, null, null); + return resultWrapper(false, false, null, null); } } ); diff --git a/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/expiration-date-validator/expiration-month-validator.js b/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/expiration-date-validator/expiration-month-validator.js index d9f9729a7c6dd0d27e80af92f6864a4e29098a68..c41ad14a459dbe7f788b8b0e21dd07a62150561c 100644 --- a/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/expiration-date-validator/expiration-month-validator.js +++ b/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/expiration-date-validator/expiration-month-validator.js @@ -9,7 +9,7 @@ define( function () { 'use strict'; - function result(isValid, isPotentiallyValid) { + function resultWrapper(isValid, isPotentiallyValid) { return { isValid: isValid, isPotentiallyValid: isPotentiallyValid @@ -21,21 +21,21 @@ define( monthValid; if ((value.replace(/\s/g, '') === '') || (value === '0')) { - return result(false, true); + return resultWrapper(false, true); } if (!/^\d*$/.test(value)) { - return result(false, false); + return resultWrapper(false, false); } if (isNaN(value)) { - return result(false, false); + return resultWrapper(false, false); } month = parseInt(value, 10); monthValid = month > 0 && month < 13; - return result(monthValid, monthValid); + return resultWrapper(monthValid, monthValid); }; } ); diff --git a/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/expiration-date-validator/expiration-year-validator.js b/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/expiration-date-validator/expiration-year-validator.js index 5b0c1da544b57c717f5096c44a0a42702b2e4e68..132c8dc42e9f2675647eb4112d09100fae84f7dd 100644 --- a/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/expiration-date-validator/expiration-year-validator.js +++ b/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/expiration-date-validator/expiration-year-validator.js @@ -9,7 +9,7 @@ define( function() { 'use strict'; - function result(isValid, isPotentiallyValid) { + function resultWrapper(isValid, isPotentiallyValid) { return { isValid: isValid, isPotentiallyValid: isPotentiallyValid @@ -17,47 +17,26 @@ define( } return function(value) { - var currentFirstTwo, - currentYear = new Date().getFullYear(), - firstTwo, + var currentYear = new Date().getFullYear(), len = value.length, - twoDigitYear, valid, - maxYear = 19; + expMaxLifetime = 19; if (value.replace(/\s/g, '') === '') { - return result(false, true); + return resultWrapper(false, true); } if (!/^\d*$/.test(value)) { - return result(false, false); + return resultWrapper(false, false); } - if (len < 2) { - return result(false, true); - } - - if (len === 3) { - // 20x === 20x - firstTwo = value.slice(0, 2); - currentFirstTwo = String(currentYear).slice(0, 2); - return result(false, firstTwo === currentFirstTwo); - } - - if (len > 4) { - return result(false, false); + if (len !== 4) { + return resultWrapper(false, true); } value = parseInt(value, 10); - twoDigitYear = Number(String(currentYear).substr(2, 2)); - - if (len === 2) { - valid = value >= twoDigitYear && value <= twoDigitYear + maxYear; - } else if (len === 4) { - valid = value >= currentYear && value <= currentYear + maxYear; - } - - return result(valid, valid); + valid = value >= currentYear && value <= currentYear + expMaxLifetime; + return resultWrapper(valid, valid); }; } ); diff --git a/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/expiration-date-validator/parse-date.js b/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/expiration-date-validator/parse-date.js index 56c281a516e7af401a013b292107ccb1211e8932..119bfa698732ecb0bf8895dad4ec75d8edeac063 100644 --- a/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/expiration-date-validator/parse-date.js +++ b/app/code/Magento/Payment/view/frontend/web/js/model/credit-card-validation/expiration-date-validator/parse-date.js @@ -20,7 +20,7 @@ define( }; } - len = value[0] === '0' || value.length > 5 || value.length === 4 || value.length === 3 ? 2 : 1; + len = (value[0] === '0' || value.length > 5 || value.length === 4 || value.length === 3) ? 2 : 1; month = value.substr(0, len); return {