cieloz 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc58d2aeb4dcfa87510aebee7ec575afd4fd9a71
4
- data.tar.gz: 7694e9c7a5290050fa512af92f197879354cebc2
3
+ metadata.gz: bafeb0b8ee2b0cc29837ae97e0a5b1c4a423fe22
4
+ data.tar.gz: 228cd850f742e759568869938329499f22e5213f
5
5
  SHA512:
6
- metadata.gz: c60d28b5fcab2951fc0d3008154f460ba16060ddc42a83e82bb15a4979b963ca0d4b716efe1d3f953f3dcaa05e73b13d324a44fd819ee1420ded6a7bccbddc45
7
- data.tar.gz: b3b664d72fcb6792f0607b26ac2e56ea1423d487a2b60a4ec022c9f06697198d7781d50bae9711f7cd5f80ff014354c3b46aa5ae7b5f370853941db7517344d4
6
+ metadata.gz: 369d7b7699e9c31cc23c664f7eb985fc35ef9cfcf6465204e2e50357db8c5fc5d04410560c718c1e95b1b7e57b717ce4e8ca8508d067e137b12d96cf4b1861b2
7
+ data.tar.gz: 5c9f92497d3396a7a81ea34302fb022d477dedd32ab92d47d380a32b70355b04907111130c0a17b40f0c6d224c56d5196ce0c992e6b6d264640afb1921307b21
@@ -13,6 +13,8 @@ en:
13
13
  cieloz/requisicao_transacao/dados_portador:
14
14
  attributes:
15
15
  numero:
16
+ invalid_diners: should have 14 digits
17
+ invalid_amex: should have 15 digits
16
18
  invalid: should have 16 digits
17
19
  codigo_seguranca:
18
20
  invalid: should have 3 or 4 digits
@@ -13,6 +13,8 @@ pt-BR:
13
13
  cieloz/requisicao_transacao/dados_portador:
14
14
  attributes:
15
15
  numero:
16
+ invalid_diners: deve ter 14 dígitos
17
+ invalid_amex: deve ter 15 dígitos
16
18
  invalid: deve ter 16 dígitos
17
19
  codigo_seguranca:
18
20
  invalid: deve ter 3 ou 4 dígitos
@@ -20,12 +20,9 @@ class Cieloz::RequisicaoTransacao
20
20
  portador.numero.gsub! ' ', ''
21
21
  end
22
22
 
23
- validates :numero, format: { with: /\A\d{16}\z/ }
24
23
  validates :codigo_seguranca, format: { with: /\A(\d{3}|\d{4})\z/ }
25
-
26
- validate :valida_validade
27
-
28
24
  validates :indicador, presence: true
25
+ validate :valida_validade
29
26
 
30
27
  def self.map(source, opts={})
31
28
  num, val, cod, nome = attrs_from source, opts,
@@ -12,7 +12,11 @@ class Cieloz::RequisicaoTransacao < Cieloz::Requisicao
12
12
 
13
13
  validate :nested_validations
14
14
 
15
- validates :dados_portador, presence: true, if: "Cieloz::Configuracao.store_mode?"
15
+ with_options if: "Cieloz::Configuracao.store_mode?" do |c|
16
+ c.validates :dados_portador, presence: true
17
+ c.validate :valida_digitos_numero_cartao
18
+ end
19
+
16
20
  validates :dados_pedido, :forma_pagamento, presence: true
17
21
 
18
22
  with_options unless: "@forma_pagamento.nil?" do |txn|
@@ -146,4 +150,19 @@ class Cieloz::RequisicaoTransacao < Cieloz::Requisicao
146
150
  bin: (@dados_portador.numero.to_s[0..5] unless @dados_portador.nil?)
147
151
  }
148
152
  end
153
+
154
+ private
155
+ def valida_digitos_numero_cartao
156
+ if dados_portador and forma_pagamento and bandeira = forma_pagamento.bandeira
157
+ numero = dados_portador.numero.to_s
158
+ case bandeira.to_s
159
+ when Cieloz::Bandeiras::DINERS
160
+ dados_portador.errors.add :numero, :invalid_diners unless numero =~ /\A\d{14}\z/
161
+ when Cieloz::Bandeiras::AMEX
162
+ dados_portador.errors.add :numero, :invalid_amex unless numero =~ /\A\d{15}\z/
163
+ else
164
+ dados_portador.errors.add :numero, :invalid unless numero =~ /\A\d{16}\z/
165
+ end
166
+ end
167
+ end
149
168
  end
@@ -1,3 +1,3 @@
1
1
  module Cieloz
2
- VERSION = "0.0.16"
2
+ VERSION = "0.0.17"
3
3
  end
@@ -17,10 +17,6 @@ describe Cieloz::RequisicaoTransacao::DadosPortador do
17
17
  let(:invalid_number) {
18
18
  I18n.t 'activemodel.errors.models.cieloz/requisicao_transacao/dados_portador.attributes.numero.invalid'
19
19
  }
20
- it { must_allow_value :numero, 1234567890123456 }
21
- it { wont_allow_value :numero, 123456789012345, message: invalid_number }
22
- it { wont_allow_value :numero, 12345678901234567, message: invalid_number }
23
- it { wont_allow_value :numero, "ABC4567890123456", message: invalid_number }
24
20
 
25
21
  it {
26
22
  (100..9999).step(123).each {|val|
@@ -394,4 +390,42 @@ describe Cieloz::RequisicaoTransacao do
394
390
  msg = "Installment should be greater than or equal to R$ 5,00"
395
391
  assert_equal msg, subject.dados_pedido.errors[:valor].first
396
392
  end
393
+
394
+ describe "validates credit card number format" do
395
+ after do
396
+ Cieloz::Configuracao.reset!
397
+ end
398
+
399
+ def self.validate_number_of_credit_card_digits_for(flag, digits)
400
+ describe flag do
401
+ let(:pg) { subject.class::FormaPagamento.new.credito flag }
402
+
403
+ before do
404
+ Cieloz::Configuracao.store_mode!
405
+ subject.forma_pagamento = pg
406
+ end
407
+
408
+ it "accepts credit card numbers with #{digits} digits" do
409
+ subject.dados_portador = subject.class::DadosPortador.new numero: '1' * digits
410
+ subject.valid?
411
+ subject.dados_portador.errors[:numero].must_be_empty
412
+ end
413
+
414
+ it "rejects credit card numbers with other formats" do
415
+ ['1' * (digits - 1), '1' * (digits + 1), 'ABC4567890123456'].each do |number|
416
+ subject.dados_portador = subject.class::DadosPortador.new numero: number
417
+ subject.valid?
418
+ subject.dados_portador.errors[:numero].wont_be_empty
419
+ end
420
+ end
421
+ end
422
+ end
423
+
424
+ validate_number_of_credit_card_digits_for Cieloz::Bandeiras::DINERS, 14
425
+ validate_number_of_credit_card_digits_for Cieloz::Bandeiras::AMEX, 15
426
+ validate_number_of_credit_card_digits_for Cieloz::Bandeiras::VISA, 16
427
+ validate_number_of_credit_card_digits_for Cieloz::Bandeiras::MASTERCARD, 16
428
+ validate_number_of_credit_card_digits_for Cieloz::Bandeiras::ELO, 16
429
+ validate_number_of_credit_card_digits_for Cieloz::Bandeiras::DISCOVER, 16
430
+ end
397
431
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cieloz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fábio Luiz Nery de Miranda