cieloz 0.0.16 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bafeb0b8ee2b0cc29837ae97e0a5b1c4a423fe22
|
4
|
+
data.tar.gz: 228cd850f742e759568869938329499f22e5213f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 369d7b7699e9c31cc23c664f7eb985fc35ef9cfcf6465204e2e50357db8c5fc5d04410560c718c1e95b1b7e57b717ce4e8ca8508d067e137b12d96cf4b1861b2
|
7
|
+
data.tar.gz: 5c9f92497d3396a7a81ea34302fb022d477dedd32ab92d47d380a32b70355b04907111130c0a17b40f0c6d224c56d5196ce0c992e6b6d264640afb1921307b21
|
data/config/locales/en.yml
CHANGED
data/config/locales/pt-BR.yml
CHANGED
@@ -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
|
-
|
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
|
data/lib/cieloz/version.rb
CHANGED
@@ -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
|