credit_card_type_field 0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +1 -0
- data/credit_card_type_field.gemspec +19 -0
- data/lib/credit_card_type_field/version.rb +3 -0
- data/lib/credit_card_type_field/view_helper.rb +25 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/view_helper_spec.rb +5 -0
- data/vendor/assets/images/credit_cards/american_express_32.png +0 -0
- data/vendor/assets/images/credit_cards/credit_card_bg.png +0 -0
- data/vendor/assets/images/credit_cards/diners_club_32.png +0 -0
- data/vendor/assets/images/credit_cards/mastercard_32.png +0 -0
- data/vendor/assets/images/credit_cards/not_valid_32.png +0 -0
- data/vendor/assets/images/credit_cards/visa_32.png +0 -0
- data/vendor/assets/javascripts/credit_card_field.coffee +23 -0
- data/vendor/assets/stylesheets/credit_card_field.css.scss +80 -0
- metadata +65 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 benzhang
|
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,44 @@
|
|
1
|
+
# CreditCardField
|
2
|
+
|
3
|
+
Credit card type field auto detected by the credit card number.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
Only support Rails 3.1+ with jQuery
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'credit_card_type_field'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install credit_card_type_field
|
19
|
+
|
20
|
+
Add to assets pipeline
|
21
|
+
|
22
|
+
application.js
|
23
|
+
|
24
|
+
$ //= require credit_card_type_field
|
25
|
+
|
26
|
+
application.css
|
27
|
+
|
28
|
+
$ *= require credit_card_type_field
|
29
|
+
|
30
|
+
## Tutorial
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
## Demo
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'credit_card_type_field/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "credit_card_type_field"
|
8
|
+
gem.version = CreditCardField::VERSION
|
9
|
+
gem.authors = ["benzhang"]
|
10
|
+
gem.email = ["bzbnhang@gmail.com"]
|
11
|
+
gem.description = %q{Credit Card type}
|
12
|
+
gem.summary = %q{A nice graphic Credit Card type field}
|
13
|
+
gem.homepage = "https://github.com/BenZhang/credit_card_type_field"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module CreditCardTypeField
|
2
|
+
module ViewHelper
|
3
|
+
|
4
|
+
def credit_card_type_field(method, options = {})
|
5
|
+
options[:card_number_selector] ||= "##{@object_name}_credit_card_no"
|
6
|
+
options[:accept_types] ||= %w(visa master american_express diners_club)
|
7
|
+
html = '<ul class="credit-card-type clearfix">'.html_safe
|
8
|
+
options[:accept_types].each {|type| html << "<li class=\"icon #{type} #{'active' if self.object.try(method) == type}\">#{type.camelize}</li>".html_safe }
|
9
|
+
html << %Q(<li class="icon not_valid #{'active' unless self.object.try(method)}">Invalid Card</li>
|
10
|
+
<li class="hint not_valid"><strong>Not a Valid Credit Card Number</strong></li>
|
11
|
+
</ul>).html_safe
|
12
|
+
html << hidden_field(method, rel: 'credit-card-type')
|
13
|
+
html << %Q(
|
14
|
+
<script>
|
15
|
+
$('input[rel=credit-card-type]').closest('form').find('#{options[:card_number_selector]}').keyup(CreditCardField.keyup);
|
16
|
+
</script>
|
17
|
+
).html_safe
|
18
|
+
end
|
19
|
+
|
20
|
+
def credit_card_type_field_tag(object_name, method, options = {})
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Configure Rails Environment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
# require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
|
+
require 'rspec/rails'
|
6
|
+
# require 'capybara/rspec'
|
7
|
+
|
8
|
+
# Capybara.javascript_driver = :selenium
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.mock_with :mocha
|
11
|
+
end
|
12
|
+
|
13
|
+
# Rails.backtrace_cleaner.remove_silencers!
|
14
|
+
|
15
|
+
# Load support files
|
16
|
+
# Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class @CreditCardType
|
2
|
+
constructor: (number) ->
|
3
|
+
@card_number = number.replace(/[ -]/g, '')
|
4
|
+
|
5
|
+
cardType: ->
|
6
|
+
visaCard = /^4[0-9]{12}(?:[0-9]{3})?$/
|
7
|
+
masterCard = /^5[1-5][0-9]{14}$/
|
8
|
+
americanExpress = /^3[47][0-9]{13}$/
|
9
|
+
dinerCard = /^3(?:0[0-5]|[68][0-9])[0-9]{11}$/
|
10
|
+
return 'visa' if visaCard.test(@card_number)
|
11
|
+
return 'master' if masterCard.test(@card_number)
|
12
|
+
return 'american_express' if americanExpress.test(@card_number)
|
13
|
+
return 'diners_club' if dinerCard.test(@card_number)
|
14
|
+
'not_valid'
|
15
|
+
|
16
|
+
@CreditCardField = {
|
17
|
+
keyup: (e)->
|
18
|
+
cardType = new CreditCardType($(this).val()).cardType()
|
19
|
+
form = $(this).closest('form')
|
20
|
+
form.find(".credit-card-type li").removeClass('active')
|
21
|
+
form.find(".credit-card-type .#{cardType}").addClass('active')
|
22
|
+
form.find('input[rel=credit-card-type]').val(cardType)
|
23
|
+
}
|
@@ -0,0 +1,80 @@
|
|
1
|
+
.credit-card-type {
|
2
|
+
margin:-10px 0 0 0;
|
3
|
+
li {
|
4
|
+
display:inline-block;
|
5
|
+
&.icon {
|
6
|
+
width:30px;
|
7
|
+
height:20px;
|
8
|
+
text-indent:-999em;
|
9
|
+
background-position:center;
|
10
|
+
opacity:0.3;
|
11
|
+
filter: alpha(opacity = 30);
|
12
|
+
&.visa { background-image:url('/assets/credit_cards/visa_32.png');}
|
13
|
+
&.master { background-image:url('/assets/credit_cards/mastercard_32.png');}
|
14
|
+
&.diners_club { background-image:url('/assets/credit_cards/diners_club_32.png');}
|
15
|
+
&.american_express { background-image:url('/assets/credit_cards/american_express_32.png');}
|
16
|
+
&.not_valid { background-image:url('/assets/credit_cards/not_valid_32.png');}
|
17
|
+
&.active { opacity:1; filter: alpha(opacity = 100); }
|
18
|
+
}
|
19
|
+
&.hint {
|
20
|
+
display:none;
|
21
|
+
margin-left:2px;
|
22
|
+
color:#f00;
|
23
|
+
font-size:90%;
|
24
|
+
&.active { display:inline-block; }
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
.credit-card-form {
|
30
|
+
label.cc-label {
|
31
|
+
height:115px;
|
32
|
+
padding:10px;
|
33
|
+
&:hover { background:#f5f5f5; }
|
34
|
+
&.active { background:#eee; box-shadow:inset 0 0 15px #ccc; border-color:#ccc; }
|
35
|
+
}
|
36
|
+
.cc-label {
|
37
|
+
margin-bottom:10px;
|
38
|
+
padding:10px 0;
|
39
|
+
border-radius:5px;
|
40
|
+
border:1px solid transparent;
|
41
|
+
.cc-template {
|
42
|
+
float:left;
|
43
|
+
border-radius:5px;
|
44
|
+
font-weight:bold;
|
45
|
+
color:#fff;
|
46
|
+
width:166px;
|
47
|
+
height:117px;
|
48
|
+
background:url(/assets/credit_cards/credit_card_bg.png);
|
49
|
+
overflow:hidden;
|
50
|
+
padding:0 5px 0 15px;
|
51
|
+
.cc-number {
|
52
|
+
padding:50px 0 10px 0;
|
53
|
+
font-size:16px;
|
54
|
+
letter-spacing:2px;
|
55
|
+
}
|
56
|
+
.cc-name {
|
57
|
+
float:left;
|
58
|
+
width:120px;
|
59
|
+
}
|
60
|
+
.cc-type {
|
61
|
+
float:right;
|
62
|
+
text-indent:-999em;
|
63
|
+
span {
|
64
|
+
display:block;
|
65
|
+
width:30px;
|
66
|
+
height:20px;
|
67
|
+
background-position:center;
|
68
|
+
&.visa { background-image:url('/assets/credit_cards/visa_32.png');}
|
69
|
+
&.master { background-image:url('/assets/credit_cards/mastercard_32.png');}
|
70
|
+
&.diners_club { background-image:url('/assets/credit_cards/diners_club_32.png');}
|
71
|
+
&.american_express { background-image:url('/assets/credit_cards/american_express_32.png');}
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
.cc-details {
|
76
|
+
padding-left:210px;
|
77
|
+
p:last-child { margin:0; }
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: credit_card_type_field
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.9'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- benzhang
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-30 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Credit Card type
|
15
|
+
email:
|
16
|
+
- bzbnhang@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- credit_card_type_field.gemspec
|
27
|
+
- lib/credit_card_type_field/version.rb
|
28
|
+
- lib/credit_card_type_field/view_helper.rb
|
29
|
+
- spec/spec_helper.rb
|
30
|
+
- spec/view_helper_spec.rb
|
31
|
+
- vendor/assets/images/credit_cards/american_express_32.png
|
32
|
+
- vendor/assets/images/credit_cards/credit_card_bg.png
|
33
|
+
- vendor/assets/images/credit_cards/diners_club_32.png
|
34
|
+
- vendor/assets/images/credit_cards/mastercard_32.png
|
35
|
+
- vendor/assets/images/credit_cards/not_valid_32.png
|
36
|
+
- vendor/assets/images/credit_cards/visa_32.png
|
37
|
+
- vendor/assets/javascripts/credit_card_field.coffee
|
38
|
+
- vendor/assets/stylesheets/credit_card_field.css.scss
|
39
|
+
homepage: https://github.com/BenZhang/credit_card_type_field
|
40
|
+
licenses: []
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.8.24
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: A nice graphic Credit Card type field
|
63
|
+
test_files:
|
64
|
+
- spec/spec_helper.rb
|
65
|
+
- spec/view_helper_spec.rb
|