card-rails 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +1 -0
- data/app/assets/javascripts/card.js +895 -0
- data/app/assets/stylesheets/card.css +432 -0
- data/card-rails.gemspec +23 -0
- data/lib/card-rails.rb +1 -0
- data/lib/card/rails.rb +7 -0
- data/lib/card/rails/engine.rb +6 -0
- data/lib/card/rails/version.rb +5 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 06aa1a85740dcd625c026d6dff6b1116fd5f71f7
|
4
|
+
data.tar.gz: ec96a8f99854ff6ac07e719eacd7f0db5e24ef04
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9d4ebfb8fb88e757bfe8a9ba6433eacb38b41f255256d4786d2eb8bc46f04af1f6fa1801b08a3c44d00d26a9154f81a8b20511ddee66b4eaef87358e64024676
|
7
|
+
data.tar.gz: a7e6ec4429f0a462cb012304c603c1fbebcfac66abc8b55b612fc8fe226310d9261fc58d4d4f6c52169487e091249e5799289f441f9c42fa082cd3769e5a3a4f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Railslauncher<railslauncher@gmail.com>
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Card::Rails
|
2
|
+
|
3
|
+
Rails asset pipeline integration for [Card](https://github.com/jessepollak/card)
|
4
|
+
|
5
|
+
Card version `0.1.1`
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'card-rails'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install card-rails
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
card-rails contains both css and js for card
|
24
|
+
|
25
|
+
Include card js in app/assets/javascripts/application.js
|
26
|
+
|
27
|
+
```javascript
|
28
|
+
//= require card
|
29
|
+
```
|
30
|
+
|
31
|
+
Include card css in app/assets/stylesheets/application.css
|
32
|
+
|
33
|
+
```css
|
34
|
+
/*
|
35
|
+
*= require card
|
36
|
+
*/
|
37
|
+
```
|
38
|
+
|
39
|
+
For information on how to use card please visit [https://github.com/jessepollak/card](https://github.com/jessepollak/card)
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,895 @@
|
|
1
|
+
!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){
|
2
|
+
// Generated by CoffeeScript 1.7.1
|
3
|
+
(function() {
|
4
|
+
var $, cardFromNumber, cardFromType, cards, defaultFormat, formatBackCardNumber, formatBackExpiry, formatCardNumber, formatExpiry, formatForwardExpiry, formatForwardSlashAndSpace, hasTextSelected, luhnCheck, reFormatCardNumber, reFormatExpiry, restrictCVC, restrictCardNumber, restrictExpiry, restrictNumeric, setCardType,
|
5
|
+
__slice = [].slice,
|
6
|
+
__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; };
|
7
|
+
|
8
|
+
$ = jQuery;
|
9
|
+
|
10
|
+
$.payment = {};
|
11
|
+
|
12
|
+
$.payment.fn = {};
|
13
|
+
|
14
|
+
$.fn.payment = function() {
|
15
|
+
var args, method;
|
16
|
+
method = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
17
|
+
return $.payment.fn[method].apply(this, args);
|
18
|
+
};
|
19
|
+
|
20
|
+
defaultFormat = /(\d{1,4})/g;
|
21
|
+
|
22
|
+
cards = [
|
23
|
+
{
|
24
|
+
type: 'visaelectron',
|
25
|
+
pattern: /^4(026|17500|405|508|844|91[37])/,
|
26
|
+
format: defaultFormat,
|
27
|
+
length: [16],
|
28
|
+
cvcLength: [3],
|
29
|
+
luhn: true
|
30
|
+
}, {
|
31
|
+
type: 'maestro',
|
32
|
+
pattern: /^(5(018|0[23]|[68])|6(39|7))/,
|
33
|
+
format: defaultFormat,
|
34
|
+
length: [12, 13, 14, 15, 16, 17, 18, 19],
|
35
|
+
cvcLength: [3],
|
36
|
+
luhn: true
|
37
|
+
}, {
|
38
|
+
type: 'forbrugsforeningen',
|
39
|
+
pattern: /^600/,
|
40
|
+
format: defaultFormat,
|
41
|
+
length: [16],
|
42
|
+
cvcLength: [3],
|
43
|
+
luhn: true
|
44
|
+
}, {
|
45
|
+
type: 'dankort',
|
46
|
+
pattern: /^5019/,
|
47
|
+
format: defaultFormat,
|
48
|
+
length: [16],
|
49
|
+
cvcLength: [3],
|
50
|
+
luhn: true
|
51
|
+
}, {
|
52
|
+
type: 'visa',
|
53
|
+
pattern: /^4/,
|
54
|
+
format: defaultFormat,
|
55
|
+
length: [13, 16],
|
56
|
+
cvcLength: [3],
|
57
|
+
luhn: true
|
58
|
+
}, {
|
59
|
+
type: 'mastercard',
|
60
|
+
pattern: /^5[0-5]/,
|
61
|
+
format: defaultFormat,
|
62
|
+
length: [16],
|
63
|
+
cvcLength: [3],
|
64
|
+
luhn: true
|
65
|
+
}, {
|
66
|
+
type: 'amex',
|
67
|
+
pattern: /^3[47]/,
|
68
|
+
format: /(\d{1,4})(\d{1,6})?(\d{1,5})?/,
|
69
|
+
length: [15],
|
70
|
+
cvcLength: [3, 4],
|
71
|
+
luhn: true
|
72
|
+
}, {
|
73
|
+
type: 'dinersclub',
|
74
|
+
pattern: /^3[0689]/,
|
75
|
+
format: defaultFormat,
|
76
|
+
length: [14],
|
77
|
+
cvcLength: [3],
|
78
|
+
luhn: true
|
79
|
+
}, {
|
80
|
+
type: 'discover',
|
81
|
+
pattern: /^6([045]|22)/,
|
82
|
+
format: defaultFormat,
|
83
|
+
length: [16],
|
84
|
+
cvcLength: [3],
|
85
|
+
luhn: true
|
86
|
+
}, {
|
87
|
+
type: 'unionpay',
|
88
|
+
pattern: /^(62|88)/,
|
89
|
+
format: defaultFormat,
|
90
|
+
length: [16, 17, 18, 19],
|
91
|
+
cvcLength: [3],
|
92
|
+
luhn: false
|
93
|
+
}, {
|
94
|
+
type: 'jcb',
|
95
|
+
pattern: /^35/,
|
96
|
+
format: defaultFormat,
|
97
|
+
length: [16],
|
98
|
+
cvcLength: [3],
|
99
|
+
luhn: true
|
100
|
+
}
|
101
|
+
];
|
102
|
+
|
103
|
+
cardFromNumber = function(num) {
|
104
|
+
var card, _i, _len;
|
105
|
+
num = (num + '').replace(/\D/g, '');
|
106
|
+
for (_i = 0, _len = cards.length; _i < _len; _i++) {
|
107
|
+
card = cards[_i];
|
108
|
+
if (card.pattern.test(num)) {
|
109
|
+
return card;
|
110
|
+
}
|
111
|
+
}
|
112
|
+
};
|
113
|
+
|
114
|
+
cardFromType = function(type) {
|
115
|
+
var card, _i, _len;
|
116
|
+
for (_i = 0, _len = cards.length; _i < _len; _i++) {
|
117
|
+
card = cards[_i];
|
118
|
+
if (card.type === type) {
|
119
|
+
return card;
|
120
|
+
}
|
121
|
+
}
|
122
|
+
};
|
123
|
+
|
124
|
+
luhnCheck = function(num) {
|
125
|
+
var digit, digits, odd, sum, _i, _len;
|
126
|
+
odd = true;
|
127
|
+
sum = 0;
|
128
|
+
digits = (num + '').split('').reverse();
|
129
|
+
for (_i = 0, _len = digits.length; _i < _len; _i++) {
|
130
|
+
digit = digits[_i];
|
131
|
+
digit = parseInt(digit, 10);
|
132
|
+
if ((odd = !odd)) {
|
133
|
+
digit *= 2;
|
134
|
+
}
|
135
|
+
if (digit > 9) {
|
136
|
+
digit -= 9;
|
137
|
+
}
|
138
|
+
sum += digit;
|
139
|
+
}
|
140
|
+
return sum % 10 === 0;
|
141
|
+
};
|
142
|
+
|
143
|
+
hasTextSelected = function($target) {
|
144
|
+
var _ref;
|
145
|
+
if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== $target.prop('selectionEnd')) {
|
146
|
+
return true;
|
147
|
+
}
|
148
|
+
if (typeof document !== "undefined" && document !== null ? (_ref = document.selection) != null ? typeof _ref.createRange === "function" ? _ref.createRange().text : void 0 : void 0 : void 0) {
|
149
|
+
return true;
|
150
|
+
}
|
151
|
+
return false;
|
152
|
+
};
|
153
|
+
|
154
|
+
reFormatCardNumber = function(e) {
|
155
|
+
return setTimeout(function() {
|
156
|
+
var $target, value;
|
157
|
+
$target = $(e.currentTarget);
|
158
|
+
value = $target.val();
|
159
|
+
value = $.payment.formatCardNumber(value);
|
160
|
+
return $target.val(value);
|
161
|
+
});
|
162
|
+
};
|
163
|
+
|
164
|
+
formatCardNumber = function(e) {
|
165
|
+
var $target, card, digit, length, re, upperLength, value;
|
166
|
+
digit = String.fromCharCode(e.which);
|
167
|
+
if (!/^\d+$/.test(digit)) {
|
168
|
+
return;
|
169
|
+
}
|
170
|
+
$target = $(e.currentTarget);
|
171
|
+
value = $target.val();
|
172
|
+
card = cardFromNumber(value + digit);
|
173
|
+
length = (value.replace(/\D/g, '') + digit).length;
|
174
|
+
upperLength = 16;
|
175
|
+
if (card) {
|
176
|
+
upperLength = card.length[card.length.length - 1];
|
177
|
+
}
|
178
|
+
if (length >= upperLength) {
|
179
|
+
return;
|
180
|
+
}
|
181
|
+
if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== value.length) {
|
182
|
+
return;
|
183
|
+
}
|
184
|
+
if (card && card.type === 'amex') {
|
185
|
+
re = /^(\d{4}|\d{4}\s\d{6})$/;
|
186
|
+
} else {
|
187
|
+
re = /(?:^|\s)(\d{4})$/;
|
188
|
+
}
|
189
|
+
if (re.test(value)) {
|
190
|
+
e.preventDefault();
|
191
|
+
return setTimeout(function() {
|
192
|
+
return $target.val(value + ' ' + digit);
|
193
|
+
});
|
194
|
+
} else if (re.test(value + digit)) {
|
195
|
+
e.preventDefault();
|
196
|
+
return setTimeout(function() {
|
197
|
+
return $target.val(value + digit + ' ');
|
198
|
+
});
|
199
|
+
}
|
200
|
+
};
|
201
|
+
|
202
|
+
formatBackCardNumber = function(e) {
|
203
|
+
var $target, value;
|
204
|
+
$target = $(e.currentTarget);
|
205
|
+
value = $target.val();
|
206
|
+
if (e.which !== 8) {
|
207
|
+
return;
|
208
|
+
}
|
209
|
+
if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== value.length) {
|
210
|
+
return;
|
211
|
+
}
|
212
|
+
if (/\d\s$/.test(value)) {
|
213
|
+
e.preventDefault();
|
214
|
+
return setTimeout(function() {
|
215
|
+
return $target.val(value.replace(/\d\s$/, ''));
|
216
|
+
});
|
217
|
+
} else if (/\s\d?$/.test(value)) {
|
218
|
+
e.preventDefault();
|
219
|
+
return setTimeout(function() {
|
220
|
+
return $target.val(value.replace(/\s\d?$/, ''));
|
221
|
+
});
|
222
|
+
}
|
223
|
+
};
|
224
|
+
|
225
|
+
reFormatExpiry = function(e) {
|
226
|
+
return setTimeout(function() {
|
227
|
+
var $target, value;
|
228
|
+
$target = $(e.currentTarget);
|
229
|
+
value = $target.val();
|
230
|
+
value = $.payment.formatExpiry(value);
|
231
|
+
return $target.val(value);
|
232
|
+
});
|
233
|
+
};
|
234
|
+
|
235
|
+
formatExpiry = function(e) {
|
236
|
+
var $target, digit, val;
|
237
|
+
digit = String.fromCharCode(e.which);
|
238
|
+
if (!/^\d+$/.test(digit)) {
|
239
|
+
return;
|
240
|
+
}
|
241
|
+
$target = $(e.currentTarget);
|
242
|
+
val = $target.val() + digit;
|
243
|
+
if (/^\d$/.test(val) && (val !== '0' && val !== '1')) {
|
244
|
+
e.preventDefault();
|
245
|
+
return setTimeout(function() {
|
246
|
+
return $target.val("0" + val + " / ");
|
247
|
+
});
|
248
|
+
} else if (/^\d\d$/.test(val)) {
|
249
|
+
e.preventDefault();
|
250
|
+
return setTimeout(function() {
|
251
|
+
return $target.val("" + val + " / ");
|
252
|
+
});
|
253
|
+
}
|
254
|
+
};
|
255
|
+
|
256
|
+
formatForwardExpiry = function(e) {
|
257
|
+
var $target, digit, val;
|
258
|
+
digit = String.fromCharCode(e.which);
|
259
|
+
if (!/^\d+$/.test(digit)) {
|
260
|
+
return;
|
261
|
+
}
|
262
|
+
$target = $(e.currentTarget);
|
263
|
+
val = $target.val();
|
264
|
+
if (/^\d\d$/.test(val)) {
|
265
|
+
return $target.val("" + val + " / ");
|
266
|
+
}
|
267
|
+
};
|
268
|
+
|
269
|
+
formatForwardSlashAndSpace = function(e) {
|
270
|
+
var $target, val, which;
|
271
|
+
which = String.fromCharCode(e.which);
|
272
|
+
if (!(which === '/' || which === ' ')) {
|
273
|
+
return;
|
274
|
+
}
|
275
|
+
$target = $(e.currentTarget);
|
276
|
+
val = $target.val();
|
277
|
+
if (/^\d$/.test(val) && val !== '0') {
|
278
|
+
return $target.val("0" + val + " / ");
|
279
|
+
}
|
280
|
+
};
|
281
|
+
|
282
|
+
formatBackExpiry = function(e) {
|
283
|
+
var $target, value;
|
284
|
+
$target = $(e.currentTarget);
|
285
|
+
value = $target.val();
|
286
|
+
if (e.which !== 8) {
|
287
|
+
return;
|
288
|
+
}
|
289
|
+
if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== value.length) {
|
290
|
+
return;
|
291
|
+
}
|
292
|
+
if (/\s\/\s\d?$/.test(value)) {
|
293
|
+
e.preventDefault();
|
294
|
+
return setTimeout(function() {
|
295
|
+
return $target.val(value.replace(/\s\/\s\d?$/, ''));
|
296
|
+
});
|
297
|
+
}
|
298
|
+
};
|
299
|
+
|
300
|
+
restrictNumeric = function(e) {
|
301
|
+
var input;
|
302
|
+
if (e.metaKey || e.ctrlKey) {
|
303
|
+
return true;
|
304
|
+
}
|
305
|
+
if (e.which === 32) {
|
306
|
+
return false;
|
307
|
+
}
|
308
|
+
if (e.which === 0) {
|
309
|
+
return true;
|
310
|
+
}
|
311
|
+
if (e.which < 33) {
|
312
|
+
return true;
|
313
|
+
}
|
314
|
+
input = String.fromCharCode(e.which);
|
315
|
+
return !!/[\d\s]/.test(input);
|
316
|
+
};
|
317
|
+
|
318
|
+
restrictCardNumber = function(e) {
|
319
|
+
var $target, card, digit, value;
|
320
|
+
$target = $(e.currentTarget);
|
321
|
+
digit = String.fromCharCode(e.which);
|
322
|
+
if (!/^\d+$/.test(digit)) {
|
323
|
+
return;
|
324
|
+
}
|
325
|
+
if (hasTextSelected($target)) {
|
326
|
+
return;
|
327
|
+
}
|
328
|
+
value = ($target.val() + digit).replace(/\D/g, '');
|
329
|
+
card = cardFromNumber(value);
|
330
|
+
if (card) {
|
331
|
+
return value.length <= card.length[card.length.length - 1];
|
332
|
+
} else {
|
333
|
+
return value.length <= 16;
|
334
|
+
}
|
335
|
+
};
|
336
|
+
|
337
|
+
restrictExpiry = function(e) {
|
338
|
+
var $target, digit, value;
|
339
|
+
$target = $(e.currentTarget);
|
340
|
+
digit = String.fromCharCode(e.which);
|
341
|
+
if (!/^\d+$/.test(digit)) {
|
342
|
+
return;
|
343
|
+
}
|
344
|
+
if (hasTextSelected($target)) {
|
345
|
+
return;
|
346
|
+
}
|
347
|
+
value = $target.val() + digit;
|
348
|
+
value = value.replace(/\D/g, '');
|
349
|
+
if (value.length > 6) {
|
350
|
+
return false;
|
351
|
+
}
|
352
|
+
};
|
353
|
+
|
354
|
+
restrictCVC = function(e) {
|
355
|
+
var $target, digit, val;
|
356
|
+
$target = $(e.currentTarget);
|
357
|
+
digit = String.fromCharCode(e.which);
|
358
|
+
if (!/^\d+$/.test(digit)) {
|
359
|
+
return;
|
360
|
+
}
|
361
|
+
if (hasTextSelected($target)) {
|
362
|
+
return;
|
363
|
+
}
|
364
|
+
val = $target.val() + digit;
|
365
|
+
return val.length <= 4;
|
366
|
+
};
|
367
|
+
|
368
|
+
setCardType = function(e) {
|
369
|
+
var $target, allTypes, card, cardType, val;
|
370
|
+
$target = $(e.currentTarget);
|
371
|
+
val = $target.val();
|
372
|
+
cardType = $.payment.cardType(val) || 'unknown';
|
373
|
+
if (!$target.hasClass(cardType)) {
|
374
|
+
allTypes = (function() {
|
375
|
+
var _i, _len, _results;
|
376
|
+
_results = [];
|
377
|
+
for (_i = 0, _len = cards.length; _i < _len; _i++) {
|
378
|
+
card = cards[_i];
|
379
|
+
_results.push(card.type);
|
380
|
+
}
|
381
|
+
return _results;
|
382
|
+
})();
|
383
|
+
$target.removeClass('unknown');
|
384
|
+
$target.removeClass(allTypes.join(' '));
|
385
|
+
$target.addClass(cardType);
|
386
|
+
$target.toggleClass('identified', cardType !== 'unknown');
|
387
|
+
return $target.trigger('payment.cardType', cardType);
|
388
|
+
}
|
389
|
+
};
|
390
|
+
|
391
|
+
$.payment.fn.formatCardCVC = function() {
|
392
|
+
this.payment('restrictNumeric');
|
393
|
+
this.on('keypress', restrictCVC);
|
394
|
+
return this;
|
395
|
+
};
|
396
|
+
|
397
|
+
$.payment.fn.formatCardExpiry = function() {
|
398
|
+
this.payment('restrictNumeric');
|
399
|
+
this.on('keypress', restrictExpiry);
|
400
|
+
this.on('keypress', formatExpiry);
|
401
|
+
this.on('keypress', formatForwardSlashAndSpace);
|
402
|
+
this.on('keypress', formatForwardExpiry);
|
403
|
+
this.on('keydown', formatBackExpiry);
|
404
|
+
this.on('change', reFormatExpiry);
|
405
|
+
this.on('input', reFormatExpiry);
|
406
|
+
return this;
|
407
|
+
};
|
408
|
+
|
409
|
+
$.payment.fn.formatCardNumber = function() {
|
410
|
+
this.payment('restrictNumeric');
|
411
|
+
this.on('keypress', restrictCardNumber);
|
412
|
+
this.on('keypress', formatCardNumber);
|
413
|
+
this.on('keydown', formatBackCardNumber);
|
414
|
+
this.on('keyup', setCardType);
|
415
|
+
this.on('paste', reFormatCardNumber);
|
416
|
+
this.on('change', reFormatCardNumber);
|
417
|
+
this.on('input', reFormatCardNumber);
|
418
|
+
this.on('input', setCardType);
|
419
|
+
return this;
|
420
|
+
};
|
421
|
+
|
422
|
+
$.payment.fn.restrictNumeric = function() {
|
423
|
+
this.on('keypress', restrictNumeric);
|
424
|
+
return this;
|
425
|
+
};
|
426
|
+
|
427
|
+
$.payment.fn.cardExpiryVal = function() {
|
428
|
+
return $.payment.cardExpiryVal($(this).val());
|
429
|
+
};
|
430
|
+
|
431
|
+
$.payment.cardExpiryVal = function(value) {
|
432
|
+
var month, prefix, year, _ref;
|
433
|
+
value = value.replace(/\s/g, '');
|
434
|
+
_ref = value.split('/', 2), month = _ref[0], year = _ref[1];
|
435
|
+
if ((year != null ? year.length : void 0) === 2 && /^\d+$/.test(year)) {
|
436
|
+
prefix = (new Date).getFullYear();
|
437
|
+
prefix = prefix.toString().slice(0, 2);
|
438
|
+
year = prefix + year;
|
439
|
+
}
|
440
|
+
month = parseInt(month, 10);
|
441
|
+
year = parseInt(year, 10);
|
442
|
+
return {
|
443
|
+
month: month,
|
444
|
+
year: year
|
445
|
+
};
|
446
|
+
};
|
447
|
+
|
448
|
+
$.payment.validateCardNumber = function(num) {
|
449
|
+
var card, _ref;
|
450
|
+
num = (num + '').replace(/\s+|-/g, '');
|
451
|
+
if (!/^\d+$/.test(num)) {
|
452
|
+
return false;
|
453
|
+
}
|
454
|
+
card = cardFromNumber(num);
|
455
|
+
if (!card) {
|
456
|
+
return false;
|
457
|
+
}
|
458
|
+
return (_ref = num.length, __indexOf.call(card.length, _ref) >= 0) && (card.luhn === false || luhnCheck(num));
|
459
|
+
};
|
460
|
+
|
461
|
+
$.payment.validateCardExpiry = function(month, year) {
|
462
|
+
var currentTime, expiry, _ref;
|
463
|
+
if (typeof month === 'object' && 'month' in month) {
|
464
|
+
_ref = month, month = _ref.month, year = _ref.year;
|
465
|
+
}
|
466
|
+
if (!(month && year)) {
|
467
|
+
return false;
|
468
|
+
}
|
469
|
+
month = $.trim(month);
|
470
|
+
year = $.trim(year);
|
471
|
+
if (!/^\d+$/.test(month)) {
|
472
|
+
return false;
|
473
|
+
}
|
474
|
+
if (!/^\d+$/.test(year)) {
|
475
|
+
return false;
|
476
|
+
}
|
477
|
+
if (!((1 <= month && month <= 12))) {
|
478
|
+
return false;
|
479
|
+
}
|
480
|
+
if (year.length === 2) {
|
481
|
+
if (year < 70) {
|
482
|
+
year = "20" + year;
|
483
|
+
} else {
|
484
|
+
year = "19" + year;
|
485
|
+
}
|
486
|
+
}
|
487
|
+
if (year.length !== 4) {
|
488
|
+
return false;
|
489
|
+
}
|
490
|
+
expiry = new Date(year, month);
|
491
|
+
currentTime = new Date;
|
492
|
+
expiry.setMonth(expiry.getMonth() - 1);
|
493
|
+
expiry.setMonth(expiry.getMonth() + 1, 1);
|
494
|
+
return expiry > currentTime;
|
495
|
+
};
|
496
|
+
|
497
|
+
$.payment.validateCardCVC = function(cvc, type) {
|
498
|
+
var card, _ref;
|
499
|
+
cvc = $.trim(cvc);
|
500
|
+
if (!/^\d+$/.test(cvc)) {
|
501
|
+
return false;
|
502
|
+
}
|
503
|
+
card = cardFromType(type);
|
504
|
+
if (card != null) {
|
505
|
+
return _ref = cvc.length, __indexOf.call(card.cvcLength, _ref) >= 0;
|
506
|
+
} else {
|
507
|
+
return cvc.length >= 3 && cvc.length <= 4;
|
508
|
+
}
|
509
|
+
};
|
510
|
+
|
511
|
+
$.payment.cardType = function(num) {
|
512
|
+
var _ref;
|
513
|
+
if (!num) {
|
514
|
+
return null;
|
515
|
+
}
|
516
|
+
return ((_ref = cardFromNumber(num)) != null ? _ref.type : void 0) || null;
|
517
|
+
};
|
518
|
+
|
519
|
+
$.payment.formatCardNumber = function(num) {
|
520
|
+
var card, groups, upperLength, _ref;
|
521
|
+
card = cardFromNumber(num);
|
522
|
+
if (!card) {
|
523
|
+
return num;
|
524
|
+
}
|
525
|
+
upperLength = card.length[card.length.length - 1];
|
526
|
+
num = num.replace(/\D/g, '');
|
527
|
+
num = num.slice(0, upperLength);
|
528
|
+
if (card.format.global) {
|
529
|
+
return (_ref = num.match(card.format)) != null ? _ref.join(' ') : void 0;
|
530
|
+
} else {
|
531
|
+
groups = card.format.exec(num);
|
532
|
+
if (groups == null) {
|
533
|
+
return;
|
534
|
+
}
|
535
|
+
groups.shift();
|
536
|
+
groups = $.grep(groups, function(n) {
|
537
|
+
return n;
|
538
|
+
});
|
539
|
+
return groups.join(' ');
|
540
|
+
}
|
541
|
+
};
|
542
|
+
|
543
|
+
$.payment.formatExpiry = function(expiry) {
|
544
|
+
var mon, parts, sep, year;
|
545
|
+
parts = expiry.match(/^\D*(\d{1,2})(\D+)?(\d{1,4})?/);
|
546
|
+
if (!parts) {
|
547
|
+
return '';
|
548
|
+
}
|
549
|
+
mon = parts[1] || '';
|
550
|
+
sep = parts[2] || '';
|
551
|
+
year = parts[3] || '';
|
552
|
+
if (year.length > 0 || (sep.length > 0 && !(/\ \/?\ ?/.test(sep)))) {
|
553
|
+
sep = ' / ';
|
554
|
+
}
|
555
|
+
if (mon.length === 1 && (mon !== '0' && mon !== '1')) {
|
556
|
+
mon = "0" + mon;
|
557
|
+
sep = ' / ';
|
558
|
+
}
|
559
|
+
return mon + sep + year;
|
560
|
+
};
|
561
|
+
|
562
|
+
}).call(this);
|
563
|
+
|
564
|
+
},{}],2:[function(_dereq_,module,exports){
|
565
|
+
var $, Card,
|
566
|
+
__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; },
|
567
|
+
__slice = [].slice;
|
568
|
+
|
569
|
+
_dereq_('jquery.payment');
|
570
|
+
|
571
|
+
$ = jQuery;
|
572
|
+
|
573
|
+
$.card = {};
|
574
|
+
|
575
|
+
$.card.fn = {};
|
576
|
+
|
577
|
+
$.fn.card = function(opts) {
|
578
|
+
return $.card.fn.construct.apply(this, opts);
|
579
|
+
};
|
580
|
+
|
581
|
+
Card = (function() {
|
582
|
+
Card.prototype.cardTemplate = "<div class=\"card-container\">\n <div class=\"card\">\n <div class=\"front\">\n <div class=\"card-logo visa\">visa</div>\n <div class=\"card-logo mastercard\">MasterCard</div>\n <div class=\"card-logo amex\"></div>\n <div class=\"card-logo discover\">discover</div>\n <div class=\"lower\">\n <div class=\"shiny\"></div>\n <div class=\"cvc display\">{{cvc}}</div>\n <div class=\"number display\">{{number}}</div>\n <div class=\"name display\">{{name}}</div>\n <div class=\"expiry display\" data-before=\"{{monthYear}}\" data-after=\"{{validDate}}\">{{expiry}}</div>\n </div>\n </div>\n <div class=\"back\">\n <div class=\"bar\"></div>\n <div class=\"cvc display\">{{cvc}}</div>\n <div class=\"shiny\"></div>\n </div>\n </div>\n</div>";
|
583
|
+
|
584
|
+
Card.prototype.template = function(tpl, data) {
|
585
|
+
return tpl.replace(/\{\{(.*?)\}\}/g, function(match, key, str) {
|
586
|
+
return data[key];
|
587
|
+
});
|
588
|
+
};
|
589
|
+
|
590
|
+
Card.prototype.cardTypes = ['maestro', 'dinersclub', 'laser', 'jcb', 'unionpay', 'discover', 'mastercard', 'amex', 'visa'];
|
591
|
+
|
592
|
+
Card.prototype.defaults = {
|
593
|
+
formatting: true,
|
594
|
+
formSelectors: {
|
595
|
+
numberInput: 'input[name="number"]',
|
596
|
+
expiryInput: 'input[name="expiry"]',
|
597
|
+
cvcInput: 'input[name="cvc"]',
|
598
|
+
nameInput: 'input[name="name"]'
|
599
|
+
},
|
600
|
+
cardSelectors: {
|
601
|
+
cardContainer: '.card-container',
|
602
|
+
card: '.card',
|
603
|
+
numberDisplay: '.number',
|
604
|
+
expiryDisplay: '.expiry',
|
605
|
+
cvcDisplay: '.cvc',
|
606
|
+
nameDisplay: '.name'
|
607
|
+
},
|
608
|
+
messages: {
|
609
|
+
validDate: 'valid\nthru',
|
610
|
+
monthYear: 'month/year'
|
611
|
+
},
|
612
|
+
values: {
|
613
|
+
number: '•••• •••• •••• ••••',
|
614
|
+
cvc: '•••',
|
615
|
+
expiry: '••/••',
|
616
|
+
name: 'Full Name'
|
617
|
+
},
|
618
|
+
classes: {
|
619
|
+
valid: 'card-valid',
|
620
|
+
invalid: 'card-invalid'
|
621
|
+
}
|
622
|
+
};
|
623
|
+
|
624
|
+
function Card(el, opts) {
|
625
|
+
this.options = $.extend(true, {}, this.defaults, opts);
|
626
|
+
$.extend(this.options.messages, $.card.messages);
|
627
|
+
$.extend(this.options.values, $.card.values);
|
628
|
+
this.$el = $(el);
|
629
|
+
if (!this.options.container) {
|
630
|
+
console.log("Please provide a container");
|
631
|
+
return;
|
632
|
+
}
|
633
|
+
this.$container = $(this.options.container);
|
634
|
+
this.render();
|
635
|
+
this.attachHandlers();
|
636
|
+
this.handleInitialValues();
|
637
|
+
}
|
638
|
+
|
639
|
+
Card.prototype.render = function() {
|
640
|
+
var baseWidth, ua;
|
641
|
+
this.$container.append(this.template(this.cardTemplate, $.extend({}, this.options.messages, this.options.values)));
|
642
|
+
$.each(this.options.cardSelectors, (function(_this) {
|
643
|
+
return function(name, selector) {
|
644
|
+
return _this["$" + name] = _this.$container.find(selector);
|
645
|
+
};
|
646
|
+
})(this));
|
647
|
+
$.each(this.options.formSelectors, (function(_this) {
|
648
|
+
return function(name, selector) {
|
649
|
+
var obj;
|
650
|
+
if (_this.options[name]) {
|
651
|
+
obj = $(_this.options[name]);
|
652
|
+
} else {
|
653
|
+
obj = _this.$el.find(selector);
|
654
|
+
}
|
655
|
+
if (!obj.length) {
|
656
|
+
console.error("Card can't find a " + name + " in your form.");
|
657
|
+
}
|
658
|
+
return _this["$" + name] = obj;
|
659
|
+
};
|
660
|
+
})(this));
|
661
|
+
if (this.options.formatting) {
|
662
|
+
this.$numberInput.payment('formatCardNumber');
|
663
|
+
this.$cvcInput.payment('formatCardCVC');
|
664
|
+
if (this.$expiryInput.length === 1) {
|
665
|
+
this.$expiryInput.payment('formatCardExpiry');
|
666
|
+
}
|
667
|
+
}
|
668
|
+
if (this.options.width) {
|
669
|
+
baseWidth = parseInt(this.$cardContainer.css('width'));
|
670
|
+
this.$cardContainer.css("transform", "scale(" + (this.options.width / baseWidth) + ")");
|
671
|
+
}
|
672
|
+
if (typeof navigator !== "undefined" && navigator !== null ? navigator.userAgent : void 0) {
|
673
|
+
ua = navigator.userAgent.toLowerCase();
|
674
|
+
if (ua.indexOf('safari') !== -1 && ua.indexOf('chrome') === -1) {
|
675
|
+
this.$card.addClass('safari');
|
676
|
+
}
|
677
|
+
}
|
678
|
+
if (new Function("/*@cc_on return @_jscript_version; @*/")()) {
|
679
|
+
return this.$card.addClass('ie-10');
|
680
|
+
}
|
681
|
+
};
|
682
|
+
|
683
|
+
Card.prototype.attachHandlers = function() {
|
684
|
+
var expiryFilters;
|
685
|
+
this.$numberInput.bindVal(this.$numberDisplay, {
|
686
|
+
fill: false,
|
687
|
+
filters: this.validToggler('cardNumber')
|
688
|
+
}).on('payment.cardType', this.handle('setCardType'));
|
689
|
+
expiryFilters = [
|
690
|
+
function(val) {
|
691
|
+
return val.replace(/(\s+)/g, '');
|
692
|
+
}
|
693
|
+
];
|
694
|
+
if (this.$expiryInput.length === 1) {
|
695
|
+
expiryFilters.push(this.validToggler('cardExpiry'));
|
696
|
+
}
|
697
|
+
this.$expiryInput.bindVal(this.$expiryDisplay, {
|
698
|
+
join: function(text) {
|
699
|
+
if (text[0].length === 2 || text[1]) {
|
700
|
+
return "/";
|
701
|
+
} else {
|
702
|
+
return "";
|
703
|
+
}
|
704
|
+
},
|
705
|
+
filters: expiryFilters
|
706
|
+
});
|
707
|
+
this.$cvcInput.bindVal(this.$cvcDisplay, {
|
708
|
+
filters: this.validToggler('cardCVC')
|
709
|
+
}).on('focus', this.handle('flipCard')).on('blur', this.handle('flipCard'));
|
710
|
+
return this.$nameInput.bindVal(this.$nameDisplay, {
|
711
|
+
fill: false,
|
712
|
+
filters: this.validToggler('cardHolderName'),
|
713
|
+
join: ' '
|
714
|
+
}).on('keydown', this.handle('captureName'));
|
715
|
+
};
|
716
|
+
|
717
|
+
Card.prototype.handleInitialValues = function() {
|
718
|
+
return $.each(this.options.formSelectors, (function(_this) {
|
719
|
+
return function(name, selector) {
|
720
|
+
var el;
|
721
|
+
el = _this["$" + name];
|
722
|
+
if (el.val()) {
|
723
|
+
el.trigger('paste');
|
724
|
+
return setTimeout(function() {
|
725
|
+
return el.trigger('keyup');
|
726
|
+
});
|
727
|
+
}
|
728
|
+
};
|
729
|
+
})(this));
|
730
|
+
};
|
731
|
+
|
732
|
+
Card.prototype.handle = function(fn) {
|
733
|
+
return (function(_this) {
|
734
|
+
return function(e) {
|
735
|
+
var $el, args;
|
736
|
+
$el = $(e.currentTarget);
|
737
|
+
args = Array.prototype.slice.call(arguments);
|
738
|
+
args.unshift($el);
|
739
|
+
return _this.handlers[fn].apply(_this, args);
|
740
|
+
};
|
741
|
+
})(this);
|
742
|
+
};
|
743
|
+
|
744
|
+
Card.prototype.validToggler = function(validatorName) {
|
745
|
+
var isValid;
|
746
|
+
if (validatorName === "cardExpiry") {
|
747
|
+
isValid = function(val) {
|
748
|
+
var objVal;
|
749
|
+
objVal = $.payment.cardExpiryVal(val);
|
750
|
+
return $.payment.validateCardExpiry(objVal.month, objVal.year);
|
751
|
+
};
|
752
|
+
} else if (validatorName === "cardCVC") {
|
753
|
+
isValid = (function(_this) {
|
754
|
+
return function(val) {
|
755
|
+
return $.payment.validateCardCVC(val, _this.cardType);
|
756
|
+
};
|
757
|
+
})(this);
|
758
|
+
} else if (validatorName === "cardNumber") {
|
759
|
+
isValid = function(val) {
|
760
|
+
return $.payment.validateCardNumber(val);
|
761
|
+
};
|
762
|
+
} else if (validatorName === "cardHolderName") {
|
763
|
+
isValid = function(val) {
|
764
|
+
return val !== "";
|
765
|
+
};
|
766
|
+
}
|
767
|
+
return (function(_this) {
|
768
|
+
return function(val, $in, $out) {
|
769
|
+
var result;
|
770
|
+
result = isValid(val);
|
771
|
+
_this.toggleValidClass($in, result);
|
772
|
+
_this.toggleValidClass($out, result);
|
773
|
+
return val;
|
774
|
+
};
|
775
|
+
})(this);
|
776
|
+
};
|
777
|
+
|
778
|
+
Card.prototype.toggleValidClass = function(el, test) {
|
779
|
+
el.toggleClass(this.options.classes.valid, test);
|
780
|
+
return el.toggleClass(this.options.classes.invalid, !test);
|
781
|
+
};
|
782
|
+
|
783
|
+
Card.prototype.handlers = {
|
784
|
+
setCardType: function($el, e, cardType) {
|
785
|
+
if (!this.$card.hasClass(cardType)) {
|
786
|
+
this.$card.removeClass('unknown');
|
787
|
+
this.$card.removeClass(this.cardTypes.join(' '));
|
788
|
+
this.$card.addClass(cardType);
|
789
|
+
this.$card.toggleClass('identified', cardType !== 'unknown');
|
790
|
+
return this.cardType = cardType;
|
791
|
+
}
|
792
|
+
},
|
793
|
+
flipCard: function($el, e) {
|
794
|
+
return this.$card.toggleClass('flipped');
|
795
|
+
},
|
796
|
+
captureName: function($el, e) {
|
797
|
+
var allowedSymbols, banKeyCodes, keyCode;
|
798
|
+
keyCode = e.which || e.keyCode;
|
799
|
+
banKeyCodes = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 106, 107, 109, 110, 111, 186, 187, 188, 189, 190, 191, 192, 219, 220, 221, 222];
|
800
|
+
allowedSymbols = [189, 109, 190, 110, 222];
|
801
|
+
if (banKeyCodes.indexOf(keyCode) !== -1 && !(!e.shiftKey && __indexOf.call(allowedSymbols, keyCode) >= 0)) {
|
802
|
+
return e.preventDefault();
|
803
|
+
}
|
804
|
+
}
|
805
|
+
};
|
806
|
+
|
807
|
+
$.fn.bindVal = function(out, opts) {
|
808
|
+
var $el, i, joiner, o, outDefaults;
|
809
|
+
if (opts == null) {
|
810
|
+
opts = {};
|
811
|
+
}
|
812
|
+
opts.fill = opts.fill || false;
|
813
|
+
opts.filters = opts.filters || [];
|
814
|
+
if (!(opts.filters instanceof Array)) {
|
815
|
+
opts.filters = [opts.filters];
|
816
|
+
}
|
817
|
+
opts.join = opts.join || "";
|
818
|
+
if (!(typeof opts.join === "function")) {
|
819
|
+
joiner = opts.join;
|
820
|
+
opts.join = function() {
|
821
|
+
return joiner;
|
822
|
+
};
|
823
|
+
}
|
824
|
+
$el = $(this);
|
825
|
+
outDefaults = (function() {
|
826
|
+
var _i, _len, _results;
|
827
|
+
_results = [];
|
828
|
+
for (i = _i = 0, _len = out.length; _i < _len; i = ++_i) {
|
829
|
+
o = out[i];
|
830
|
+
_results.push(out.eq(i).text());
|
831
|
+
}
|
832
|
+
return _results;
|
833
|
+
})();
|
834
|
+
$el.on('focus', function() {
|
835
|
+
return out.addClass('focused');
|
836
|
+
});
|
837
|
+
$el.on('blur', function() {
|
838
|
+
return out.removeClass('focused');
|
839
|
+
});
|
840
|
+
$el.on('keyup change paste', function(e) {
|
841
|
+
var filter, join, outVal, val, _i, _j, _len, _len1, _ref, _results;
|
842
|
+
val = $el.map(function() {
|
843
|
+
return $(this).val();
|
844
|
+
}).get();
|
845
|
+
join = opts.join(val);
|
846
|
+
val = val.join(join);
|
847
|
+
if (val === join) {
|
848
|
+
val = "";
|
849
|
+
}
|
850
|
+
_ref = opts.filters;
|
851
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
852
|
+
filter = _ref[_i];
|
853
|
+
val = filter(val, $el, out);
|
854
|
+
}
|
855
|
+
_results = [];
|
856
|
+
for (i = _j = 0, _len1 = out.length; _j < _len1; i = ++_j) {
|
857
|
+
o = out[i];
|
858
|
+
if (opts.fill) {
|
859
|
+
outVal = val + outDefaults[i].substring(val.length);
|
860
|
+
} else {
|
861
|
+
outVal = val || outDefaults[i];
|
862
|
+
}
|
863
|
+
_results.push(out.eq(i).text(outVal));
|
864
|
+
}
|
865
|
+
return _results;
|
866
|
+
});
|
867
|
+
return $el;
|
868
|
+
};
|
869
|
+
|
870
|
+
return Card;
|
871
|
+
|
872
|
+
})();
|
873
|
+
|
874
|
+
$.fn.extend({
|
875
|
+
card: function() {
|
876
|
+
var args, option;
|
877
|
+
option = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
878
|
+
return this.each(function() {
|
879
|
+
var $this, data;
|
880
|
+
$this = $(this);
|
881
|
+
data = $this.data('card');
|
882
|
+
if (!data) {
|
883
|
+
$this.data('card', (data = new Card(this, option)));
|
884
|
+
}
|
885
|
+
if (typeof option === 'string') {
|
886
|
+
return data[option].apply(data, args);
|
887
|
+
}
|
888
|
+
});
|
889
|
+
}
|
890
|
+
});
|
891
|
+
|
892
|
+
|
893
|
+
},{"jquery.payment":1}]},{},[2])
|
894
|
+
(2)
|
895
|
+
});
|