cieloz 0.0.8 → 0.0.9
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.
- data/config/locales/en.yml +22 -1
- data/config/locales/pt-BR.yml +22 -1
- data/lib/cieloz/bandeiras.rb +5 -5
- data/lib/cieloz/requisicao_transacao/dados_pedido.rb +5 -5
- data/lib/cieloz/requisicao_transacao/dados_portador.rb +12 -10
- data/lib/cieloz/requisicao_transacao.rb +6 -7
- data/lib/cieloz/version.rb +1 -1
- data/test/unit/bandeiras_operacoes_test.rb +1 -2
- data/test/unit/validations_test.rb +27 -20
- metadata +8 -2
data/config/locales/en.yml
CHANGED
@@ -5,7 +5,28 @@ en:
|
|
5
5
|
cieloz/requisicao_transacao:
|
6
6
|
attributes:
|
7
7
|
autorizar:
|
8
|
+
inclusion: should be in [0,1,2,3,4]
|
8
9
|
authentication_not_supported: Authentication not supported
|
9
10
|
direct_auth_available_for_credit_only: Direct auth available for credit only
|
10
|
-
|
11
|
+
capturar:
|
12
|
+
inclusion: should be true or false
|
13
|
+
cieloz/requisicao_transacao/dados_portador:
|
14
|
+
attributes:
|
15
|
+
numero:
|
16
|
+
invalid: should have 16 digits
|
17
|
+
validade:
|
18
|
+
invalid: should be in YYYYDD format
|
19
|
+
codigo_seguranca:
|
20
|
+
invalid: should have 3 or 4 digits
|
21
|
+
cieloz/requisicao_transacao/dados_pedido:
|
22
|
+
attributes:
|
23
|
+
idioma:
|
24
|
+
inclusion: should be PT (Portuguese), EN (English) or ES (Spanish)
|
25
|
+
valor:
|
11
26
|
minimum_installment_not_satisfied: Installment should be greater than or equal to R$ 5,00
|
27
|
+
cieloz/requisicao_transacao/forma_pagamento:
|
28
|
+
attributes:
|
29
|
+
bandeira:
|
30
|
+
blank: choose credit card flag
|
31
|
+
inclusion: choose credit card flag
|
32
|
+
|
data/config/locales/pt-BR.yml
CHANGED
@@ -5,7 +5,28 @@ pt-BR:
|
|
5
5
|
cieloz/requisicao_transacao:
|
6
6
|
attributes:
|
7
7
|
autorizar:
|
8
|
+
inclusion: deveria estar entre [0,1,2,3,4]
|
8
9
|
authentication_not_supported: Bandeira não possui programa de autenticação
|
9
10
|
direct_auth_available_for_credit_only: Autorização Direta disponível apenas em operações de crédito
|
10
|
-
|
11
|
+
capturar:
|
12
|
+
inclusion: deveria ser true ou false
|
13
|
+
cieloz/requisicao_transacao/dados_portador:
|
14
|
+
attributes:
|
15
|
+
numero:
|
16
|
+
invalid: deve ter 16 dígitos
|
17
|
+
validade:
|
18
|
+
invalid: deve estar no formato YYYYDD
|
19
|
+
codigo_seguranca:
|
20
|
+
invalid: deve ter 3 ou 4 dígitos
|
21
|
+
cieloz/requisicao_transacao/dados_pedido:
|
22
|
+
attributes:
|
23
|
+
idioma:
|
24
|
+
inclusion: deveria ser PT (Português), EN (Inglês) ou ES (Espanhol)
|
25
|
+
valor:
|
11
26
|
minimum_installment_not_satisfied: O valor mínimo da parcela deve ser R$ 5,00
|
27
|
+
cieloz/requisicao_transacao/forma_pagamento:
|
28
|
+
attributes:
|
29
|
+
bandeira:
|
30
|
+
blank: escolha a bandeira
|
31
|
+
inclusion: escolha a bandeira
|
32
|
+
|
data/lib/cieloz/bandeiras.rb
CHANGED
@@ -4,17 +4,17 @@ module Cieloz
|
|
4
4
|
AMEX, DINERS, DISCOVER, ELO, MASTERCARD, VISA = ALL
|
5
5
|
|
6
6
|
def self.operacao produto
|
7
|
-
|
8
|
-
|
7
|
+
produto = produto.to_s
|
8
|
+
case produto
|
9
|
+
when 'mastercard_securecode'
|
9
10
|
[MASTERCARD, :autorizar_somente_autenticada]
|
10
|
-
when
|
11
|
+
when 'verified_by_visa'
|
11
12
|
[VISA, :autorizar_somente_autenticada]
|
12
13
|
else
|
13
|
-
produto = produto.to_s
|
14
14
|
if ALL.include? produto
|
15
15
|
[produto, :autorizacao_direta]
|
16
16
|
else
|
17
|
-
|
17
|
+
[nil, nil]
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -8,14 +8,14 @@ class Cieloz::RequisicaoTransacao
|
|
8
8
|
|
9
9
|
validates :numero, :valor, :moeda, :data_hora, presence: true
|
10
10
|
|
11
|
-
validates :numero, length: {
|
11
|
+
validates :numero, length: { maximum: 20 }
|
12
12
|
|
13
|
-
validates :valor, length: {
|
14
|
-
validates :valor, numericality: { only_integer: true }
|
13
|
+
validates :valor, length: { maximum: 12 }
|
14
|
+
validates :valor, numericality: { only_integer: true }, unless: "@valor.blank?"
|
15
15
|
|
16
|
-
validates :descricao, length: {
|
16
|
+
validates :descricao, length: { maximum: 1024 }
|
17
17
|
validates :idioma, inclusion: { in: IDIOMAS }
|
18
|
-
validates :soft_descriptor, length: {
|
18
|
+
validates :soft_descriptor, length: { maximum: 13 }
|
19
19
|
|
20
20
|
def attributes
|
21
21
|
{
|
@@ -10,19 +10,21 @@ class Cieloz::RequisicaoTransacao
|
|
10
10
|
attr_accessor :numero, :nome_portador, :validade
|
11
11
|
attr_reader :indicador, :codigo_seguranca
|
12
12
|
|
13
|
-
validates :nome_portador, length: {
|
13
|
+
validates :nome_portador, length: { maximum: 50 }
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
set_callback :validate, :before do |portador|
|
16
|
+
[:numero, :validade, :codigo_seguranca].each {|attr|
|
17
|
+
val = portador.send attr
|
18
|
+
portador.instance_variable_set "@#{attr}", val.to_s
|
19
|
+
}
|
20
|
+
portador.numero.gsub! ' ', ''
|
21
|
+
end
|
19
22
|
|
20
|
-
validates :
|
21
|
-
validates :validade, format: { with:
|
22
|
-
validates :
|
23
|
+
validates :numero, format: { with: /^\d{16}$/ }
|
24
|
+
validates :validade, format: { with: /^2\d{3}(0[1-9]|1[012])$/ }
|
25
|
+
validates :codigo_seguranca, format: { with: /^(\d{3}|\d{4})$/ }
|
23
26
|
|
24
|
-
validates :
|
25
|
-
validates :codigo_seguranca, numericality: { only_integer: true }
|
27
|
+
validates :indicador, presence: true
|
26
28
|
|
27
29
|
def initialize attrs={}
|
28
30
|
super
|
@@ -23,18 +23,18 @@ class Cieloz::RequisicaoTransacao < Cieloz::Requisicao
|
|
23
23
|
validate :parcela_minima?,
|
24
24
|
if: "not @dados_pedido.nil? and not @forma_pagamento.nil?"
|
25
25
|
|
26
|
-
validates :autorizar,
|
26
|
+
validates :autorizar, inclusion: {
|
27
27
|
in: [
|
28
28
|
SOMENTE_AUTENTICAR, AUTORIZAR_SE_AUTENTICADA,
|
29
29
|
AUTORIZAR_NAO_AUTENTICADA, AUTORIZACAO_DIRETA, RECORRENTE
|
30
30
|
]
|
31
31
|
}
|
32
32
|
# validates string values because false.blank? is true, failing presence validation
|
33
|
-
validates :capturar,
|
33
|
+
validates :capturar, inclusion: { in: ["true", "false"] }
|
34
34
|
|
35
35
|
with_options if: "@autorizar != AUTORIZACAO_DIRETA" do |txn|
|
36
36
|
txn.validates :url_retorno, presence: true
|
37
|
-
txn.validates :url_retorno, length: {
|
37
|
+
txn.validates :url_retorno, length: { maximum: 1024 }
|
38
38
|
end
|
39
39
|
|
40
40
|
validates :campo_livre, length: { maximum: 128 }
|
@@ -52,10 +52,9 @@ class Cieloz::RequisicaoTransacao < Cieloz::Requisicao
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def parcela_minima?
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
55
|
+
valor, parcelas = @dados_pedido.valor.to_i, @forma_pagamento.parcelas.to_i
|
56
|
+
if parcelas > 0 and valor / parcelas < 500
|
57
|
+
@dados_pedido.errors.add :valor, :minimum_installment_not_satisfied
|
59
58
|
end
|
60
59
|
end
|
61
60
|
|
data/lib/cieloz/version.rb
CHANGED
@@ -19,7 +19,6 @@ describe "Bandeiras e Operacoes" do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it "disallows unsupported products" do
|
22
|
-
|
23
|
-
error.message.must_match /product_not_supported/
|
22
|
+
assert_equal [nil, nil], _.operacao("anything else")
|
24
23
|
end
|
25
24
|
end
|
@@ -16,18 +16,21 @@ describe Cieloz::RequisicaoTransacao::DadosPortador do
|
|
16
16
|
|
17
17
|
it { must ensure_length_of(:nome_portador).is_at_most(50) }
|
18
18
|
|
19
|
-
it { must
|
20
|
-
it {
|
21
|
-
it {
|
19
|
+
it { must allow_value(1234567890123456).for(:numero) }
|
20
|
+
it { wont allow_value(123456789012345).for(:numero) }
|
21
|
+
it { wont allow_value(12345678901234567).for(:numero) }
|
22
|
+
it { wont allow_value("ABC4567890123456").for(:numero) }
|
22
23
|
|
23
|
-
it {
|
24
|
-
|
25
|
-
|
24
|
+
it {
|
25
|
+
(100..9999).step(123).each {|val|
|
26
|
+
must allow_value(val).for(:codigo_seguranca)
|
27
|
+
}
|
28
|
+
}
|
26
29
|
|
27
|
-
it {
|
28
|
-
|
29
|
-
|
30
|
-
it {
|
30
|
+
it { wont allow_value(99).for(:codigo_seguranca) }
|
31
|
+
it { wont allow_value(10000).for(:codigo_seguranca) }
|
32
|
+
it { wont allow_value("ab1").for(:codigo_seguranca) }
|
33
|
+
it { wont allow_value("abc1").for(:codigo_seguranca) }
|
31
34
|
|
32
35
|
def mm_values range
|
33
36
|
yyyy = 2013
|
@@ -90,15 +93,21 @@ end
|
|
90
93
|
|
91
94
|
describe Cieloz::RequisicaoTransacao::DadosPedido do
|
92
95
|
it { must validate_presence_of :numero }
|
93
|
-
it { must ensure_length_of(:numero)
|
94
|
-
.is_at_least(1)
|
95
|
-
.is_at_most(20) }
|
96
|
+
it { must ensure_length_of(:numero).is_at_most(20) }
|
96
97
|
|
97
98
|
it { must validate_presence_of :valor }
|
99
|
+
it { must ensure_length_of(:valor).is_at_most(12) }
|
98
100
|
it { must validate_numericality_of(:valor).only_integer }
|
99
|
-
|
100
|
-
|
101
|
-
|
101
|
+
|
102
|
+
it "dont validate valor if it's blank" do
|
103
|
+
subject.valor = ""
|
104
|
+
refute subject.valid?
|
105
|
+
assert_equal [I18n.t('errors.messages.blank')], subject.errors[:valor]
|
106
|
+
|
107
|
+
subject.valor = "abc"
|
108
|
+
refute subject.valid?
|
109
|
+
assert_equal [I18n.t('errors.messages.not_a_number')], subject.errors[:valor]
|
110
|
+
end
|
102
111
|
|
103
112
|
it { must validate_presence_of :moeda }
|
104
113
|
it { must validate_presence_of :data_hora }
|
@@ -238,14 +247,13 @@ describe Cieloz::RequisicaoTransacao do
|
|
238
247
|
wont validate_presence_of :url_retorno
|
239
248
|
end
|
240
249
|
|
241
|
-
it { must ensure_length_of(:url_retorno).
|
250
|
+
it { must ensure_length_of(:url_retorno).is_at_most(1024) }
|
242
251
|
|
243
252
|
it "doesnt validate url_retorno length for autorizacao direta" do
|
244
253
|
subject.autorizacao_direta
|
245
254
|
wont ensure_length_of(:url_retorno).is_at_least(1).is_at_most(1024)
|
246
255
|
end
|
247
256
|
|
248
|
-
it { must validate_presence_of :autorizar }
|
249
257
|
it {
|
250
258
|
must ensure_inclusion_of(:autorizar).in_array [
|
251
259
|
_::SOMENTE_AUTENTICAR, _::AUTORIZAR_SE_AUTENTICADA,
|
@@ -309,7 +317,6 @@ describe Cieloz::RequisicaoTransacao do
|
|
309
317
|
}
|
310
318
|
end
|
311
319
|
|
312
|
-
it { must validate_presence_of :capturar }
|
313
320
|
it { must ensure_inclusion_of(:capturar).in_array(["true", "false"]) }
|
314
321
|
|
315
322
|
it { must ensure_length_of(:campo_livre).is_at_most(128) }
|
@@ -349,6 +356,6 @@ describe Cieloz::RequisicaoTransacao do
|
|
349
356
|
|
350
357
|
refute subject.valid?
|
351
358
|
msg = "Installment should be greater than or equal to R$ 5,00"
|
352
|
-
assert_equal msg, subject.errors[:
|
359
|
+
assert_equal msg, subject.dados_pedido.errors[:valor].first
|
353
360
|
end
|
354
361
|
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.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -246,12 +246,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
246
246
|
- - ! '>='
|
247
247
|
- !ruby/object:Gem::Version
|
248
248
|
version: '0'
|
249
|
+
segments:
|
250
|
+
- 0
|
251
|
+
hash: 3193634196579590297
|
249
252
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
250
253
|
none: false
|
251
254
|
requirements:
|
252
255
|
- - ! '>='
|
253
256
|
- !ruby/object:Gem::Version
|
254
257
|
version: '0'
|
258
|
+
segments:
|
259
|
+
- 0
|
260
|
+
hash: 3193634196579590297
|
255
261
|
requirements: []
|
256
262
|
rubyforge_project:
|
257
263
|
rubygems_version: 1.8.23
|