Commit 50c5ef35 authored by Jesse Pollak's avatar Jesse Pollak
Browse files

Merge pull request #110 from KillaPL/update_jquery_payment

Update jquery payment
Showing with 155 additions and 96 deletions
+155 -96
!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.card=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
// Generated by CoffeeScript 1.7.1
(function() {
var $, cardFromNumber, cardFromType, cards, defaultFormat, formatBackCardNumber, formatBackExpiry, formatCardNumber, formatExpiry, formatForwardExpiry, formatForwardSlash, hasTextSelected, luhnCheck, reFormatCardNumber, restrictCVC, restrictCardNumber, restrictExpiry, restrictNumeric, setCardType,
var $, cardFromNumber, cardFromType, cards, defaultFormat, formatBackCardNumber, formatBackExpiry, formatCardNumber, formatExpiry, formatForwardExpiry, formatForwardSlashAndSpace, hasTextSelected, luhnCheck, reFormatCardNumber, reFormatExpiry, restrictCVC, restrictCardNumber, restrictExpiry, restrictNumeric, setCardType,
__slice = [].slice,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
......@@ -21,50 +21,43 @@
cards = [
{
type: 'maestro',
pattern: /^(5018|5020|5038|6304|6759|676[1-3])/,
type: 'visaelectron',
pattern: /^4(026|17500|405|508|844|91[37])/,
format: defaultFormat,
length: [12, 13, 14, 15, 16, 17, 18, 19],
length: [16],
cvcLength: [3],
luhn: true
}, {
type: 'dinersclub',
pattern: /^(36|38|30[0-5])/,
type: 'maestro',
pattern: /^(5(018|0[23]|[68])|6(39|7))/,
format: defaultFormat,
length: [14],
length: [12, 13, 14, 15, 16, 17, 18, 19],
cvcLength: [3],
luhn: true
}, {
type: 'laser',
pattern: /^(6706|6771|6709)/,
type: 'forbrugsforeningen',
pattern: /^600/,
format: defaultFormat,
length: [16, 17, 18, 19],
length: [16],
cvcLength: [3],
luhn: true
}, {
type: 'jcb',
pattern: /^35/,
type: 'dankort',
pattern: /^5019/,
format: defaultFormat,
length: [16],
cvcLength: [3],
luhn: true
}, {
type: 'unionpay',
pattern: /^62/,
format: defaultFormat,
length: [16, 17, 18, 19],
cvcLength: [3],
luhn: false
}, {
type: 'discover',
pattern: /^(6011|65|64[4-9]|622)/,
type: 'visa',
pattern: /^4/,
format: defaultFormat,
length: [16],
length: [13, 16],
cvcLength: [3],
luhn: true
}, {
type: 'mastercard',
pattern: /^5[1-5]/,
pattern: /^5[0-5]/,
format: defaultFormat,
length: [16],
cvcLength: [3],
......@@ -77,10 +70,31 @@
cvcLength: [3, 4],
luhn: true
}, {
type: 'visa',
pattern: /^4/,
type: 'dinersclub',
pattern: /^3[0689]/,
format: defaultFormat,
length: [13, 16],
length: [14],
cvcLength: [3],
luhn: true
}, {
type: 'discover',
pattern: /^6([045]|22)/,
format: defaultFormat,
length: [16],
cvcLength: [3],
luhn: true
}, {
type: 'unionpay',
pattern: /^(62|88)/,
format: defaultFormat,
length: [16, 17, 18, 19],
cvcLength: [3],
luhn: false
}, {
type: 'jcb',
pattern: /^35/,
format: defaultFormat,
length: [16],
cvcLength: [3],
luhn: true
}
......@@ -138,15 +152,13 @@
};
reFormatCardNumber = function(e) {
return setTimeout((function(_this) {
return function() {
var $target, value;
$target = $(e.currentTarget);
value = $target.val();
value = $.payment.formatCardNumber(value);
return $target.val(value);
};
})(this));
return setTimeout(function() {
var $target, value;
$target = $(e.currentTarget);
value = $target.val();
value = $.payment.formatCardNumber(value);
return $target.val(value);
});
};
formatCardNumber = function(e) {
......@@ -176,10 +188,14 @@
}
if (re.test(value)) {
e.preventDefault();
return $target.val(value + ' ' + digit);
return setTimeout(function() {
return $target.val(value + ' ' + digit);
});
} else if (re.test(value + digit)) {
e.preventDefault();
return $target.val(value + digit + ' ');
return setTimeout(function() {
return $target.val(value + digit + ' ');
});
}
};
......@@ -187,9 +203,6 @@
var $target, value;
$target = $(e.currentTarget);
value = $target.val();
if (e.meta) {
return;
}
if (e.which !== 8) {
return;
}
......@@ -198,13 +211,27 @@
}
if (/\d\s$/.test(value)) {
e.preventDefault();
return $target.val(value.replace(/\d\s$/, ''));
return setTimeout(function() {
return $target.val(value.replace(/\d\s$/, ''));
});
} else if (/\s\d?$/.test(value)) {
e.preventDefault();
return $target.val(value.replace(/\s\d?$/, ''));
return setTimeout(function() {
return $target.val(value.replace(/\s\d?$/, ''));
});
}
};
reFormatExpiry = function(e) {
return setTimeout(function() {
var $target, value;
$target = $(e.currentTarget);
value = $target.val();
value = $.payment.formatExpiry(value);
return $target.val(value);
});
};
formatExpiry = function(e) {
var $target, digit, val;
digit = String.fromCharCode(e.which);
......@@ -215,10 +242,14 @@
val = $target.val() + digit;
if (/^\d$/.test(val) && (val !== '0' && val !== '1')) {
e.preventDefault();
return $target.val("0" + val + " / ");
return setTimeout(function() {
return $target.val("0" + val + " / ");
});
} else if (/^\d\d$/.test(val)) {
e.preventDefault();
return $target.val("" + val + " / ");
return setTimeout(function() {
return $target.val("" + val + " / ");
});
}
};
......@@ -235,10 +266,10 @@
}
};
formatForwardSlash = function(e) {
var $target, slash, val;
slash = String.fromCharCode(e.which);
if (slash !== '/') {
formatForwardSlashAndSpace = function(e) {
var $target, val, which;
which = String.fromCharCode(e.which);
if (!(which === '/' || which === ' ')) {
return;
}
$target = $(e.currentTarget);
......@@ -250,9 +281,6 @@
formatBackExpiry = function(e) {
var $target, value;
if (e.meta) {
return;
}
$target = $(e.currentTarget);
value = $target.val();
if (e.which !== 8) {
......@@ -261,12 +289,11 @@
if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== value.length) {
return;
}
if (/\d(\s|\/)+$/.test(value)) {
e.preventDefault();
return $target.val(value.replace(/\d(\s|\/)*$/, ''));
} else if (/\s\/\s?\d?$/.test(value)) {
if (/\s\/\s\d?$/.test(value)) {
e.preventDefault();
return $target.val(value.replace(/\s\/\s?\d?$/, ''));
return setTimeout(function() {
return $target.val(value.replace(/\s\/\s\d?$/, ''));
});
}
};
......@@ -371,9 +398,11 @@
this.payment('restrictNumeric');
this.on('keypress', restrictExpiry);
this.on('keypress', formatExpiry);
this.on('keypress', formatForwardSlash);
this.on('keypress', formatForwardSlashAndSpace);
this.on('keypress', formatForwardExpiry);
this.on('keydown', formatBackExpiry);
this.on('change', reFormatExpiry);
this.on('input', reFormatExpiry);
return this;
};
......@@ -384,6 +413,9 @@
this.on('keydown', formatBackCardNumber);
this.on('keyup', setCardType);
this.on('paste', reFormatCardNumber);
this.on('change', reFormatCardNumber);
this.on('input', reFormatCardNumber);
this.on('input', setCardType);
return this;
};
......@@ -426,47 +458,51 @@
return (_ref = num.length, __indexOf.call(card.length, _ref) >= 0) && (card.luhn === false || luhnCheck(num));
};
$.payment.validateCardExpiry = (function(_this) {
return function(month, year) {
var currentTime, expiry, prefix, _ref;
if (typeof month === 'object' && 'month' in month) {
_ref = month, month = _ref.month, year = _ref.year;
}
if (!(month && year)) {
return false;
}
month = $.trim(month);
year = $.trim(year);
if (!/^\d+$/.test(month)) {
return false;
}
if (!/^\d+$/.test(year)) {
return false;
}
if (!(parseInt(month, 10) <= 12)) {
return false;
}
if (year.length === 2) {
prefix = (new Date).getFullYear();
prefix = prefix.toString().slice(0, 2);
year = prefix + year;
$.payment.validateCardExpiry = function(month, year) {
var currentTime, expiry, _ref;
if (typeof month === 'object' && 'month' in month) {
_ref = month, month = _ref.month, year = _ref.year;
}
if (!(month && year)) {
return false;
}
month = $.trim(month);
year = $.trim(year);
if (!/^\d+$/.test(month)) {
return false;
}
if (!/^\d+$/.test(year)) {
return false;
}
if (!((1 <= month && month <= 12))) {
return false;
}
if (year.length === 2) {
if (year < 70) {
year = "20" + year;
} else {
year = "19" + year;
}
expiry = new Date(year, month);
currentTime = new Date;
expiry.setMonth(expiry.getMonth() - 1);
expiry.setMonth(expiry.getMonth() + 1, 1);
return expiry > currentTime;
};
})(this);
}
if (year.length !== 4) {
return false;
}
expiry = new Date(year, month);
currentTime = new Date;
expiry.setMonth(expiry.getMonth() - 1);
expiry.setMonth(expiry.getMonth() + 1, 1);
return expiry > currentTime;
};
$.payment.validateCardCVC = function(cvc, type) {
var _ref, _ref1;
var card, _ref;
cvc = $.trim(cvc);
if (!/^\d+$/.test(cvc)) {
return false;
}
if (type) {
return _ref = cvc.length, __indexOf.call((_ref1 = cardFromType(type)) != null ? _ref1.cvcLength : void 0, _ref) >= 0;
card = cardFromType(type);
if (card != null) {
return _ref = cvc.length, __indexOf.call(card.cvcLength, _ref) >= 0;
} else {
return cvc.length >= 3 && cvc.length <= 4;
}
......@@ -488,16 +524,39 @@
}
upperLength = card.length[card.length.length - 1];
num = num.replace(/\D/g, '');
num = num.slice(0, +upperLength + 1 || 9e9);
num = num.slice(0, upperLength);
if (card.format.global) {
return (_ref = num.match(card.format)) != null ? _ref.join(' ') : void 0;
} else {
groups = card.format.exec(num);
if (groups != null) {
groups.shift();
if (groups == null) {
return;
}
return groups != null ? groups.join(' ') : void 0;
groups.shift();
groups = $.grep(groups, function(n) {
return n;
});
return groups.join(' ');
}
};
$.payment.formatExpiry = function(expiry) {
var mon, parts, sep, year;
parts = expiry.match(/^\D*(\d{1,2})(\D+)?(\d{1,4})?/);
if (!parts) {
return '';
}
mon = parts[1] || '';
sep = parts[2] || '';
year = parts[3] || '';
if (year.length > 0 || (sep.length > 0 && !(/\ \/?\ ?/.test(sep)))) {
sep = ' / ';
}
if (mon.length === 1 && (mon !== '0' && mon !== '1')) {
mon = "0" + mon;
sep = ' / ';
}
return mon + sep + year;
};
}).call(this);
......
......@@ -32,6 +32,6 @@
},
"dependencies": {
"jquery": "~2.1.1",
"jquery.payment": "~1.0.3"
"jquery.payment": "~1.1.3"
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment