Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: add VR support #120

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,35 @@ $ gem install credit_card_validations


The following issuing institutes are accepted:
| Name | Key |
--------------------- | ------------|

| Name | Key |
--------------------- | ------------|
[American Express](http://en.wikipedia.org/wiki/American_Express) | :amex
[China UnionPay](http://en.wikipedia.org/wiki/China_UnionPay) | :unionpay
[China UnionPay](http://en.wikipedia.org/wiki/China_UnionPay) | :unionpay
[Dankort](http://en.wikipedia.org/wiki/Dankort) | :dankort
[Diners Club](http://en.wikipedia.org/wiki/Diners_Club_International) | :diners
[Diners Club](http://en.wikipedia.org/wiki/Diners_Club_International) | :diners
[Elo](https://pt.wikipedia.org/wiki/Elo_Participa%C3%A7%C3%B5es_S/A) | :elo
[Discover](http://en.wikipedia.org/wiki/Discover_Card) | :discover
[Hipercard](http://pt.wikipedia.org/wiki/Hipercard) | :hipercard
[Discover](http://en.wikipedia.org/wiki/Discover_Card) | :discover
[Hipercard](http://pt.wikipedia.org/wiki/Hipercard) | :hipercard
[JCB](http://en.wikipedia.org/wiki/Japan_Credit_Bureau) | :jcb
[Maestro](http://en.wikipedia.org/wiki/Maestro_%28debit_card%29) | :maestro
[MasterCard](http://en.wikipedia.org/wiki/MasterCard) | :mastercard
[MIR](http://www.nspk.ru/en/cards-mir/) | :mir
[Rupay](http://en.wikipedia.org/wiki/RuPay) | :rupay
[Rupay](http://en.wikipedia.org/wiki/RuPay) | :rupay
[Solo](http://en.wikipedia.org/wiki/Solo_(debit_card)) | :solo
[Switch](http://en.wikipedia.org/wiki/Switch_(debit_card)) | :switch
[Visa](http://en.wikipedia.org/wiki/Visa_Inc.) | :visa
[Switch](http://en.wikipedia.org/wiki/Switch_(debit_card)) | :switch
[Visa](http://en.wikipedia.org/wiki/Visa_Inc.) | :visa
[VR Alimentação](https://www.vr.com.br/) | :vr_alimentacao
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guizaols can you please explain what is the difference between this brands , isn't it 1 single brand to validate, what are use cases to have 3 different types and not only 1 vr

[VR Refeição](https://www.vr.com.br/) | :vr_refeicao
[VR Multi (Alimentação + Refeição)](https://www.vr.com.br/) | :vr_multi



The following are supported with plugins

| Name | Key |
--------------------- | ------------|
[Diners Club US](http://en.wikipedia.org/wiki/Diners_Club_International#MasterCard_alliance) | :diners_us
| Name | Key |
--------------------- | ------------|
[Diners Club US](http://en.wikipedia.org/wiki/Diners_Club_International#MasterCard_alliance) | :diners_us
[EnRoute](https://en.wikipedia.org/wiki/EnRoute_(credit_card)) | :en_route
[Laser](https://en.wikipedia.org/wiki/Laser_%28debit_card%29) | :laser

Expand Down
3 changes: 1 addition & 2 deletions lib/credit_card_validations/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ def valid_credit_card_brand?(*brands)
def credit_card_brand_name
CreditCardValidations::Detector.new(self).brand_name
end

end
end
30 changes: 30 additions & 0 deletions lib/data/brands.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,36 @@
- '633303'
- '633301'
- '633300'
:vr_refeicao:
:rules:
- :length:
- 16
:prefixes:
- '627416'
- '637202'
- '637200'
:options:
:brand_name: VR Refeição
:vr_alimentacao:
:rules:
- :length:
- 16
:prefixes:
- '637036'
- '637001'
- '637200'
:options:
:brand_name: VR Alimentação
::vr_multi:
:rules:
- :length:
- 16
:prefixes:
- '637200'
- '637430'
- '637441'
:options:
:brand_name: VR Multi (VR + VA)
:maestro:
:rules:
- :length:
Expand Down
2 changes: 1 addition & 1 deletion spec/active_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

describe 'Except Amex and Maestro brand' do
it 'should reject all other valid numbers' do
VALID_NUMBERS.except(:amex, :maestro).each do |_, numbers|
VALID_NUMBERS.except(:amex, :maestro, :vr_refeicao).each do |_, numbers|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

describe 'Except Amex and Maestro brand' now is not reflecting real test, also there is new describe block below
describe 'Only Amex and Mestro brands' that is testing opposite behaviour of this describe block

maybe it is better just to remove this change

card = model
card.number = numbers.first
expect(card.valid?).must_equal false
Expand Down
10 changes: 0 additions & 10 deletions spec/credit_card_validations_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
require_relative 'test_helper'

describe CreditCardValidations do


before do
CreditCardValidations.reload!
end


describe 'configure' do

let(:number) { '6111111180456137' }

before do
Expand Down Expand Up @@ -37,7 +33,6 @@
CreditCardValidations.reset
CreditCardValidations.reload!
end

end

describe 'MMI' do
Expand Down Expand Up @@ -65,10 +60,8 @@
CreditCardValidations::Luhn.expects(:valid?).never
expect(card_detector.valid?(:unionpay)).must_equal true
end

end


it 'should check luhn' do
VALID_NUMBERS.each do |brand, card_numbers|
if has_luhn_check_rule?(brand)
Expand Down Expand Up @@ -136,9 +129,7 @@


describe 'adding/removing brand' do

describe 'adding rules' do

let(:voyager_number) { '869926275400212' }

it 'should validate number as voyager' do
Expand Down Expand Up @@ -204,5 +195,4 @@ def detector(number)
def has_luhn_check_rule?(key)
CreditCardValidations::Detector.has_luhn_check_rule?(key)
end

end
6 changes: 5 additions & 1 deletion spec/fixtures/valid_cards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,8 @@
- '6504 9799 9991 0279'
- '6516 5299 9991 0328'
:mir:
- 2202 1234 1234 1234
- '2202 1234 1234 1234'
:vr_alimentacao:
- 6370 3600 2847 1958
:vr_refeicao:
- 6274 1600 1473 6274
20 changes: 18 additions & 2 deletions spec/string_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
require 'credit_card_validations/string'

describe 'String ext' do

let(:mastercard) { CreditCardValidations::Factory.random(:mastercard) }
let(:visa) { CreditCardValidations::Factory.random(:visa) }
let(:vr_alimentacao) { CreditCardValidations::Factory.random(:vr_alimentacao) }
let(:vr_refeicao) { CreditCardValidations::Factory.random(:vr_refeicao) }
let(:invalid) { INVALID_NUMBERS.sample }

it 'should allow detect brand for mastercard' do
Expand All @@ -29,4 +30,19 @@
expect(invalid.valid_credit_card_brand?(:visa, :amex)).must_equal false
end

end
it 'should allow detect brand for VR Alimentação' do
expect(vr_alimentacao.credit_card_brand).must_equal :vr_alimentacao
expect(vr_alimentacao.credit_card_brand_name).must_equal 'VR Alimentação'
expect(vr_alimentacao.valid_credit_card_brand?(:vr_alimentacao)).must_equal true
expect(vr_alimentacao.valid_credit_card_brand?('VR Alimentação')).must_equal true
expect(vr_alimentacao.valid_credit_card_brand?(:visa, :amex)).must_equal false
end

it 'should allow detect brand for VR Refeição' do
expect(vr_refeicao.credit_card_brand).must_equal :vr_refeicao
expect(vr_refeicao.credit_card_brand_name).must_equal 'VR Refeição'
expect(vr_refeicao.valid_credit_card_brand?(:vr_refeicao)).must_equal true
expect(vr_refeicao.valid_credit_card_brand?('VR Refeição')).must_equal true
expect(vr_refeicao.valid_credit_card_brand?(:visa, :amex)).must_equal false
end
end