spree_zaez_komerci 3.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +11 -0
  5. data/Gemfile +9 -0
  6. data/Guardfile +90 -0
  7. data/LICENSE +26 -0
  8. data/README.md +52 -0
  9. data/Rakefile +21 -0
  10. data/app/assets/images/rede-credit-cards/rede-dinersclub.png +0 -0
  11. data/app/assets/images/rede-credit-cards/rede-hipercard.png +0 -0
  12. data/app/assets/images/rede-credit-cards/rede-jcb.png +0 -0
  13. data/app/assets/images/rede-credit-cards/rede-mastercard.png +0 -0
  14. data/app/assets/images/rede-credit-cards/rede-visa.png +0 -0
  15. data/app/assets/javascripts/spree/backend/spree_zaez_komerci.js +1 -0
  16. data/app/assets/javascripts/spree/frontend/app/komerci_credit_card.js.coffee +26 -0
  17. data/app/assets/javascripts/spree/frontend/spree_zaez_komerci.js +1 -0
  18. data/app/assets/stylesheets/spree/frontend/spree_zaez_komerci.css +7 -0
  19. data/app/controllers/spree/admin/komerci_settings_controller.rb +20 -0
  20. data/app/models/spree/credit_card_decorator.rb +7 -0
  21. data/app/models/spree/komerci_transaction.rb +8 -0
  22. data/app/models/spree/payment/gateway_options_decorator.rb +14 -0
  23. data/app/models/spree/payment_method/komerci.rb +250 -0
  24. data/app/overrides/spree/admin/shared/sub_menu/_configuration/add_komerci_settings_to_configuration_tab.html.erb.deface +2 -0
  25. data/app/views/spree/admin/komerci_settings/edit.html.erb +67 -0
  26. data/app/views/spree/admin/payments/source_forms/_komerci.html.erb +62 -0
  27. data/app/views/spree/admin/payments/source_views/_komerci.html.erb +33 -0
  28. data/app/views/spree/checkout/payment/_komerci.html.erb +62 -0
  29. data/bin/rails +7 -0
  30. data/config/locales/en.yml +31 -0
  31. data/config/locales/pt-br.yml +32 -0
  32. data/config/routes.rb +5 -0
  33. data/db/migrate/20160630132716_add_portions_to_spree_payments.rb +5 -0
  34. data/db/migrate/20160630161016_create_spree_komerci_transaction.rb +14 -0
  35. data/db/migrate/20160701184408_add_payment_id_to_spree_komerci_transactions.rb +5 -0
  36. data/db/migrate/20160704120859_add_total_to_spree_komerci_transactions.rb +5 -0
  37. data/lib/generators/spree_zaez_komerci/install/install_generator.rb +30 -0
  38. data/lib/spree/komerci_configuration.rb +190 -0
  39. data/lib/spree_zaez_komerci/engine.rb +30 -0
  40. data/lib/spree_zaez_komerci/factories.rb +30 -0
  41. data/lib/spree_zaez_komerci.rb +5 -0
  42. data/spec/features/admin/komerci_actions_spec.rb +80 -0
  43. data/spec/features/admin/komerci_settings_spec.rb +77 -0
  44. data/spec/features/checkout_with_komerci_spec.rb +75 -0
  45. data/spec/fixtures/authorize_error.txt +14 -0
  46. data/spec/fixtures/authorize_success.txt +14 -0
  47. data/spec/fixtures/conf_authorize_error.txt +7 -0
  48. data/spec/fixtures/conf_authorize_success.txt +7 -0
  49. data/spec/fixtures/error.txt +1 -0
  50. data/spec/fixtures/void_error.txt +7 -0
  51. data/spec/fixtures/void_success.txt +7 -0
  52. data/spec/lib/spree/komerci_configuration_spec.rb +82 -0
  53. data/spec/models/spree/payment_method/komerci_spec.rb +206 -0
  54. data/spec/spec_helper.rb +99 -0
  55. data/spec/support/capybara_login.rb +11 -0
  56. data/spec/support/shared_contexts/checkout_setup.rb +9 -0
  57. data/spree_zaez_komerci.gemspec +42 -0
  58. data/vendor/assets/javascripts/jquery.payment.js +612 -0
  59. metadata +423 -0
@@ -0,0 +1,612 @@
1
+ // Generated by CoffeeScript 1.7.1
2
+ (function() {
3
+ var cardFromNumber, cardFromType, cards, defaultFormat, formatBackCardNumber, formatBackExpiry, formatCardNumber, formatExpiry, formatForwardExpiry, formatForwardSlashAndSpace, hasTextSelected, luhnCheck, reFormatCVC, reFormatCardNumber, reFormatExpiry, reFormatNumeric, restrictCVC, restrictCardNumber, restrictExpiry, restrictNumeric, setCardType,
4
+ __slice = [].slice,
5
+ __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; };
6
+
7
+ $.payment = {};
8
+
9
+ $.payment.fn = {};
10
+
11
+ $.fn.payment = function() {
12
+ var args, method;
13
+ method = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
14
+ return $.payment.fn[method].apply(this, args);
15
+ };
16
+
17
+ defaultFormat = /(\d{1,4})/g;
18
+
19
+ $.payment.cards = cards = [
20
+ {
21
+ type: 'visaelectron',
22
+ pattern: /^4(026|17500|405|508|844|91[37])/,
23
+ format: defaultFormat,
24
+ length: [16],
25
+ cvcLength: [3],
26
+ luhn: true
27
+ }, {
28
+ type: 'maestro',
29
+ pattern: /^(5(018|0[23]|[68])|6(39|7))/,
30
+ format: defaultFormat,
31
+ length: [12, 13, 14, 15, 16, 17, 18, 19],
32
+ cvcLength: [3],
33
+ luhn: true
34
+ }, {
35
+ type: 'forbrugsforeningen',
36
+ pattern: /^600/,
37
+ format: defaultFormat,
38
+ length: [16],
39
+ cvcLength: [3],
40
+ luhn: true
41
+ }, {
42
+ type: 'dankort',
43
+ pattern: /^5019/,
44
+ format: defaultFormat,
45
+ length: [16],
46
+ cvcLength: [3],
47
+ luhn: true
48
+ }, {
49
+ type: 'visa',
50
+ pattern: /^4/,
51
+ format: defaultFormat,
52
+ length: [13, 16],
53
+ cvcLength: [3],
54
+ luhn: true
55
+ }, {
56
+ type: 'mastercard',
57
+ pattern: /^(5[1-5]|2[2-7])/,
58
+ format: defaultFormat,
59
+ length: [16],
60
+ cvcLength: [3],
61
+ luhn: true
62
+ }, {
63
+ type: 'amex',
64
+ pattern: /^3[47]/,
65
+ format: /(\d{1,4})(\d{1,6})?(\d{1,5})?/,
66
+ length: [15],
67
+ cvcLength: [3, 4],
68
+ luhn: true
69
+ }, {
70
+ type: 'dinersclub',
71
+ pattern: /^(301|305|36|38(?![384100|384100|384160]))/,
72
+ format: /(\d{1,4})(\d{1,6})?(\d{1,4})?/,
73
+ length: [14],
74
+ cvcLength: [3],
75
+ luhn: true
76
+ }, {
77
+ type: 'discover',
78
+ pattern: /^6([045]|22)/,
79
+ format: defaultFormat,
80
+ length: [16],
81
+ cvcLength: [3],
82
+ luhn: true
83
+ }, {
84
+ type: 'unionpay',
85
+ pattern: /^(62|88)/,
86
+ format: defaultFormat,
87
+ length: [16, 17, 18, 19],
88
+ cvcLength: [3],
89
+ luhn: false
90
+ }, {
91
+ type: 'jcb',
92
+ pattern: /^35/,
93
+ format: defaultFormat,
94
+ length: [16],
95
+ cvcLength: [3],
96
+ luhn: true
97
+ }, {
98
+ type: 'elo',
99
+ pattern: /^(401178|401179|431274|438935|451416|457393|457631|457632|504175|627780|636297|636369|(506699|5067[0-6]\d|50677[0-8])|(50900\d|5090[1-9]\d|509[1-9]\d{2})|65003[1-3]|(65003[5-9]|65004\d|65005[0-1])|(65040[5-9]|6504[1-3]\d)|(65048[5-9]|65049\d|6505[0-2]\d|65053[0-8])|(65054[1-9]|6505[5-8]\d|65059[0-8])|(65070\d|65071[0-8])|65072[0-7]|(65090[1-9]|65091\d|650920)|(65165[2-9]|6516[6-7]\d)|(65500\d|65501\d)|(65502[1-9]|6550[3-4]\d|65505[0-8]))[0-9]{10,12}/,
100
+ format: defaultFormat,
101
+ length: [16],
102
+ cvcLength: [3],
103
+ luhn: true
104
+ }, {
105
+ type: 'aura',
106
+ pattern: /^(50[0-9])/,
107
+ format: defaultFormat,
108
+ length: [16, 19],
109
+ cvcLength: [3],
110
+ luhn: true
111
+ }, {
112
+ type: 'hipercard',
113
+ pattern: /^(384100|384140|384160|606282|637095|637568|637599|637609|637612)/,
114
+ format: defaultFormat,
115
+ length: [13, 16, 19],
116
+ cvcLength: [3],
117
+ luhn: true
118
+ }
119
+ ];
120
+
121
+ cardFromNumber = function(num) {
122
+ var card, _i, _len;
123
+ num = (num + '').replace(/\D/g, '');
124
+ for (_i = 0, _len = cards.length; _i < _len; _i++) {
125
+ card = cards[_i];
126
+ if (card.pattern.test(num)) {
127
+ return card;
128
+ }
129
+ }
130
+ };
131
+
132
+ cardFromType = function(type) {
133
+ var card, _i, _len;
134
+ for (_i = 0, _len = cards.length; _i < _len; _i++) {
135
+ card = cards[_i];
136
+ if (card.type === type) {
137
+ return card;
138
+ }
139
+ }
140
+ };
141
+
142
+ luhnCheck = function(num) {
143
+ var digit, digits, odd, sum, _i, _len;
144
+ odd = true;
145
+ sum = 0;
146
+ digits = (num + '').split('').reverse();
147
+ for (_i = 0, _len = digits.length; _i < _len; _i++) {
148
+ digit = digits[_i];
149
+ digit = parseInt(digit, 10);
150
+ if ((odd = !odd)) {
151
+ digit *= 2;
152
+ }
153
+ if (digit > 9) {
154
+ digit -= 9;
155
+ }
156
+ sum += digit;
157
+ }
158
+ return sum % 10 === 0;
159
+ };
160
+
161
+ hasTextSelected = function($target) {
162
+ var _ref;
163
+ if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== $target.prop('selectionEnd')) {
164
+ return true;
165
+ }
166
+ if ((typeof document !== "undefined" && document !== null ? (_ref = document.selection) != null ? _ref.createRange : void 0 : void 0) != null) {
167
+ if (document.selection.createRange().text) {
168
+ return true;
169
+ }
170
+ }
171
+ return false;
172
+ };
173
+
174
+ reFormatNumeric = function(e) {
175
+ return setTimeout(function() {
176
+ var $target, value;
177
+ $target = $(e.currentTarget);
178
+ value = $target.val();
179
+ value = value.replace(/\D/g, '');
180
+ return $target.val(value);
181
+ });
182
+ };
183
+
184
+ reFormatCardNumber = function(e) {
185
+ return setTimeout(function() {
186
+ var $target, value;
187
+ $target = $(e.currentTarget);
188
+ value = $target.val();
189
+ value = $.payment.formatCardNumber(value);
190
+ return $target.val(value);
191
+ });
192
+ };
193
+
194
+ formatCardNumber = function(e) {
195
+ var $target, card, digit, length, re, upperLength, value;
196
+ digit = String.fromCharCode(e.which);
197
+ if (!/^\d+$/.test(digit)) {
198
+ return;
199
+ }
200
+ $target = $(e.currentTarget);
201
+ value = $target.val();
202
+ card = cardFromNumber(value + digit);
203
+ length = (value.replace(/\D/g, '') + digit).length;
204
+ upperLength = 16;
205
+ if (card) {
206
+ upperLength = card.length[card.length.length - 1];
207
+ }
208
+ if (length >= upperLength) {
209
+ return;
210
+ }
211
+ if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== value.length) {
212
+ return;
213
+ }
214
+ if (card && card.type === 'amex') {
215
+ re = /^(\d{4}|\d{4}\s\d{6})$/;
216
+ } else {
217
+ re = /(?:^|\s)(\d{4})$/;
218
+ }
219
+ if (re.test(value)) {
220
+ e.preventDefault();
221
+ return setTimeout(function() {
222
+ return $target.val(value + ' ' + digit);
223
+ });
224
+ } else if (re.test(value + digit)) {
225
+ e.preventDefault();
226
+ return setTimeout(function() {
227
+ return $target.val(value + digit + ' ');
228
+ });
229
+ }
230
+ };
231
+
232
+ formatBackCardNumber = function(e) {
233
+ var $target, value;
234
+ $target = $(e.currentTarget);
235
+ value = $target.val();
236
+ if (e.which !== 8) {
237
+ return;
238
+ }
239
+ if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== value.length) {
240
+ return;
241
+ }
242
+ if (/\d\s$/.test(value)) {
243
+ e.preventDefault();
244
+ return setTimeout(function() {
245
+ return $target.val(value.replace(/\d\s$/, ''));
246
+ });
247
+ } else if (/\s\d?$/.test(value)) {
248
+ e.preventDefault();
249
+ return setTimeout(function() {
250
+ return $target.val(value.replace(/\d$/, ''));
251
+ });
252
+ }
253
+ };
254
+
255
+ reFormatExpiry = function(e) {
256
+ return setTimeout(function() {
257
+ var $target, value;
258
+ $target = $(e.currentTarget);
259
+ value = $target.val();
260
+ value = $.payment.formatExpiry(value);
261
+ return $target.val(value);
262
+ });
263
+ };
264
+
265
+ formatExpiry = function(e) {
266
+ var $target, digit, val;
267
+ digit = String.fromCharCode(e.which);
268
+ if (!/^\d+$/.test(digit)) {
269
+ return;
270
+ }
271
+ $target = $(e.currentTarget);
272
+ val = $target.val() + digit;
273
+ if (/^\d$/.test(val) && (val !== '0' && val !== '1')) {
274
+ e.preventDefault();
275
+ return setTimeout(function() {
276
+ return $target.val("0" + val + " / ");
277
+ });
278
+ } else if (/^\d\d$/.test(val)) {
279
+ e.preventDefault();
280
+ return setTimeout(function() {
281
+ return $target.val("" + val + " / ");
282
+ });
283
+ }
284
+ };
285
+
286
+ formatForwardExpiry = function(e) {
287
+ var $target, digit, val;
288
+ digit = String.fromCharCode(e.which);
289
+ if (!/^\d+$/.test(digit)) {
290
+ return;
291
+ }
292
+ $target = $(e.currentTarget);
293
+ val = $target.val();
294
+ if (/^\d\d$/.test(val)) {
295
+ return $target.val("" + val + " / ");
296
+ }
297
+ };
298
+
299
+ formatForwardSlashAndSpace = function(e) {
300
+ var $target, val, which;
301
+ which = String.fromCharCode(e.which);
302
+ if (!(which === '/' || which === ' ')) {
303
+ return;
304
+ }
305
+ $target = $(e.currentTarget);
306
+ val = $target.val();
307
+ if (/^\d$/.test(val) && val !== '0') {
308
+ return $target.val("0" + val + " / ");
309
+ }
310
+ };
311
+
312
+ formatBackExpiry = function(e) {
313
+ var $target, value;
314
+ $target = $(e.currentTarget);
315
+ value = $target.val();
316
+ if (e.which !== 8) {
317
+ return;
318
+ }
319
+ if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== value.length) {
320
+ return;
321
+ }
322
+ if (/\d\s\/\s$/.test(value)) {
323
+ e.preventDefault();
324
+ return setTimeout(function() {
325
+ return $target.val(value.replace(/\d\s\/\s$/, ''));
326
+ });
327
+ }
328
+ };
329
+
330
+ reFormatCVC = function(e) {
331
+ return setTimeout(function() {
332
+ var $target, value;
333
+ $target = $(e.currentTarget);
334
+ value = $target.val();
335
+ value = value.replace(/\D/g, '').slice(0, 4);
336
+ return $target.val(value);
337
+ });
338
+ };
339
+
340
+ restrictNumeric = function(e) {
341
+ var input;
342
+ if (e.metaKey || e.ctrlKey) {
343
+ return true;
344
+ }
345
+ if (e.which === 32) {
346
+ return false;
347
+ }
348
+ if (e.which === 0) {
349
+ return true;
350
+ }
351
+ if (e.which < 33) {
352
+ return true;
353
+ }
354
+ input = String.fromCharCode(e.which);
355
+ return !!/[\d\s]/.test(input);
356
+ };
357
+
358
+ restrictCardNumber = function(e) {
359
+ var $target, card, digit, value;
360
+ $target = $(e.currentTarget);
361
+ digit = String.fromCharCode(e.which);
362
+ if (!/^\d+$/.test(digit)) {
363
+ return;
364
+ }
365
+ if (hasTextSelected($target)) {
366
+ return;
367
+ }
368
+ value = ($target.val() + digit).replace(/\D/g, '');
369
+ card = cardFromNumber(value);
370
+ if (card) {
371
+ return value.length <= card.length[card.length.length - 1];
372
+ } else {
373
+ return value.length <= 16;
374
+ }
375
+ };
376
+
377
+ restrictExpiry = function(e) {
378
+ var $target, digit, value;
379
+ $target = $(e.currentTarget);
380
+ digit = String.fromCharCode(e.which);
381
+ if (!/^\d+$/.test(digit)) {
382
+ return;
383
+ }
384
+ if (hasTextSelected($target)) {
385
+ return;
386
+ }
387
+ value = $target.val() + digit;
388
+ value = value.replace(/\D/g, '');
389
+ if (value.length > 6) {
390
+ return false;
391
+ }
392
+ };
393
+
394
+ restrictCVC = function(e) {
395
+ var $target, digit, val;
396
+ $target = $(e.currentTarget);
397
+ digit = String.fromCharCode(e.which);
398
+ if (!/^\d+$/.test(digit)) {
399
+ return;
400
+ }
401
+ if (hasTextSelected($target)) {
402
+ return;
403
+ }
404
+ val = $target.val() + digit;
405
+ return val.length <= 4;
406
+ };
407
+
408
+ setCardType = function(e) {
409
+ var $target, allTypes, card, cardType, val;
410
+ $target = $(e.currentTarget);
411
+ val = $target.val();
412
+ cardType = $.payment.cardType(val) || 'unknown';
413
+ if (!$target.hasClass(cardType)) {
414
+ allTypes = (function() {
415
+ var _i, _len, _results;
416
+ _results = [];
417
+ for (_i = 0, _len = cards.length; _i < _len; _i++) {
418
+ card = cards[_i];
419
+ _results.push(card.type);
420
+ }
421
+ return _results;
422
+ })();
423
+ $target.removeClass('unknown');
424
+ $target.removeClass(allTypes.join(' '));
425
+ $target.addClass(cardType);
426
+ $target.toggleClass('identified', cardType !== 'unknown');
427
+ return $target.trigger('payment.cardType', cardType);
428
+ }
429
+ };
430
+
431
+ $.payment.fn.formatCardCVC = function() {
432
+ this.on('keypress', restrictNumeric);
433
+ this.on('keypress', restrictCVC);
434
+ this.on('paste', reFormatCVC);
435
+ this.on('change', reFormatCVC);
436
+ this.on('input', reFormatCVC);
437
+ return this;
438
+ };
439
+
440
+ $.payment.fn.formatCardExpiry = function() {
441
+ this.on('keypress', restrictNumeric);
442
+ this.on('keypress', restrictExpiry);
443
+ this.on('keypress', formatExpiry);
444
+ this.on('keypress', formatForwardSlashAndSpace);
445
+ this.on('keypress', formatForwardExpiry);
446
+ this.on('keydown', formatBackExpiry);
447
+ this.on('change', reFormatExpiry);
448
+ this.on('input', reFormatExpiry);
449
+ return this;
450
+ };
451
+
452
+ $.payment.fn.formatCardNumber = function() {
453
+ this.on('keypress', restrictNumeric);
454
+ this.on('keypress', restrictCardNumber);
455
+ this.on('keypress', formatCardNumber);
456
+ this.on('keydown', formatBackCardNumber);
457
+ this.on('keyup', setCardType);
458
+ this.on('paste', reFormatCardNumber);
459
+ this.on('change', reFormatCardNumber);
460
+ this.on('input', reFormatCardNumber);
461
+ this.on('input', setCardType);
462
+ return this;
463
+ };
464
+
465
+ $.payment.fn.restrictNumeric = function() {
466
+ this.on('keypress', restrictNumeric);
467
+ this.on('paste', reFormatNumeric);
468
+ this.on('change', reFormatNumeric);
469
+ this.on('input', reFormatNumeric);
470
+ return this;
471
+ };
472
+
473
+ $.payment.fn.cardExpiryVal = function() {
474
+ return $.payment.cardExpiryVal($(this).val());
475
+ };
476
+
477
+ $.payment.cardExpiryVal = function(value) {
478
+ var month, prefix, year, _ref;
479
+ value = value.replace(/\s/g, '');
480
+ _ref = value.split('/', 2), month = _ref[0], year = _ref[1];
481
+ if ((year != null ? year.length : void 0) === 2 && /^\d+$/.test(year)) {
482
+ prefix = (new Date).getFullYear();
483
+ prefix = prefix.toString().slice(0, 2);
484
+ year = prefix + year;
485
+ }
486
+ month = parseInt(month, 10);
487
+ year = parseInt(year, 10);
488
+ return {
489
+ month: month,
490
+ year: year
491
+ };
492
+ };
493
+
494
+ $.payment.validateCardNumber = function(num) {
495
+ var card, _ref;
496
+ num = (num + '').replace(/\s+|-/g, '');
497
+ if (!/^\d+$/.test(num)) {
498
+ return false;
499
+ }
500
+ card = cardFromNumber(num);
501
+ if (!card) {
502
+ return false;
503
+ }
504
+ return (_ref = num.length, __indexOf.call(card.length, _ref) >= 0) && (card.luhn === false || luhnCheck(num));
505
+ };
506
+
507
+ $.payment.validateCardExpiry = function(month, year) {
508
+ var currentTime, expiry, _ref;
509
+ if (typeof month === 'object' && 'month' in month) {
510
+ _ref = month, month = _ref.month, year = _ref.year;
511
+ }
512
+ if (!(month && year)) {
513
+ return false;
514
+ }
515
+ month = $.trim(month);
516
+ year = $.trim(year);
517
+ if (!/^\d+$/.test(month)) {
518
+ return false;
519
+ }
520
+ if (!/^\d+$/.test(year)) {
521
+ return false;
522
+ }
523
+ if (!((1 <= month && month <= 12))) {
524
+ return false;
525
+ }
526
+ if (year.length === 2) {
527
+ if (year < 70) {
528
+ year = "20" + year;
529
+ } else {
530
+ year = "19" + year;
531
+ }
532
+ }
533
+ if (year.length !== 4) {
534
+ return false;
535
+ }
536
+ expiry = new Date(year, month);
537
+ currentTime = new Date;
538
+ expiry.setMonth(expiry.getMonth() - 1);
539
+ expiry.setMonth(expiry.getMonth() + 1, 1);
540
+ return expiry > currentTime;
541
+ };
542
+
543
+ $.payment.validateCardCVC = function(cvc, type) {
544
+ var card, _ref;
545
+ cvc = $.trim(cvc);
546
+ if (!/^\d+$/.test(cvc)) {
547
+ return false;
548
+ }
549
+ card = cardFromType(type);
550
+ if (card != null) {
551
+ return _ref = cvc.length, __indexOf.call(card.cvcLength, _ref) >= 0;
552
+ } else {
553
+ return cvc.length >= 3 && cvc.length <= 4;
554
+ }
555
+ };
556
+
557
+ $.payment.cardType = function(num) {
558
+ var _ref;
559
+ if (!num) {
560
+ return null;
561
+ }
562
+ return ((_ref = cardFromNumber(num)) != null ? _ref.type : void 0) || null;
563
+ };
564
+
565
+ $.payment.formatCardNumber = function(num) {
566
+ var card, groups, upperLength, _ref;
567
+ num = num.replace(/\D/g, '');
568
+ card = cardFromNumber(num);
569
+ if (!card) {
570
+ return num;
571
+ }
572
+ upperLength = card.length[card.length.length - 1];
573
+ num = num.slice(0, upperLength);
574
+ if (card.format.global) {
575
+ return (_ref = num.match(card.format)) != null ? _ref.join(' ') : void 0;
576
+ } else {
577
+ groups = card.format.exec(num);
578
+ if (groups == null) {
579
+ return;
580
+ }
581
+ groups.shift();
582
+ groups = $.grep(groups, function(n) {
583
+ return n;
584
+ });
585
+ return groups.join(' ');
586
+ }
587
+ };
588
+
589
+ $.payment.formatExpiry = function(expiry) {
590
+ var mon, parts, sep, year;
591
+ parts = expiry.match(/^\D*(\d{1,2})(\D+)?(\d{1,4})?/);
592
+ if (!parts) {
593
+ return '';
594
+ }
595
+ mon = parts[1] || '';
596
+ sep = parts[2] || '';
597
+ year = parts[3] || '';
598
+ if (year.length > 0) {
599
+ sep = ' / ';
600
+ } else if (sep === ' /') {
601
+ mon = mon.substring(0, 1);
602
+ sep = '';
603
+ } else if (mon.length === 2 || sep.length > 0) {
604
+ sep = ' / ';
605
+ } else if (mon.length === 1 && (mon !== '0' && mon !== '1')) {
606
+ mon = "0" + mon;
607
+ sep = ' / ';
608
+ }
609
+ return mon + sep + year;
610
+ };
611
+
612
+ }).call(this);