jquery_payment-rails 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +32 -0
- data/Rakefile +2 -0
- data/jquery_payment-rails.gemspec +25 -0
- data/lib/jquery/payment/rails.rb +9 -0
- data/lib/jquery/payment/rails/engine.rb +8 -0
- data/lib/jquery/payment/rails/version.rb +7 -0
- data/lib/jquery_payment-rails.rb +9 -0
- data/vendor/assets/javascripts/jquery.payment.coffee +486 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d6de8a8424d1d6cb153258fe8828e1979e7ab1cd
|
4
|
+
data.tar.gz: da72f61f9585111778a2e5a8191d2752fff468c6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 827e91b721f69860e79773df1f88722aea271be630a69ac26dcc87c79da56cd79dd1cf2df7e3e2ffb348ebc0f4c8cea653033522d10e5542c3aeb6dbdc18bb96
|
7
|
+
data.tar.gz: be56c9a4720291a9010e9bc191e7c1928ad41032ebd6b4cfb194448915f7a3ff7a43a1de6403502fde21f4413d5ea81f58b50e848f7397eab40a9c3aa34c131c
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Navin Peiris
|
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,32 @@
|
|
1
|
+
# jquery.payment for Rails
|
2
|
+
|
3
|
+
[jQuery.payment](https://github.com/stripe/jquery.payment), a general purpose library for building credit card forms
|
4
|
+
by Stripe for the Rails asset pipeline. See the plugin homepage for more details.
|
5
|
+
|
6
|
+
## Plugin versions
|
7
|
+
|
8
|
+
* jquery.payment Plugin v1.1.0
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'jquery_payment-rails'
|
16
|
+
```
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
Add the following to your `app/assets/javascripts/application.js`:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
//= require jquery.payment
|
24
|
+
```
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
1. Fork it ( https://github.com/navinpeiris/jquery_payment-rails/fork )
|
29
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
32
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
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/rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'jquery_payment-rails'
|
8
|
+
spec.version = JQuery::Payment::Rails::VERSION
|
9
|
+
spec.authors = ['Navin Peiris']
|
10
|
+
spec.email = ['navin.peiris@gmail.com']
|
11
|
+
spec.summary = %q{jquery.payment for Rails Asset Pipeline}
|
12
|
+
spec.description = %q{jquery.payment library for building credit card forms for the Rails Asset Pipeline }
|
13
|
+
spec.homepage = 'https://github.com/navinpeiris/jquery_payment-rails'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'railties', '>= 3.1'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
end
|
@@ -0,0 +1,486 @@
|
|
1
|
+
$ = jQuery
|
2
|
+
$.payment = {}
|
3
|
+
$.payment.fn = {}
|
4
|
+
$.fn.payment = (method, args...) ->
|
5
|
+
$.payment.fn[method].apply(this, args)
|
6
|
+
|
7
|
+
# Utils
|
8
|
+
|
9
|
+
defaultFormat = /(\d{1,4})/g
|
10
|
+
|
11
|
+
cards = [
|
12
|
+
# Debit cards must come first, since they have more
|
13
|
+
# specific patterns than their credit-card equivalents.
|
14
|
+
{
|
15
|
+
type: 'visaelectron'
|
16
|
+
pattern: /^4(026|17500|405|508|844|91[37])/
|
17
|
+
format: defaultFormat
|
18
|
+
length: [16]
|
19
|
+
cvcLength: [3]
|
20
|
+
luhn: true
|
21
|
+
}
|
22
|
+
{
|
23
|
+
type: 'maestro'
|
24
|
+
pattern: /^(5(018|0[23]|[68])|6(39|7))/
|
25
|
+
format: defaultFormat
|
26
|
+
length: [12..19]
|
27
|
+
cvcLength: [3]
|
28
|
+
luhn: true
|
29
|
+
}
|
30
|
+
{
|
31
|
+
type: 'forbrugsforeningen'
|
32
|
+
pattern: /^600/
|
33
|
+
format: defaultFormat
|
34
|
+
length: [16]
|
35
|
+
cvcLength: [3]
|
36
|
+
luhn: true
|
37
|
+
}
|
38
|
+
{
|
39
|
+
type: 'dankort'
|
40
|
+
pattern: /^5019/
|
41
|
+
format: defaultFormat
|
42
|
+
length: [16]
|
43
|
+
cvcLength: [3]
|
44
|
+
luhn: true
|
45
|
+
}
|
46
|
+
# Credit cards
|
47
|
+
{
|
48
|
+
type: 'visa'
|
49
|
+
pattern: /^4/
|
50
|
+
format: defaultFormat
|
51
|
+
length: [13, 16]
|
52
|
+
cvcLength: [3]
|
53
|
+
luhn: true
|
54
|
+
}
|
55
|
+
{
|
56
|
+
type: 'mastercard'
|
57
|
+
pattern: /^5[0-5]/
|
58
|
+
format: defaultFormat
|
59
|
+
length: [16]
|
60
|
+
cvcLength: [3]
|
61
|
+
luhn: true
|
62
|
+
}
|
63
|
+
{
|
64
|
+
type: 'amex'
|
65
|
+
pattern: /^3[47]/
|
66
|
+
format: /(\d{1,4})(\d{1,6})?(\d{1,5})?/
|
67
|
+
length: [15]
|
68
|
+
cvcLength: [3..4]
|
69
|
+
luhn: true
|
70
|
+
}
|
71
|
+
{
|
72
|
+
type: 'dinersclub'
|
73
|
+
pattern: /^3[0689]/
|
74
|
+
format: defaultFormat
|
75
|
+
length: [14]
|
76
|
+
cvcLength: [3]
|
77
|
+
luhn: true
|
78
|
+
}
|
79
|
+
{
|
80
|
+
type: 'discover'
|
81
|
+
pattern: /^6([045]|22)/
|
82
|
+
format: defaultFormat
|
83
|
+
length: [16]
|
84
|
+
cvcLength: [3]
|
85
|
+
luhn: true
|
86
|
+
}
|
87
|
+
{
|
88
|
+
type: 'unionpay'
|
89
|
+
pattern: /^(62|88)/
|
90
|
+
format: defaultFormat
|
91
|
+
length: [16..19]
|
92
|
+
cvcLength: [3]
|
93
|
+
luhn: false
|
94
|
+
}
|
95
|
+
{
|
96
|
+
type: 'jcb'
|
97
|
+
pattern: /^35/
|
98
|
+
format: defaultFormat
|
99
|
+
length: [16]
|
100
|
+
cvcLength: [3]
|
101
|
+
luhn: true
|
102
|
+
}
|
103
|
+
]
|
104
|
+
|
105
|
+
cardFromNumber = (num) ->
|
106
|
+
num = (num + '').replace(/\D/g, '')
|
107
|
+
return card for card in cards when card.pattern.test(num)
|
108
|
+
|
109
|
+
cardFromType = (type) ->
|
110
|
+
return card for card in cards when card.type is type
|
111
|
+
|
112
|
+
luhnCheck = (num) ->
|
113
|
+
odd = true
|
114
|
+
sum = 0
|
115
|
+
|
116
|
+
digits = (num + '').split('').reverse()
|
117
|
+
|
118
|
+
for digit in digits
|
119
|
+
digit = parseInt(digit, 10)
|
120
|
+
digit *= 2 if (odd = !odd)
|
121
|
+
digit -= 9 if digit > 9
|
122
|
+
sum += digit
|
123
|
+
|
124
|
+
sum % 10 == 0
|
125
|
+
|
126
|
+
hasTextSelected = ($target) ->
|
127
|
+
# If some text is selected
|
128
|
+
return true if $target.prop('selectionStart')? and
|
129
|
+
$target.prop('selectionStart') isnt $target.prop('selectionEnd')
|
130
|
+
|
131
|
+
# If some text is selected in IE
|
132
|
+
return true if document?.selection?.createRange?().text
|
133
|
+
|
134
|
+
false
|
135
|
+
|
136
|
+
# Private
|
137
|
+
|
138
|
+
# Format Card Number
|
139
|
+
|
140
|
+
reFormatCardNumber = (e) ->
|
141
|
+
setTimeout ->
|
142
|
+
$target = $(e.currentTarget)
|
143
|
+
value = $target.val()
|
144
|
+
value = $.payment.formatCardNumber(value)
|
145
|
+
$target.val(value)
|
146
|
+
|
147
|
+
formatCardNumber = (e) ->
|
148
|
+
# Only format if input is a number
|
149
|
+
digit = String.fromCharCode(e.which)
|
150
|
+
return unless /^\d+$/.test(digit)
|
151
|
+
|
152
|
+
$target = $(e.currentTarget)
|
153
|
+
value = $target.val()
|
154
|
+
card = cardFromNumber(value + digit)
|
155
|
+
length = (value.replace(/\D/g, '') + digit).length
|
156
|
+
|
157
|
+
upperLength = 16
|
158
|
+
upperLength = card.length[card.length.length - 1] if card
|
159
|
+
return if length >= upperLength
|
160
|
+
|
161
|
+
# Return if focus isn't at the end of the text
|
162
|
+
return if $target.prop('selectionStart')? and
|
163
|
+
$target.prop('selectionStart') isnt value.length
|
164
|
+
|
165
|
+
if card && card.type is 'amex'
|
166
|
+
# AMEX cards are formatted differently
|
167
|
+
re = /^(\d{4}|\d{4}\s\d{6})$/
|
168
|
+
else
|
169
|
+
re = /(?:^|\s)(\d{4})$/
|
170
|
+
|
171
|
+
# If '4242' + 4
|
172
|
+
if re.test(value)
|
173
|
+
e.preventDefault()
|
174
|
+
setTimeout -> $target.val(value + ' ' + digit)
|
175
|
+
|
176
|
+
# If '424' + 2
|
177
|
+
else if re.test(value + digit)
|
178
|
+
e.preventDefault()
|
179
|
+
setTimeout -> $target.val(value + digit + ' ')
|
180
|
+
|
181
|
+
formatBackCardNumber = (e) ->
|
182
|
+
$target = $(e.currentTarget)
|
183
|
+
value = $target.val()
|
184
|
+
|
185
|
+
# Return unless backspacing
|
186
|
+
return unless e.which is 8
|
187
|
+
|
188
|
+
# Return if focus isn't at the end of the text
|
189
|
+
return if $target.prop('selectionStart')? and
|
190
|
+
$target.prop('selectionStart') isnt value.length
|
191
|
+
|
192
|
+
# Remove the trailing space
|
193
|
+
if /\d\s$/.test(value)
|
194
|
+
e.preventDefault()
|
195
|
+
setTimeout -> $target.val(value.replace(/\d\s$/, ''))
|
196
|
+
else if /\s\d?$/.test(value)
|
197
|
+
e.preventDefault()
|
198
|
+
setTimeout -> $target.val(value.replace(/\s\d?$/, ''))
|
199
|
+
|
200
|
+
# Format Expiry
|
201
|
+
|
202
|
+
reFormatExpiry = (e) ->
|
203
|
+
setTimeout ->
|
204
|
+
$target = $(e.currentTarget)
|
205
|
+
value = $target.val()
|
206
|
+
value = $.payment.formatExpiry(value)
|
207
|
+
$target.val(value)
|
208
|
+
|
209
|
+
formatExpiry = (e) ->
|
210
|
+
# Only format if input is a number
|
211
|
+
digit = String.fromCharCode(e.which)
|
212
|
+
return unless /^\d+$/.test(digit)
|
213
|
+
|
214
|
+
$target = $(e.currentTarget)
|
215
|
+
val = $target.val() + digit
|
216
|
+
|
217
|
+
if /^\d$/.test(val) and val not in ['0', '1']
|
218
|
+
e.preventDefault()
|
219
|
+
setTimeout -> $target.val("0#{val} / ")
|
220
|
+
|
221
|
+
else if /^\d\d$/.test(val)
|
222
|
+
e.preventDefault()
|
223
|
+
setTimeout -> $target.val("#{val} / ")
|
224
|
+
|
225
|
+
formatForwardExpiry = (e) ->
|
226
|
+
digit = String.fromCharCode(e.which)
|
227
|
+
return unless /^\d+$/.test(digit)
|
228
|
+
|
229
|
+
$target = $(e.currentTarget)
|
230
|
+
val = $target.val()
|
231
|
+
|
232
|
+
if /^\d\d$/.test(val)
|
233
|
+
$target.val("#{val} / ")
|
234
|
+
|
235
|
+
formatForwardSlash = (e) ->
|
236
|
+
slash = String.fromCharCode(e.which)
|
237
|
+
return unless slash is '/'
|
238
|
+
|
239
|
+
$target = $(e.currentTarget)
|
240
|
+
val = $target.val()
|
241
|
+
|
242
|
+
if /^\d$/.test(val) and val isnt '0'
|
243
|
+
$target.val("0#{val} / ")
|
244
|
+
|
245
|
+
formatBackExpiry = (e) ->
|
246
|
+
$target = $(e.currentTarget)
|
247
|
+
value = $target.val()
|
248
|
+
|
249
|
+
# Return unless backspacing
|
250
|
+
return unless e.which is 8
|
251
|
+
|
252
|
+
# Return if focus isn't at the end of the text
|
253
|
+
return if $target.prop('selectionStart')? and
|
254
|
+
$target.prop('selectionStart') isnt value.length
|
255
|
+
|
256
|
+
# Remove the trailing space
|
257
|
+
if /\s\/\s\d?$/.test(value)
|
258
|
+
e.preventDefault()
|
259
|
+
setTimeout -> $target.val(value.replace(/\s\/\s\d?$/, ''))
|
260
|
+
|
261
|
+
# Restrictions
|
262
|
+
|
263
|
+
restrictNumeric = (e) ->
|
264
|
+
# Key event is for a browser shortcut
|
265
|
+
return true if e.metaKey or e.ctrlKey
|
266
|
+
|
267
|
+
# If keycode is a space
|
268
|
+
return false if e.which is 32
|
269
|
+
|
270
|
+
# If keycode is a special char (WebKit)
|
271
|
+
return true if e.which is 0
|
272
|
+
|
273
|
+
# If char is a special char (Firefox)
|
274
|
+
return true if e.which < 33
|
275
|
+
|
276
|
+
input = String.fromCharCode(e.which)
|
277
|
+
|
278
|
+
# Char is a number or a space
|
279
|
+
!!/[\d\s]/.test(input)
|
280
|
+
|
281
|
+
restrictCardNumber = (e) ->
|
282
|
+
$target = $(e.currentTarget)
|
283
|
+
digit = String.fromCharCode(e.which)
|
284
|
+
return unless /^\d+$/.test(digit)
|
285
|
+
|
286
|
+
return if hasTextSelected($target)
|
287
|
+
|
288
|
+
# Restrict number of digits
|
289
|
+
value = ($target.val() + digit).replace(/\D/g, '')
|
290
|
+
card = cardFromNumber(value)
|
291
|
+
|
292
|
+
if card
|
293
|
+
value.length <= card.length[card.length.length - 1]
|
294
|
+
else
|
295
|
+
# All other cards are 16 digits long
|
296
|
+
value.length <= 16
|
297
|
+
|
298
|
+
restrictExpiry = (e) ->
|
299
|
+
$target = $(e.currentTarget)
|
300
|
+
digit = String.fromCharCode(e.which)
|
301
|
+
return unless /^\d+$/.test(digit)
|
302
|
+
|
303
|
+
return if hasTextSelected($target)
|
304
|
+
|
305
|
+
value = $target.val() + digit
|
306
|
+
value = value.replace(/\D/g, '')
|
307
|
+
|
308
|
+
return false if value.length > 6
|
309
|
+
|
310
|
+
restrictCVC = (e) ->
|
311
|
+
$target = $(e.currentTarget)
|
312
|
+
digit = String.fromCharCode(e.which)
|
313
|
+
return unless /^\d+$/.test(digit)
|
314
|
+
|
315
|
+
return if hasTextSelected($target)
|
316
|
+
|
317
|
+
val = $target.val() + digit
|
318
|
+
val.length <= 4
|
319
|
+
|
320
|
+
setCardType = (e) ->
|
321
|
+
$target = $(e.currentTarget)
|
322
|
+
val = $target.val()
|
323
|
+
cardType = $.payment.cardType(val) or 'unknown'
|
324
|
+
|
325
|
+
unless $target.hasClass(cardType)
|
326
|
+
allTypes = (card.type for card in cards)
|
327
|
+
|
328
|
+
$target.removeClass('unknown')
|
329
|
+
$target.removeClass(allTypes.join(' '))
|
330
|
+
|
331
|
+
$target.addClass(cardType)
|
332
|
+
$target.toggleClass('identified', cardType isnt 'unknown')
|
333
|
+
$target.trigger('payment.cardType', cardType)
|
334
|
+
|
335
|
+
# Public
|
336
|
+
|
337
|
+
# Formatting
|
338
|
+
|
339
|
+
$.payment.fn.formatCardCVC = ->
|
340
|
+
@payment('restrictNumeric')
|
341
|
+
@on('keypress', restrictCVC)
|
342
|
+
this
|
343
|
+
|
344
|
+
$.payment.fn.formatCardExpiry = ->
|
345
|
+
@payment('restrictNumeric')
|
346
|
+
@on('keypress', restrictExpiry)
|
347
|
+
@on('keypress', formatExpiry)
|
348
|
+
@on('keypress', formatForwardSlash)
|
349
|
+
@on('keypress', formatForwardExpiry)
|
350
|
+
@on('keydown', formatBackExpiry)
|
351
|
+
@on('change', reFormatExpiry)
|
352
|
+
@on('input', reFormatExpiry)
|
353
|
+
this
|
354
|
+
|
355
|
+
$.payment.fn.formatCardNumber = ->
|
356
|
+
@payment('restrictNumeric')
|
357
|
+
@on('keypress', restrictCardNumber)
|
358
|
+
@on('keypress', formatCardNumber)
|
359
|
+
@on('keydown', formatBackCardNumber)
|
360
|
+
@on('keyup', setCardType)
|
361
|
+
@on('paste', reFormatCardNumber)
|
362
|
+
@on('change', reFormatCardNumber)
|
363
|
+
@on('input', reFormatCardNumber)
|
364
|
+
@on('input', setCardType)
|
365
|
+
this
|
366
|
+
|
367
|
+
# Restrictions
|
368
|
+
|
369
|
+
$.payment.fn.restrictNumeric = ->
|
370
|
+
@on('keypress', restrictNumeric)
|
371
|
+
this
|
372
|
+
|
373
|
+
# Validations
|
374
|
+
|
375
|
+
$.payment.fn.cardExpiryVal = ->
|
376
|
+
$.payment.cardExpiryVal($(this).val())
|
377
|
+
|
378
|
+
$.payment.cardExpiryVal = (value) ->
|
379
|
+
value = value.replace(/\s/g, '')
|
380
|
+
[month, year] = value.split('/', 2)
|
381
|
+
|
382
|
+
# Allow for year shortcut
|
383
|
+
if year?.length is 2 and /^\d+$/.test(year)
|
384
|
+
prefix = (new Date).getFullYear()
|
385
|
+
prefix = prefix.toString()[0..1]
|
386
|
+
year = prefix + year
|
387
|
+
|
388
|
+
month = parseInt(month, 10)
|
389
|
+
year = parseInt(year, 10)
|
390
|
+
|
391
|
+
month: month, year: year
|
392
|
+
|
393
|
+
$.payment.validateCardNumber = (num) ->
|
394
|
+
num = (num + '').replace(/\s+|-/g, '')
|
395
|
+
return false unless /^\d+$/.test(num)
|
396
|
+
|
397
|
+
card = cardFromNumber(num)
|
398
|
+
return false unless card
|
399
|
+
|
400
|
+
num.length in card.length and
|
401
|
+
(card.luhn is false or luhnCheck(num))
|
402
|
+
|
403
|
+
$.payment.validateCardExpiry = (month, year) ->
|
404
|
+
# Allow passing an object
|
405
|
+
if typeof month is 'object' and 'month' of month
|
406
|
+
{month, year} = month
|
407
|
+
|
408
|
+
return false unless month and year
|
409
|
+
|
410
|
+
month = $.trim(month)
|
411
|
+
year = $.trim(year)
|
412
|
+
|
413
|
+
return false unless /^\d+$/.test(month)
|
414
|
+
return false unless /^\d+$/.test(year)
|
415
|
+
return false unless 1 <= month <= 12
|
416
|
+
|
417
|
+
if year.length == 2
|
418
|
+
if year < 70
|
419
|
+
year = "20#{year}"
|
420
|
+
else
|
421
|
+
year = "19#{year}"
|
422
|
+
|
423
|
+
return false unless year.length == 4
|
424
|
+
|
425
|
+
expiry = new Date(year, month)
|
426
|
+
currentTime = new Date
|
427
|
+
|
428
|
+
# Months start from 0 in JavaScript
|
429
|
+
expiry.setMonth(expiry.getMonth() - 1)
|
430
|
+
|
431
|
+
# The cc expires at the end of the month,
|
432
|
+
# so we need to make the expiry the first day
|
433
|
+
# of the month after
|
434
|
+
expiry.setMonth(expiry.getMonth() + 1, 1)
|
435
|
+
|
436
|
+
expiry > currentTime
|
437
|
+
|
438
|
+
$.payment.validateCardCVC = (cvc, type) ->
|
439
|
+
cvc = $.trim(cvc)
|
440
|
+
return false unless /^\d+$/.test(cvc)
|
441
|
+
|
442
|
+
if type
|
443
|
+
# Check against a explicit card type
|
444
|
+
cvc.length in cardFromType(type)?.cvcLength
|
445
|
+
else
|
446
|
+
# Check against all types
|
447
|
+
cvc.length >= 3 and cvc.length <= 4
|
448
|
+
|
449
|
+
$.payment.cardType = (num) ->
|
450
|
+
return null unless num
|
451
|
+
cardFromNumber(num)?.type or null
|
452
|
+
|
453
|
+
$.payment.formatCardNumber = (num) ->
|
454
|
+
card = cardFromNumber(num)
|
455
|
+
return num unless card
|
456
|
+
|
457
|
+
upperLength = card.length[card.length.length - 1]
|
458
|
+
|
459
|
+
num = num.replace(/\D/g, '')
|
460
|
+
num = num[0...upperLength]
|
461
|
+
|
462
|
+
if card.format.global
|
463
|
+
num.match(card.format)?.join(' ')
|
464
|
+
else
|
465
|
+
groups = card.format.exec(num)
|
466
|
+
return unless groups?
|
467
|
+
groups.shift()
|
468
|
+
groups = $.grep(groups, (n) -> n) # Filter empty groups
|
469
|
+
groups.join(' ')
|
470
|
+
|
471
|
+
$.payment.formatExpiry = (expiry) ->
|
472
|
+
parts = expiry.match(/^\D*(\d{1,2})(\D+)?(\d{1,4})?/)
|
473
|
+
return '' unless parts
|
474
|
+
|
475
|
+
mon = parts[1] || ''
|
476
|
+
sep = parts[2] || ''
|
477
|
+
year = parts[3] || ''
|
478
|
+
|
479
|
+
if year.length > 0 || (sep.length > 0 && !(/\ \/?\ ?/.test(sep)))
|
480
|
+
sep = ' / '
|
481
|
+
|
482
|
+
if mon.length == 1 and mon not in ['0', '1']
|
483
|
+
mon = "0#{mon}"
|
484
|
+
sep = ' / '
|
485
|
+
|
486
|
+
return mon + sep + year
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jquery_payment-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Navin Peiris
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: railties
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: 'jquery.payment library for building credit card forms for the Rails
|
56
|
+
Asset Pipeline '
|
57
|
+
email:
|
58
|
+
- navin.peiris@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- jquery_payment-rails.gemspec
|
69
|
+
- lib/jquery/payment/rails.rb
|
70
|
+
- lib/jquery/payment/rails/engine.rb
|
71
|
+
- lib/jquery/payment/rails/version.rb
|
72
|
+
- lib/jquery_payment-rails.rb
|
73
|
+
- vendor/assets/javascripts/jquery.payment.coffee
|
74
|
+
homepage: https://github.com/navinpeiris/jquery_payment-rails
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.2.2
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: jquery.payment for Rails Asset Pipeline
|
98
|
+
test_files: []
|