jquery-payment_lib-rails 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2cab3433ccae79973b429e95cdcb236c2d87cba4
4
+ data.tar.gz: 0a75a6125378db49d6cb26d73c2a3fd6a84a6e32
5
+ SHA512:
6
+ metadata.gz: cbaad47ef0f09043ea3b21e34ca02a2b8ae8ae1989e5b5c2d6cdce663beeff457de6cd3d6d35605744492ae0db80ad94cfd3541d9314f646513af16cbbd24490
7
+ data.tar.gz: a601157c530da447a9e738eb4c7b580b2e62294d97e5604c53785ece3da7fde67cab725761a750acfa1f93d2bd83623960dbde0e7cef2ca0cf105e4318e7d6ca
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jquery-payment_lib-rails.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # jquery-payment_lib-rails
2
+
3
+ This gem makes easy to use [jquery.payment](https://github.com/stripe/jquery.payment) javascript library in your rails application.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'jquery-payment_lib-rails'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install jquery-payment_lib-rails
20
+
21
+ ## Usage
22
+
23
+ In your application js:
24
+
25
+ ```js
26
+ //= require jquery.payment
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jquery/payment_lib/rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jquery/payment_lib/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jquery-payment_lib-rails"
8
+ spec.version = Jquery::PaymentLib::Rails::VERSION
9
+ spec.authors = ["Nikolay Digaev"]
10
+ spec.email = ["ffs.cmp@gmail.com"]
11
+
12
+ spec.summary = %q{Use jQuery.payment with Rails}
13
+ spec.description = %q{This gem provides jQuery.payment library for using in your Rails application.}
14
+ spec.homepage = "https://github.com/digaev/jquery-payment_lib-rails"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib", "vendor"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.10"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,7 @@
1
+ module Jquery
2
+ module PaymentLib
3
+ module Rails
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require "jquery/payment_lib/rails/version"
2
+
3
+ module Jquery
4
+ module PaymentLib
5
+ module Rails
6
+ class Engine < ::Rails::Engine
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,635 @@
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, replaceFullWidthChars, restrictCVC, restrictCardNumber, restrictExpiry, restrictNumeric, safeVal, 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
+ $ = window.jQuery || window.Zepto || window.$;
8
+
9
+ $.payment = {};
10
+
11
+ $.payment.fn = {};
12
+
13
+ $.fn.payment = function() {
14
+ var args, method;
15
+ method = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
16
+ return $.payment.fn[method].apply(this, args);
17
+ };
18
+
19
+ defaultFormat = /(\d{1,4})/g;
20
+
21
+ $.payment.cards = cards = [
22
+ {
23
+ type: 'visaelectron',
24
+ pattern: /^4(026|17500|405|508|844|91[37])/,
25
+ format: defaultFormat,
26
+ length: [16],
27
+ cvcLength: [3],
28
+ luhn: true
29
+ }, {
30
+ type: 'maestro',
31
+ pattern: /^(5(018|0[23]|[68])|6(39|7))/,
32
+ format: defaultFormat,
33
+ length: [12, 13, 14, 15, 16, 17, 18, 19],
34
+ cvcLength: [3],
35
+ luhn: true
36
+ }, {
37
+ type: 'forbrugsforeningen',
38
+ pattern: /^600/,
39
+ format: defaultFormat,
40
+ length: [16],
41
+ cvcLength: [3],
42
+ luhn: true
43
+ }, {
44
+ type: 'dankort',
45
+ pattern: /^5019/,
46
+ format: defaultFormat,
47
+ length: [16],
48
+ cvcLength: [3],
49
+ luhn: true
50
+ }, {
51
+ type: 'visa',
52
+ pattern: /^4/,
53
+ format: defaultFormat,
54
+ length: [13, 16],
55
+ cvcLength: [3],
56
+ luhn: true
57
+ }, {
58
+ type: 'mastercard',
59
+ pattern: /^(5[1-5]|2[2-7])/,
60
+ format: defaultFormat,
61
+ length: [16],
62
+ cvcLength: [3],
63
+ luhn: true
64
+ }, {
65
+ type: 'amex',
66
+ pattern: /^3[47]/,
67
+ format: /(\d{1,4})(\d{1,6})?(\d{1,5})?/,
68
+ length: [15],
69
+ cvcLength: [3, 4],
70
+ luhn: true
71
+ }, {
72
+ type: 'dinersclub',
73
+ pattern: /^3[0689]/,
74
+ format: /(\d{1,4})(\d{1,6})?(\d{1,4})?/,
75
+ length: [14],
76
+ cvcLength: [3],
77
+ luhn: true
78
+ }, {
79
+ type: 'discover',
80
+ pattern: /^6([045]|22)/,
81
+ format: defaultFormat,
82
+ length: [16],
83
+ cvcLength: [3],
84
+ luhn: true
85
+ }, {
86
+ type: 'unionpay',
87
+ pattern: /^(62|88)/,
88
+ format: defaultFormat,
89
+ length: [16, 17, 18, 19],
90
+ cvcLength: [3],
91
+ luhn: false
92
+ }, {
93
+ type: 'jcb',
94
+ pattern: /^35/,
95
+ format: defaultFormat,
96
+ length: [16],
97
+ cvcLength: [3],
98
+ luhn: true
99
+ }
100
+ ];
101
+
102
+ cardFromNumber = function(num) {
103
+ var card, _i, _len;
104
+ num = (num + '').replace(/\D/g, '');
105
+ for (_i = 0, _len = cards.length; _i < _len; _i++) {
106
+ card = cards[_i];
107
+ if (card.pattern.test(num)) {
108
+ return card;
109
+ }
110
+ }
111
+ };
112
+
113
+ cardFromType = function(type) {
114
+ var card, _i, _len;
115
+ for (_i = 0, _len = cards.length; _i < _len; _i++) {
116
+ card = cards[_i];
117
+ if (card.type === type) {
118
+ return card;
119
+ }
120
+ }
121
+ };
122
+
123
+ luhnCheck = function(num) {
124
+ var digit, digits, odd, sum, _i, _len;
125
+ odd = true;
126
+ sum = 0;
127
+ digits = (num + '').split('').reverse();
128
+ for (_i = 0, _len = digits.length; _i < _len; _i++) {
129
+ digit = digits[_i];
130
+ digit = parseInt(digit, 10);
131
+ if ((odd = !odd)) {
132
+ digit *= 2;
133
+ }
134
+ if (digit > 9) {
135
+ digit -= 9;
136
+ }
137
+ sum += digit;
138
+ }
139
+ return sum % 10 === 0;
140
+ };
141
+
142
+ hasTextSelected = function($target) {
143
+ var _ref;
144
+ if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== $target.prop('selectionEnd')) {
145
+ return true;
146
+ }
147
+ if ((typeof document !== "undefined" && document !== null ? (_ref = document.selection) != null ? _ref.createRange : void 0 : void 0) != null) {
148
+ if (document.selection.createRange().text) {
149
+ return true;
150
+ }
151
+ }
152
+ return false;
153
+ };
154
+
155
+ safeVal = function(value, $target) {
156
+ var cursor, error, last;
157
+ try {
158
+ cursor = $target.prop('selectionStart');
159
+ } catch (_error) {
160
+ error = _error;
161
+ cursor = null;
162
+ }
163
+ last = $target.val();
164
+ $target.val(value);
165
+ if (cursor !== null && $target.is(":focus")) {
166
+ if (cursor === last.length) {
167
+ cursor = value.length;
168
+ }
169
+ $target.prop('selectionStart', cursor);
170
+ return $target.prop('selectionEnd', cursor);
171
+ }
172
+ };
173
+
174
+ replaceFullWidthChars = function(str) {
175
+ var chars, chr, fullWidth, halfWidth, idx, value, _i, _len;
176
+ if (str == null) {
177
+ str = '';
178
+ }
179
+ fullWidth = '\uff10\uff11\uff12\uff13\uff14\uff15\uff16\uff17\uff18\uff19';
180
+ halfWidth = '0123456789';
181
+ value = '';
182
+ chars = str.split('');
183
+ for (_i = 0, _len = chars.length; _i < _len; _i++) {
184
+ chr = chars[_i];
185
+ idx = fullWidth.indexOf(chr);
186
+ if (idx > -1) {
187
+ chr = halfWidth[idx];
188
+ }
189
+ value += chr;
190
+ }
191
+ return value;
192
+ };
193
+
194
+ reFormatNumeric = function(e) {
195
+ return setTimeout(function() {
196
+ var $target, value;
197
+ $target = $(e.currentTarget);
198
+ value = $target.val();
199
+ value = replaceFullWidthChars(value);
200
+ value = value.replace(/\D/g, '');
201
+ return safeVal(value, $target);
202
+ });
203
+ };
204
+
205
+ reFormatCardNumber = function(e) {
206
+ return setTimeout(function() {
207
+ var $target, value;
208
+ $target = $(e.currentTarget);
209
+ value = $target.val();
210
+ value = replaceFullWidthChars(value);
211
+ value = $.payment.formatCardNumber(value);
212
+ return safeVal(value, $target);
213
+ });
214
+ };
215
+
216
+ formatCardNumber = function(e) {
217
+ var $target, card, digit, length, re, upperLength, value;
218
+ digit = String.fromCharCode(e.which);
219
+ if (!/^\d+$/.test(digit)) {
220
+ return;
221
+ }
222
+ $target = $(e.currentTarget);
223
+ value = $target.val();
224
+ card = cardFromNumber(value + digit);
225
+ length = (value.replace(/\D/g, '') + digit).length;
226
+ upperLength = 16;
227
+ if (card) {
228
+ upperLength = card.length[card.length.length - 1];
229
+ }
230
+ if (length >= upperLength) {
231
+ return;
232
+ }
233
+ if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== value.length) {
234
+ return;
235
+ }
236
+ if (card && card.type === 'amex') {
237
+ re = /^(\d{4}|\d{4}\s\d{6})$/;
238
+ } else {
239
+ re = /(?:^|\s)(\d{4})$/;
240
+ }
241
+ if (re.test(value)) {
242
+ e.preventDefault();
243
+ return setTimeout(function() {
244
+ return $target.val(value + ' ' + digit);
245
+ });
246
+ } else if (re.test(value + digit)) {
247
+ e.preventDefault();
248
+ return setTimeout(function() {
249
+ return $target.val(value + digit + ' ');
250
+ });
251
+ }
252
+ };
253
+
254
+ formatBackCardNumber = function(e) {
255
+ var $target, value;
256
+ $target = $(e.currentTarget);
257
+ value = $target.val();
258
+ if (e.which !== 8) {
259
+ return;
260
+ }
261
+ if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== value.length) {
262
+ return;
263
+ }
264
+ if (/\d\s$/.test(value)) {
265
+ e.preventDefault();
266
+ return setTimeout(function() {
267
+ return $target.val(value.replace(/\d\s$/, ''));
268
+ });
269
+ } else if (/\s\d?$/.test(value)) {
270
+ e.preventDefault();
271
+ return setTimeout(function() {
272
+ return $target.val(value.replace(/\d$/, ''));
273
+ });
274
+ }
275
+ };
276
+
277
+ reFormatExpiry = function(e) {
278
+ return setTimeout(function() {
279
+ var $target, value;
280
+ $target = $(e.currentTarget);
281
+ value = $target.val();
282
+ value = replaceFullWidthChars(value);
283
+ value = $.payment.formatExpiry(value);
284
+ return safeVal(value, $target);
285
+ });
286
+ };
287
+
288
+ formatExpiry = function(e) {
289
+ var $target, digit, val;
290
+ digit = String.fromCharCode(e.which);
291
+ if (!/^\d+$/.test(digit)) {
292
+ return;
293
+ }
294
+ $target = $(e.currentTarget);
295
+ val = $target.val() + digit;
296
+ if (/^\d$/.test(val) && (val !== '0' && val !== '1')) {
297
+ e.preventDefault();
298
+ return setTimeout(function() {
299
+ return $target.val("0" + val + " / ");
300
+ });
301
+ } else if (/^\d\d$/.test(val)) {
302
+ e.preventDefault();
303
+ return setTimeout(function() {
304
+ return $target.val("" + val + " / ");
305
+ });
306
+ }
307
+ };
308
+
309
+ formatForwardExpiry = function(e) {
310
+ var $target, digit, val;
311
+ digit = String.fromCharCode(e.which);
312
+ if (!/^\d+$/.test(digit)) {
313
+ return;
314
+ }
315
+ $target = $(e.currentTarget);
316
+ val = $target.val();
317
+ if (/^\d\d$/.test(val)) {
318
+ return $target.val("" + val + " / ");
319
+ }
320
+ };
321
+
322
+ formatForwardSlashAndSpace = function(e) {
323
+ var $target, val, which;
324
+ which = String.fromCharCode(e.which);
325
+ if (!(which === '/' || which === ' ')) {
326
+ return;
327
+ }
328
+ $target = $(e.currentTarget);
329
+ val = $target.val();
330
+ if (/^\d$/.test(val) && val !== '0') {
331
+ return $target.val("0" + val + " / ");
332
+ }
333
+ };
334
+
335
+ formatBackExpiry = function(e) {
336
+ var $target, value;
337
+ $target = $(e.currentTarget);
338
+ value = $target.val();
339
+ if (e.which !== 8) {
340
+ return;
341
+ }
342
+ if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== value.length) {
343
+ return;
344
+ }
345
+ if (/\d\s\/\s$/.test(value)) {
346
+ e.preventDefault();
347
+ return setTimeout(function() {
348
+ return $target.val(value.replace(/\d\s\/\s$/, ''));
349
+ });
350
+ }
351
+ };
352
+
353
+ reFormatCVC = function(e) {
354
+ return setTimeout(function() {
355
+ var $target, value;
356
+ $target = $(e.currentTarget);
357
+ value = $target.val();
358
+ value = replaceFullWidthChars(value);
359
+ value = value.replace(/\D/g, '').slice(0, 4);
360
+ return safeVal(value, $target);
361
+ });
362
+ };
363
+
364
+ restrictNumeric = function(e) {
365
+ var input;
366
+ if (e.metaKey || e.ctrlKey) {
367
+ return true;
368
+ }
369
+ if (e.which === 32) {
370
+ return false;
371
+ }
372
+ if (e.which === 0) {
373
+ return true;
374
+ }
375
+ if (e.which < 33) {
376
+ return true;
377
+ }
378
+ input = String.fromCharCode(e.which);
379
+ return !!/[\d\s]/.test(input);
380
+ };
381
+
382
+ restrictCardNumber = function(e) {
383
+ var $target, card, digit, value;
384
+ $target = $(e.currentTarget);
385
+ digit = String.fromCharCode(e.which);
386
+ if (!/^\d+$/.test(digit)) {
387
+ return;
388
+ }
389
+ if (hasTextSelected($target)) {
390
+ return;
391
+ }
392
+ value = ($target.val() + digit).replace(/\D/g, '');
393
+ card = cardFromNumber(value);
394
+ if (card) {
395
+ return value.length <= card.length[card.length.length - 1];
396
+ } else {
397
+ return value.length <= 16;
398
+ }
399
+ };
400
+
401
+ restrictExpiry = function(e) {
402
+ var $target, digit, value;
403
+ $target = $(e.currentTarget);
404
+ digit = String.fromCharCode(e.which);
405
+ if (!/^\d+$/.test(digit)) {
406
+ return;
407
+ }
408
+ if (hasTextSelected($target)) {
409
+ return;
410
+ }
411
+ value = $target.val() + digit;
412
+ value = value.replace(/\D/g, '');
413
+ if (value.length > 6) {
414
+ return false;
415
+ }
416
+ };
417
+
418
+ restrictCVC = function(e) {
419
+ var $target, digit, val;
420
+ $target = $(e.currentTarget);
421
+ digit = String.fromCharCode(e.which);
422
+ if (!/^\d+$/.test(digit)) {
423
+ return;
424
+ }
425
+ if (hasTextSelected($target)) {
426
+ return;
427
+ }
428
+ val = $target.val() + digit;
429
+ return val.length <= 4;
430
+ };
431
+
432
+ setCardType = function(e) {
433
+ var $target, allTypes, card, cardType, val;
434
+ $target = $(e.currentTarget);
435
+ val = $target.val();
436
+ cardType = $.payment.cardType(val) || 'unknown';
437
+ if (!$target.hasClass(cardType)) {
438
+ allTypes = (function() {
439
+ var _i, _len, _results;
440
+ _results = [];
441
+ for (_i = 0, _len = cards.length; _i < _len; _i++) {
442
+ card = cards[_i];
443
+ _results.push(card.type);
444
+ }
445
+ return _results;
446
+ })();
447
+ $target.removeClass('unknown');
448
+ $target.removeClass(allTypes.join(' '));
449
+ $target.addClass(cardType);
450
+ $target.toggleClass('identified', cardType !== 'unknown');
451
+ return $target.trigger('payment.cardType', cardType);
452
+ }
453
+ };
454
+
455
+ $.payment.fn.formatCardCVC = function() {
456
+ this.on('keypress', restrictNumeric);
457
+ this.on('keypress', restrictCVC);
458
+ this.on('paste', reFormatCVC);
459
+ this.on('change', reFormatCVC);
460
+ this.on('input', reFormatCVC);
461
+ return this;
462
+ };
463
+
464
+ $.payment.fn.formatCardExpiry = function() {
465
+ this.on('keypress', restrictNumeric);
466
+ this.on('keypress', restrictExpiry);
467
+ this.on('keypress', formatExpiry);
468
+ this.on('keypress', formatForwardSlashAndSpace);
469
+ this.on('keypress', formatForwardExpiry);
470
+ this.on('keydown', formatBackExpiry);
471
+ this.on('change', reFormatExpiry);
472
+ this.on('input', reFormatExpiry);
473
+ return this;
474
+ };
475
+
476
+ $.payment.fn.formatCardNumber = function() {
477
+ this.on('keypress', restrictNumeric);
478
+ this.on('keypress', restrictCardNumber);
479
+ this.on('keypress', formatCardNumber);
480
+ this.on('keydown', formatBackCardNumber);
481
+ this.on('keyup', setCardType);
482
+ this.on('paste', reFormatCardNumber);
483
+ this.on('change', reFormatCardNumber);
484
+ this.on('input', reFormatCardNumber);
485
+ this.on('input', setCardType);
486
+ return this;
487
+ };
488
+
489
+ $.payment.fn.restrictNumeric = function() {
490
+ this.on('keypress', restrictNumeric);
491
+ this.on('paste', reFormatNumeric);
492
+ this.on('change', reFormatNumeric);
493
+ this.on('input', reFormatNumeric);
494
+ return this;
495
+ };
496
+
497
+ $.payment.fn.cardExpiryVal = function() {
498
+ return $.payment.cardExpiryVal($(this).val());
499
+ };
500
+
501
+ $.payment.cardExpiryVal = function(value) {
502
+ var month, prefix, year, _ref;
503
+ _ref = value.split(/[\s\/]+/, 2), month = _ref[0], year = _ref[1];
504
+ if ((year != null ? year.length : void 0) === 2 && /^\d+$/.test(year)) {
505
+ prefix = (new Date).getFullYear();
506
+ prefix = prefix.toString().slice(0, 2);
507
+ year = prefix + year;
508
+ }
509
+ month = parseInt(month, 10);
510
+ year = parseInt(year, 10);
511
+ return {
512
+ month: month,
513
+ year: year
514
+ };
515
+ };
516
+
517
+ $.payment.validateCardNumber = function(num) {
518
+ var card, _ref;
519
+ num = (num + '').replace(/\s+|-/g, '');
520
+ if (!/^\d+$/.test(num)) {
521
+ return false;
522
+ }
523
+ card = cardFromNumber(num);
524
+ if (!card) {
525
+ return false;
526
+ }
527
+ return (_ref = num.length, __indexOf.call(card.length, _ref) >= 0) && (card.luhn === false || luhnCheck(num));
528
+ };
529
+
530
+ $.payment.validateCardExpiry = function(month, year) {
531
+ var currentTime, expiry, _ref;
532
+ if (typeof month === 'object' && 'month' in month) {
533
+ _ref = month, month = _ref.month, year = _ref.year;
534
+ }
535
+ if (!(month && year)) {
536
+ return false;
537
+ }
538
+ month = $.trim(month);
539
+ year = $.trim(year);
540
+ if (!/^\d+$/.test(month)) {
541
+ return false;
542
+ }
543
+ if (!/^\d+$/.test(year)) {
544
+ return false;
545
+ }
546
+ if (!((1 <= month && month <= 12))) {
547
+ return false;
548
+ }
549
+ if (year.length === 2) {
550
+ if (year < 70) {
551
+ year = "20" + year;
552
+ } else {
553
+ year = "19" + year;
554
+ }
555
+ }
556
+ if (year.length !== 4) {
557
+ return false;
558
+ }
559
+ expiry = new Date(year, month);
560
+ currentTime = new Date;
561
+ expiry.setMonth(expiry.getMonth() - 1);
562
+ expiry.setMonth(expiry.getMonth() + 1, 1);
563
+ return expiry > currentTime;
564
+ };
565
+
566
+ $.payment.validateCardCVC = function(cvc, type) {
567
+ var card, _ref;
568
+ cvc = $.trim(cvc);
569
+ if (!/^\d+$/.test(cvc)) {
570
+ return false;
571
+ }
572
+ card = cardFromType(type);
573
+ if (card != null) {
574
+ return _ref = cvc.length, __indexOf.call(card.cvcLength, _ref) >= 0;
575
+ } else {
576
+ return cvc.length >= 3 && cvc.length <= 4;
577
+ }
578
+ };
579
+
580
+ $.payment.cardType = function(num) {
581
+ var _ref;
582
+ if (!num) {
583
+ return null;
584
+ }
585
+ return ((_ref = cardFromNumber(num)) != null ? _ref.type : void 0) || null;
586
+ };
587
+
588
+ $.payment.formatCardNumber = function(num) {
589
+ var card, groups, upperLength, _ref;
590
+ num = num.replace(/\D/g, '');
591
+ card = cardFromNumber(num);
592
+ if (!card) {
593
+ return num;
594
+ }
595
+ upperLength = card.length[card.length.length - 1];
596
+ num = num.slice(0, upperLength);
597
+ if (card.format.global) {
598
+ return (_ref = num.match(card.format)) != null ? _ref.join(' ') : void 0;
599
+ } else {
600
+ groups = card.format.exec(num);
601
+ if (groups == null) {
602
+ return;
603
+ }
604
+ groups.shift();
605
+ groups = $.grep(groups, function(n) {
606
+ return n;
607
+ });
608
+ return groups.join(' ');
609
+ }
610
+ };
611
+
612
+ $.payment.formatExpiry = function(expiry) {
613
+ var mon, parts, sep, year;
614
+ parts = expiry.match(/^\D*(\d{1,2})(\D+)?(\d{1,4})?/);
615
+ if (!parts) {
616
+ return '';
617
+ }
618
+ mon = parts[1] || '';
619
+ sep = parts[2] || '';
620
+ year = parts[3] || '';
621
+ if (year.length > 0) {
622
+ sep = ' / ';
623
+ } else if (sep === ' /') {
624
+ mon = mon.substring(0, 1);
625
+ sep = '';
626
+ } else if (mon.length === 2 || sep.length > 0) {
627
+ sep = ' / ';
628
+ } else if (mon.length === 1 && (mon !== '0' && mon !== '1')) {
629
+ mon = "0" + mon;
630
+ sep = ' / ';
631
+ }
632
+ return mon + sep + year;
633
+ };
634
+
635
+ }).call(this);
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jquery-payment_lib-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nikolay Digaev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: This gem provides jQuery.payment library for using in your Rails application.
42
+ email:
43
+ - ffs.cmp@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".travis.yml"
50
+ - Gemfile
51
+ - README.md
52
+ - Rakefile
53
+ - bin/console
54
+ - bin/setup
55
+ - jquery-payment_lib-rails.gemspec
56
+ - lib/jquery/payment_lib/rails.rb
57
+ - lib/jquery/payment_lib/rails/version.rb
58
+ - vendor/assets/javascripts/jquery.payment.js
59
+ homepage: https://github.com/digaev/jquery-payment_lib-rails
60
+ licenses: []
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ - vendor
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.4.8
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Use jQuery.payment with Rails
83
+ test_files: []