credit_card_validations 5.0.0 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +3 -4
- data/Changelog.md +15 -0
- data/README.md +12 -0
- data/lib/credit_card_validations/configuration.rb +9 -0
- data/lib/credit_card_validations/version.rb +1 -1
- data/lib/credit_card_validations.rb +23 -2
- data/lib/data/brands.yaml +3 -5
- data/spec/credit_card_validations_spec.rb +33 -0
- data/spec/fixtures/overrided_brands.yml +19 -0
- data/spec/test_helper.rb +1 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c955ab578ccc68fa1525166a326408c8f7ceedb16dfd197b4cee363453f4148c
|
4
|
+
data.tar.gz: f66d2c0969e1aac24c04463633e4466c997527b4d9b3a11f36914d207eea08dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96231d43a74789045abf1df806f085d649fb9400c749f2334eaa08771fcc2e369831ae65a74698484fe2b8a531241e8effa4dc6d5258f29523af33319dae435c
|
7
|
+
data.tar.gz: 4926b30dce4ca818b0ab18e7711ba96b8145a461703c3659c3eff1368fa860760febb476d1086b7f7addce5608ee501986c30a2dcb13cdab68f26a78a98e18d7
|
data/.github/workflows/build.yml
CHANGED
@@ -19,12 +19,11 @@ jobs:
|
|
19
19
|
env:
|
20
20
|
RAILS_VERSION: ${{ matrix.rails }}
|
21
21
|
steps:
|
22
|
-
- uses: actions/checkout@
|
23
|
-
- uses:
|
22
|
+
- uses: actions/checkout@v3
|
23
|
+
- uses: ruby/setup-ruby@v1
|
24
24
|
with:
|
25
25
|
ruby-version: ${{ matrix.ruby-version }}
|
26
|
+
bundler-cache: true
|
26
27
|
- name: Run tests
|
27
28
|
run: |
|
28
|
-
gem install bundler -v '< 2'
|
29
|
-
bundle install
|
30
29
|
bundle exec rake
|
data/Changelog.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
# 6.0.0
|
2
|
+
* changes to discover branch
|
3
|
+
* allows to configure usage of own yaml brands file
|
4
|
+
|
5
|
+
# 5.0.0
|
6
|
+
* rails 7 support
|
7
|
+
* drop rails support < 5.2
|
8
|
+
|
9
|
+
# 4.1.0
|
10
|
+
* changes to disover and maesto rules
|
11
|
+
|
12
|
+
# 4.0.0
|
13
|
+
* support rails 6
|
14
|
+
* test against ruby 3.0, drop ruby 2.1 support
|
15
|
+
|
1
16
|
# 3.5.1
|
2
17
|
* Bump activemodel and activesupport versions
|
3
18
|
|
data/README.md
CHANGED
@@ -146,6 +146,18 @@ require 'credit_card_validations/plugins/laser'
|
|
146
146
|
require 'credit_card_validations/plugins/diners_us'
|
147
147
|
```
|
148
148
|
|
149
|
+
|
150
|
+
### Configuration
|
151
|
+
|
152
|
+
In order to override default data source you can copy [original one](https://github.com/didww/credit_card_validations/blob/master/lib/data/brands.yaml) , change it and configure during rails initializer
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
CreditCardValidations.configure do |config|
|
156
|
+
config.source = '/path/to/my_brands.yml'
|
157
|
+
end
|
158
|
+
```
|
159
|
+
|
160
|
+
|
149
161
|
## Contributing
|
150
162
|
|
151
163
|
1. Fork it
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'credit_card_validations/version'
|
2
|
+
require 'credit_card_validations/configuration'
|
2
3
|
require 'credit_card_validations/error'
|
3
4
|
require 'active_model'
|
4
5
|
require 'active_support/core_ext'
|
@@ -14,16 +15,36 @@ module CreditCardValidations
|
|
14
15
|
autoload :Factory, 'credit_card_validations/factory'
|
15
16
|
autoload :Mmi, 'credit_card_validations/mmi'
|
16
17
|
|
18
|
+
attr_accessor :configuration
|
19
|
+
|
20
|
+
def self.configuration
|
21
|
+
@configuration ||= Configuration.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.reset
|
25
|
+
@configuration = Configuration.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.configure
|
29
|
+
yield(configuration)
|
30
|
+
reload!
|
31
|
+
end
|
17
32
|
|
18
33
|
def self.add_brand(key, rules, options = {})
|
19
34
|
Detector.add_brand(key, rules, options)
|
20
35
|
end
|
21
36
|
|
22
|
-
|
37
|
+
def self.source
|
38
|
+
configuration.source || File.join(File.join(File.dirname(__FILE__)), 'data', 'brands.yaml')
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.data
|
42
|
+
YAML.load_file(source) || {}
|
43
|
+
end
|
23
44
|
|
24
45
|
def self.reload!
|
25
46
|
Detector.brands = {}
|
26
|
-
|
47
|
+
data.each do |key, data|
|
27
48
|
add_brand(key, data.fetch(:rules), data.fetch(:options, {}))
|
28
49
|
end
|
29
50
|
end
|
data/lib/data/brands.yaml
CHANGED
@@ -486,16 +486,14 @@
|
|
486
486
|
- '303'
|
487
487
|
- '304'
|
488
488
|
- '305'
|
489
|
+
- '3095'
|
490
|
+
- '36'
|
489
491
|
- '38'
|
490
492
|
- '39'
|
491
493
|
- '60110'
|
492
494
|
- '60112'
|
493
495
|
- '60113'
|
494
|
-
- '
|
495
|
-
- '601141'
|
496
|
-
- '601142'
|
497
|
-
- '601143'
|
498
|
-
- '601144'
|
496
|
+
- '60114'
|
499
497
|
- '601174'
|
500
498
|
- '601177'
|
501
499
|
- '601178'
|
@@ -7,6 +7,39 @@ describe CreditCardValidations do
|
|
7
7
|
CreditCardValidations.reload!
|
8
8
|
end
|
9
9
|
|
10
|
+
|
11
|
+
describe 'configure' do
|
12
|
+
|
13
|
+
let(:number) { '6111111180456137' }
|
14
|
+
|
15
|
+
before do
|
16
|
+
expect(card_detector.valid?(:discover)).must_equal false
|
17
|
+
CreditCardValidations.configure do |config|
|
18
|
+
config.source = OVERRIDED_BRANDS_FILE
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:card_detector) {
|
23
|
+
detector(number)
|
24
|
+
}
|
25
|
+
|
26
|
+
it 'should generate overrided discover' do
|
27
|
+
discover = CreditCardValidations::Factory.random(:discover)
|
28
|
+
expect(detector(discover).valid?('DiscoverBrand')).must_equal true
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should detect patched discover' do
|
32
|
+
expect(card_detector.valid?(:discover)).must_equal true
|
33
|
+
expect(card_detector.valid?(:visa)).must_equal false
|
34
|
+
end
|
35
|
+
|
36
|
+
after do
|
37
|
+
CreditCardValidations.reset
|
38
|
+
CreditCardValidations.reload!
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
10
43
|
describe 'MMI' do
|
11
44
|
it 'should detect issuer category' do
|
12
45
|
d = detector(VALID_NUMBERS[:visa].first)
|
data/spec/test_helper.rb
CHANGED
@@ -15,4 +15,5 @@ require 'models/credit_card'
|
|
15
15
|
|
16
16
|
VALID_NUMBERS = YAML.load_file File.join(File.dirname(__FILE__), 'fixtures/valid_cards.yml')
|
17
17
|
INVALID_NUMBERS = YAML.load_file File.join(File.dirname(__FILE__), 'fixtures/invalid_cards.yml')
|
18
|
+
OVERRIDED_BRANDS_FILE = File.join(File.dirname(__FILE__), 'fixtures/overrided_brands.yml')
|
18
19
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: credit_card_validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -124,6 +124,7 @@ files:
|
|
124
124
|
- credit_card_validations.gemspec
|
125
125
|
- lib/active_model/credit_card_number_validator.rb
|
126
126
|
- lib/credit_card_validations.rb
|
127
|
+
- lib/credit_card_validations/configuration.rb
|
127
128
|
- lib/credit_card_validations/detector.rb
|
128
129
|
- lib/credit_card_validations/error.rb
|
129
130
|
- lib/credit_card_validations/factory.rb
|
@@ -139,6 +140,7 @@ files:
|
|
139
140
|
- spec/credit_card_validations_spec.rb
|
140
141
|
- spec/factory_spec.rb
|
141
142
|
- spec/fixtures/invalid_cards.yml
|
143
|
+
- spec/fixtures/overrided_brands.yml
|
142
144
|
- spec/fixtures/valid_cards.yml
|
143
145
|
- spec/models/credit_card.rb
|
144
146
|
- spec/string_spec.rb
|
@@ -175,6 +177,7 @@ test_files:
|
|
175
177
|
- spec/credit_card_validations_spec.rb
|
176
178
|
- spec/factory_spec.rb
|
177
179
|
- spec/fixtures/invalid_cards.yml
|
180
|
+
- spec/fixtures/overrided_brands.yml
|
178
181
|
- spec/fixtures/valid_cards.yml
|
179
182
|
- spec/models/credit_card.rb
|
180
183
|
- spec/string_spec.rb
|