cieloz 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +35 -23
- data/cieloz.gemspec +2 -6
- data/config/locales/en.yml +1 -1
- data/config/locales/pt-BR.yml +1 -1
- data/lib/cieloz/bandeiras.rb +3 -7
- data/lib/cieloz/builder.rb +13 -3
- data/lib/cieloz/requisicao_transacao/forma_pagamento.rb +3 -8
- data/lib/cieloz/version.rb +1 -1
- data/test/fixtures/vcr_cassettes/requisicao_test_request_posting.yml +2 -2
- data/test/minitest_helper.rb +80 -18
- data/test/unit/bandeiras_operacoes_test.rb +4 -4
- data/test/unit/builder_test.rb +12 -12
- data/test/unit/requisicao_test.rb +5 -3
- data/test/unit/requisicao_transacao_test.rb +7 -8
- data/test/unit/validations_test.rb +61 -49
- metadata +4 -34
- data/test/fixtures/vcr_cassettes/requisicao_test_complex_attributes.yml +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44f0b7f86a5bc2766239b1c8d73d72827f87dc59
|
4
|
+
data.tar.gz: 0cf55d74016d32d29f5d6f38e1a8a1f1e9771712
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf0992631c8e0d7e9e8ff40fa88596a629cf5dfd567f3bcbc406320a36d6ff7b720603ff660e474ef965e6816e577ce40e3bd165d0801eb200478bd5898027a7
|
7
|
+
data.tar.gz: 135b997134af94baf69a0e5483ceecfc7decc10c0d1422539b8cdabac266519c09ec67560ba20966ccd869ce30d586f5e27919aba40ec0134cea5a7bd208b667
|
data/README.md
CHANGED
@@ -21,7 +21,7 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
# Usage
|
23
23
|
|
24
|
-
This is a quick start guide to Cieloz API.
|
24
|
+
This is a quick start guide to Cieloz API.
|
25
25
|
If you want to learn deeply about Cielo Gateway, read the Getting Started section.
|
26
26
|
|
27
27
|
## Low Level API: Requisicao objects
|
@@ -50,16 +50,16 @@ as a xml attribute, so it can be logged.
|
|
50
50
|
|
51
51
|
pedido = Cieloz::RequisicaoTransacao::DadosPedido.new numero: 123, valor: 5000, moeda: 986,
|
52
52
|
data_hora: now, descricao: "teste", idioma: "PT", soft_descriptor: "13letterstest"
|
53
|
-
|
53
|
+
|
54
54
|
pagamento = Cieloz::RequisicaoTransacao::FormaPagamento.new.credito "visa"
|
55
|
-
|
55
|
+
|
56
56
|
transacao = Cieloz::RequisicaoTransacao.new dados_ec: dados_ec,
|
57
57
|
dados_pedido: pedido,
|
58
58
|
forma_pagamento: pagamento,
|
59
59
|
url_retorno: your_callback_url
|
60
|
-
|
60
|
+
|
61
61
|
response = transacao.autorizacao_direta.submit
|
62
|
-
|
62
|
+
|
63
63
|
response.success? # returned Transacao (with status and id for the created Cielo transaction) or Error object?
|
64
64
|
|
65
65
|
### Verify
|
@@ -100,9 +100,21 @@ The easiest way to use this gem is through the high level API provided by Cieloz
|
|
100
100
|
It provides convenient methods to build the respective Cieloz request objects from your domain model object.
|
101
101
|
|
102
102
|
### Cieloz.transacao - builds a RequisicaoTransacao object for Payment Authorization
|
103
|
-
|
104
|
-
pd = Cieloz.pedido order
|
105
|
-
|
103
|
+
|
104
|
+
pd = Cieloz.pedido order
|
105
|
+
|
106
|
+
pg = Cieloz.debito payment, bandeira: 'visa' # debit
|
107
|
+
|
108
|
+
or
|
109
|
+
|
110
|
+
pg = Cieloz.credito payment, bandeira: 'visa' # credit with 1 parcel
|
111
|
+
|
112
|
+
or
|
113
|
+
|
114
|
+
# parcelled credit
|
115
|
+
pg = Cieloz.parcelado payment, bandeira: 'visa', parcelas: :installments
|
116
|
+
|
117
|
+
|
106
118
|
tx = Cieloz.transacao nil, dados_pedido: pd, forma_pagamento: pg
|
107
119
|
|
108
120
|
### Cieloz.consulta - builds RequisicaoConsulta
|
@@ -112,23 +124,23 @@ It provides convenient methods to build the respective Cieloz request objects fr
|
|
112
124
|
### Cieloz.captura - builds RequisicaoCaptura
|
113
125
|
|
114
126
|
captura = Cieloz.captura payment # total capture
|
115
|
-
|
127
|
+
|
116
128
|
or
|
117
|
-
|
129
|
+
|
118
130
|
captura = Cieloz.captura payment, value: partial_value
|
119
131
|
|
120
132
|
|
121
133
|
### Cieloz.cancelamento - builds RequisicaoCancelamento
|
122
134
|
|
123
135
|
cancelamento = Cieloz.cancelamento payment # total cancel
|
124
|
-
|
136
|
+
|
125
137
|
or
|
126
|
-
|
138
|
+
|
127
139
|
cancelamento = Cieloz.cancelamento payment, value: partial_cancel
|
128
|
-
|
140
|
+
|
129
141
|
### Domain Model Mapping Startegies
|
130
142
|
|
131
|
-
High Level API uses three different strategies to extract the attribute values required to build Cielo object attribute
|
143
|
+
High Level API uses three different strategies to extract the attribute values required to build Cielo object attribute
|
132
144
|
values to be serialized in XML format and sent to Cielo Web Service (see Domain Model Mapping Strategies below).
|
133
145
|
|
134
146
|
When an attribute cannot be resolved from one mapping strategy, Cieloz::Builder retrieves the default values configured
|
@@ -147,14 +159,14 @@ When your domain object attribute names are the same as the Cielo Web Service ex
|
|
147
159
|
|
148
160
|
order.numero = "R123456"
|
149
161
|
order.valor = 12345
|
150
|
-
|
162
|
+
|
151
163
|
# creates Cieloz::RequisicaoTransacao::DadosPedido extracting order attributes
|
152
164
|
# that has the same names as DadosPedido attributes
|
153
165
|
pedido = Cieloz.pedido order
|
154
|
-
|
166
|
+
|
155
167
|
p pedido.numero
|
156
168
|
$ R123456
|
157
|
-
|
169
|
+
|
158
170
|
p pedido.valor
|
159
171
|
$ 12345
|
160
172
|
|
@@ -168,10 +180,10 @@ When you should provide a mapping between your domain model attributes and Cielo
|
|
168
180
|
# maps order.number to DadosPedido#numero
|
169
181
|
# and order.value to DadosPedido#valor
|
170
182
|
pedido = Cieloz.pedido order, numero: :number, valor: :value
|
171
|
-
|
183
|
+
|
172
184
|
p pedido.numero
|
173
185
|
$ R123456
|
174
|
-
|
186
|
+
|
175
187
|
p pedido.valor
|
176
188
|
$ 12345
|
177
189
|
|
@@ -180,10 +192,10 @@ When you should provide a mapping between your domain model attributes and Cielo
|
|
180
192
|
When you provide values.
|
181
193
|
|
182
194
|
pedido = Cieloz.pedido nil, numero: "R123456", valor: 12345
|
183
|
-
|
195
|
+
|
184
196
|
p pedido.numero
|
185
197
|
$ R123456
|
186
|
-
|
198
|
+
|
187
199
|
p pedido.valor
|
188
200
|
$ 12345
|
189
201
|
|
@@ -191,10 +203,10 @@ When you provide values.
|
|
191
203
|
|
192
204
|
order.descricao = "Hello Cielo!"
|
193
205
|
pedido = Cieloz.pedido source, numero: number, valor: 12345
|
194
|
-
|
206
|
+
|
195
207
|
p pedido.numero
|
196
208
|
$ R123456
|
197
|
-
|
209
|
+
|
198
210
|
p pedido.valor
|
199
211
|
$ 12345
|
200
212
|
|
data/cieloz.gemspec
CHANGED
@@ -24,11 +24,7 @@ Gem::Specification.new do |gem|
|
|
24
24
|
gem.add_development_dependency "rake"
|
25
25
|
gem.add_development_dependency "turn"
|
26
26
|
gem.add_development_dependency "vcr"
|
27
|
-
gem.add_development_dependency "
|
28
|
-
|
29
|
-
# see https://github.com/thoughtbot/shoulda-matchers/issues/235
|
30
|
-
gem.add_development_dependency "bourne", "1.3.0"
|
27
|
+
gem.add_development_dependency "webmock"
|
31
28
|
|
32
|
-
gem.add_development_dependency "
|
33
|
-
gem.add_development_dependency "minitest-matchers"
|
29
|
+
gem.add_development_dependency "debugger"
|
34
30
|
end
|
data/config/locales/en.yml
CHANGED
@@ -5,7 +5,7 @@ en:
|
|
5
5
|
cieloz/requisicao_transacao:
|
6
6
|
attributes:
|
7
7
|
autorizar:
|
8
|
-
inclusion: should be in [0,1,2,3,4]
|
8
|
+
inclusion: "should be in [0 (Authenticate Only), 1 (Autorize only if Authenticated), 2 (Authorize not Authenticated), 3 (Direct Authorization), 4 (Recorrent)]"
|
9
9
|
authentication_not_supported: Authentication not supported
|
10
10
|
direct_auth_available_for_credit_only: Direct auth available for credit only
|
11
11
|
capturar:
|
data/config/locales/pt-BR.yml
CHANGED
@@ -5,7 +5,7 @@ pt-BR:
|
|
5
5
|
cieloz/requisicao_transacao:
|
6
6
|
attributes:
|
7
7
|
autorizar:
|
8
|
-
inclusion: deveria estar entre [0,1,2,3,4]
|
8
|
+
inclusion: "deveria estar entre [0 (Somente Autenticar), 1 (Autorizar Somente Autenticada), 2 (Autorizar não Autenticada), 3 (Autorização Direta), 4 (Recorrente)]"
|
9
9
|
authentication_not_supported: Bandeira não possui programa de autenticação
|
10
10
|
direct_auth_available_for_credit_only: Autorização Direta disponível apenas em operações de crédito
|
11
11
|
capturar:
|
data/lib/cieloz/bandeiras.rb
CHANGED
@@ -7,15 +7,11 @@ module Cieloz
|
|
7
7
|
produto = produto.to_s
|
8
8
|
case produto
|
9
9
|
when 'mastercard_securecode'
|
10
|
-
|
10
|
+
:autorizar_somente_autenticada
|
11
11
|
when 'verified_by_visa'
|
12
|
-
|
12
|
+
:autorizar_somente_autenticada
|
13
13
|
else
|
14
|
-
if ALL.include? produto
|
15
|
-
[produto, :autorizacao_direta]
|
16
|
-
else
|
17
|
-
[nil, nil]
|
18
|
-
end
|
14
|
+
:autorizacao_direta if ALL.include? produto
|
19
15
|
end
|
20
16
|
end
|
21
17
|
end
|
data/lib/cieloz/builder.rb
CHANGED
@@ -25,9 +25,19 @@ module Cieloz
|
|
25
25
|
descricao: desc, soft_descriptor: soft
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
29
|
-
|
30
|
-
RequisicaoTransacao::FormaPagamento.new.
|
28
|
+
def debito source, opts={}
|
29
|
+
bandeira = attrs_from source, opts, :bandeira
|
30
|
+
RequisicaoTransacao::FormaPagamento.new.credito bandeira
|
31
|
+
end
|
32
|
+
|
33
|
+
def credito source, opts={}
|
34
|
+
bandeira = attrs_from source, opts, :bandeira
|
35
|
+
RequisicaoTransacao::FormaPagamento.new.credito bandeira
|
36
|
+
end
|
37
|
+
|
38
|
+
def parcelado source, opts={}
|
39
|
+
bandeira, parcelas = attrs_from source, opts, :bandeira, :parcelas
|
40
|
+
RequisicaoTransacao::FormaPagamento.new.parcelado bandeira, parcelas
|
31
41
|
end
|
32
42
|
|
33
43
|
def transacao source, opts={}
|
@@ -62,13 +62,7 @@ class Cieloz::RequisicaoTransacao
|
|
62
62
|
when (1..max) then PARCELADO_LOJA
|
63
63
|
when (max+1..max_adm) then PARCELADO_ADM
|
64
64
|
end
|
65
|
-
parcelar bandeira,
|
66
|
-
end
|
67
|
-
|
68
|
-
# Utility methods that deduces what authorization method should be performed
|
69
|
-
def operacao opr, parcelas
|
70
|
-
bandeira, @metodo_autorizacao = Cieloz::Bandeiras.operacao opr
|
71
|
-
parcelado bandeira, parcelas
|
65
|
+
parcelar bandeira, produto, parcelas
|
72
66
|
end
|
73
67
|
|
74
68
|
def metodo_autorizacao
|
@@ -77,13 +71,14 @@ class Cieloz::RequisicaoTransacao
|
|
77
71
|
|
78
72
|
private
|
79
73
|
def set_attrs bandeira, produto, parcelas
|
74
|
+
@metodo_autorizacao = Cieloz::Bandeiras.operacao bandeira
|
80
75
|
@bandeira = bandeira
|
81
76
|
@produto = produto
|
82
77
|
@parcelas = parcelas
|
83
78
|
self
|
84
79
|
end
|
85
80
|
|
86
|
-
def parcelar bandeira,
|
81
|
+
def parcelar bandeira, produto, parcelas
|
87
82
|
if parcelas == 1
|
88
83
|
credito bandeira
|
89
84
|
else
|
data/lib/cieloz/version.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: post
|
5
|
-
uri: https://
|
5
|
+
uri: https://qasecommerce.cielo.com.br/servicos/ecommwsec.do
|
6
6
|
body:
|
7
7
|
encoding: UTF-8
|
8
8
|
string: mensagem=<?xml version="1.0" encoding="UTF-8"?><requisicao id="1" versao="1.2.0"><dados-ec><numero>123</numero><chave>abc123</chave></dados-ec></requisicao>
|
@@ -40,6 +40,6 @@ http_interactions:
|
|
40
40
|
PGVjb206bnVtZXJvPjEyMzwvZWNvbTpudW1lcm8+PGVjb206Y2hhdmU+YWJj
|
41
41
|
MTIzPC9lY29tOmNoYXZlPjwvZWNvbTpkYWRvcy1lYz48L2Vjb206cmVxdWlz
|
42
42
|
aWNhbz4nCl1dPjwvbWVuc2FnZW0+PC9lcnJvPgo=
|
43
|
-
http_version:
|
43
|
+
http_version:
|
44
44
|
recorded_at: Sat, 10 Aug 2013 17:53:05 GMT
|
45
45
|
recorded_with: VCR 2.5.0
|
data/test/minitest_helper.rb
CHANGED
@@ -4,20 +4,16 @@ require 'cieloz'
|
|
4
4
|
require 'minitest/autorun'
|
5
5
|
# require 'turn/autorun'
|
6
6
|
|
7
|
-
require 'minitest/matchers'
|
8
|
-
require 'shoulda/matchers'
|
9
|
-
|
10
7
|
require 'vcr'
|
11
8
|
require 'erb'
|
12
9
|
|
13
10
|
VCR.configure do |c|
|
14
11
|
c.cassette_library_dir = 'test/fixtures/vcr_cassettes'
|
15
12
|
c.hook_into :webmock
|
13
|
+
c.debug_logger = File.open('test/tmp/vcr.log', 'w')
|
16
14
|
end
|
17
15
|
|
18
16
|
class MiniTest::Spec
|
19
|
-
include Shoulda::Matchers::ActiveModel
|
20
|
-
|
21
17
|
class << self
|
22
18
|
alias :_create :create
|
23
19
|
|
@@ -35,19 +31,6 @@ class MiniTest::Spec
|
|
35
31
|
end
|
36
32
|
end
|
37
33
|
|
38
|
-
module Shoulda::Matchers::ActiveModel
|
39
|
-
class AllowValueMatcher
|
40
|
-
def matches? instance
|
41
|
-
@instance = instance
|
42
|
-
@values_to_match.none? do |value|
|
43
|
-
@value = value
|
44
|
-
@instance.instance_variable_set "@#{@attribute}", @value
|
45
|
-
errors_match?
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
34
|
def expected_xml opts={}
|
52
35
|
root, id, versao = opts[:root], opts[:id], opts[:versao]
|
53
36
|
|
@@ -68,3 +51,82 @@ end
|
|
68
51
|
def xml_for type, dir, binding
|
69
52
|
render_template dir, "dados-#{type}.xml", binding
|
70
53
|
end
|
54
|
+
|
55
|
+
module MiniTest::Assertions
|
56
|
+
def must_validate_presence_of(attribute)
|
57
|
+
@attribute = attribute
|
58
|
+
must_be_invalid_with nil, :blank
|
59
|
+
end
|
60
|
+
|
61
|
+
def wont_validate_presence_of(attribute)
|
62
|
+
@attribute = attribute
|
63
|
+
must_be_valid_with nil, :blank
|
64
|
+
end
|
65
|
+
|
66
|
+
def must_allow_value(attribute, value, options={})
|
67
|
+
@attribute = attribute
|
68
|
+
must_be_valid_with value, :invalid, options
|
69
|
+
end
|
70
|
+
|
71
|
+
def wont_allow_value(attribute, value, options={})
|
72
|
+
@attribute = attribute
|
73
|
+
must_be_invalid_with value, :invalid, options
|
74
|
+
end
|
75
|
+
|
76
|
+
def must_ensure_length_of(attribute, options)
|
77
|
+
@attribute = attribute
|
78
|
+
if max = options[:is_at_most]
|
79
|
+
value = (max + 1).times.collect { "a" }.join
|
80
|
+
must_be_invalid_with value, 'too_long', count: max
|
81
|
+
end
|
82
|
+
if min = options[:is_at_least]
|
83
|
+
value = (min - 1).times.collect { "a" }.join
|
84
|
+
must_be_invalid_with value, 'too_short', count: min
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def wont_ensure_length_of(attribute, options)
|
89
|
+
@attribute = attribute
|
90
|
+
if max = options[:is_at_most]
|
91
|
+
value = (max + 1).times.collect { "a" }.join
|
92
|
+
must_be_valid_with value, 'too_long', count: max
|
93
|
+
end
|
94
|
+
if min = options[:is_at_least]
|
95
|
+
value = (min - 1).times.collect { "a" }.join
|
96
|
+
must_be_valid_with value, 'too_short', count: min
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def must_validate_numericality_of(attribute, options)
|
101
|
+
@attribute = attribute
|
102
|
+
if options[:only_integer]
|
103
|
+
must_be_invalid_with 1.1, :not_an_integer
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def must_ensure_inclusion_of(attribute, options)
|
108
|
+
@attribute = attribute
|
109
|
+
if array = options[:in_array]
|
110
|
+
array.each do |value|
|
111
|
+
must_be_valid_with value, options['message']
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
private
|
117
|
+
def must_be_valid_with(value, error_key, options={})
|
118
|
+
subject.instance_variable_set "@#{@attribute}", value
|
119
|
+
subject.valid?
|
120
|
+
|
121
|
+
msg = options[:message] || I18n.t("errors.messages.#{error_key}", options)
|
122
|
+
(subject.errors.messages[@attribute] || []).wont_include msg
|
123
|
+
end
|
124
|
+
|
125
|
+
def must_be_invalid_with(value, error_key, options={})
|
126
|
+
subject.instance_variable_set "@#{@attribute}", value
|
127
|
+
subject.valid?
|
128
|
+
|
129
|
+
msg = options[:message] || I18n.t("errors.messages.#{error_key}", options)
|
130
|
+
(subject.errors.messages[@attribute] || []).must_include msg
|
131
|
+
end
|
132
|
+
end
|
@@ -3,22 +3,22 @@ describe "Bandeiras e Operacoes" do
|
|
3
3
|
|
4
4
|
it "recognizes mastercard secure code requires authentication" do
|
5
5
|
res = _.operacao "mastercard_securecode"
|
6
|
-
assert_equal
|
6
|
+
assert_equal :autorizar_somente_autenticada, res
|
7
7
|
end
|
8
8
|
|
9
9
|
it "recognizes verified by visa code requires authentication" do
|
10
10
|
res = _.operacao "verified_by_visa"
|
11
|
-
assert_equal
|
11
|
+
assert_equal :autorizar_somente_autenticada, res
|
12
12
|
end
|
13
13
|
|
14
14
|
it "recognizes supported products allows direct authorization" do
|
15
15
|
_::ALL.each do |bandeira|
|
16
16
|
res = _.operacao bandeira
|
17
|
-
assert_equal
|
17
|
+
assert_equal :autorizacao_direta, res
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
it "disallows unsupported products" do
|
22
|
-
|
22
|
+
assert_nil _.operacao("anything else")
|
23
23
|
end
|
24
24
|
end
|
data/test/unit/builder_test.rb
CHANGED
@@ -93,32 +93,32 @@ describe Cieloz::Builder do
|
|
93
93
|
|
94
94
|
describe "Pagamento Building" do
|
95
95
|
before do
|
96
|
-
def @source.
|
96
|
+
def @source.bandeira ; 'visa' end
|
97
97
|
def @source.parcelas ; 2 end
|
98
98
|
end
|
99
99
|
|
100
100
|
it "asks for operacao / parcelas attributes when missing opts" do
|
101
|
-
pg = _.
|
101
|
+
pg = _.parcelado @source
|
102
102
|
pg.bandeira.must_equal "visa"
|
103
103
|
pg.parcelas.must_equal @source.parcelas
|
104
104
|
end
|
105
105
|
|
106
106
|
it "maps operacao / numero when opts are given" do
|
107
|
-
def @source.operation ;
|
108
|
-
def @source.installments ; 6
|
107
|
+
def @source.operation ; 'mastercard' end
|
108
|
+
def @source.installments ; 6 end
|
109
109
|
|
110
|
-
opts = {
|
111
|
-
pg = _.
|
110
|
+
opts = { bandeira: :operation, parcelas: :installments }
|
111
|
+
pg = _.parcelado @source, opts
|
112
112
|
|
113
113
|
pg.bandeira.must_equal @source.operation.to_s
|
114
114
|
pg.parcelas.must_equal @source.installments
|
115
115
|
end
|
116
116
|
|
117
117
|
it "get given operacao / numero values" do
|
118
|
-
opts = {
|
119
|
-
pg = _.
|
118
|
+
opts = { bandeira: "amex", parcelas: 9 }
|
119
|
+
pg = _.parcelado @source, opts
|
120
120
|
|
121
|
-
pg.bandeira.must_equal opts[:
|
121
|
+
pg.bandeira.must_equal opts[:bandeira]
|
122
122
|
pg.parcelas.must_equal opts[:parcelas]
|
123
123
|
end
|
124
124
|
end
|
@@ -144,7 +144,7 @@ describe Cieloz::Builder do
|
|
144
144
|
|
145
145
|
@portador = _.portador(@source)
|
146
146
|
@pedido = _.pedido(@source)
|
147
|
-
@pagamento = _.
|
147
|
+
@pagamento = _.parcelado(@source)
|
148
148
|
|
149
149
|
@source.instance_variable_set :@portador, @portador
|
150
150
|
@source.instance_variable_set :@pedido, @pedido
|
@@ -203,8 +203,8 @@ describe Cieloz::Builder do
|
|
203
203
|
_.transacao(@source).autorizar
|
204
204
|
.must_equal Cieloz::RequisicaoTransacao::AUTORIZACAO_DIRETA
|
205
205
|
|
206
|
-
["verified_by_visa", "mastercard_securecode"].each {|
|
207
|
-
pg = _.
|
206
|
+
["verified_by_visa", "mastercard_securecode"].each {|flag|
|
207
|
+
pg = _.parcelado @source, bandeira: flag, parcelas: 2
|
208
208
|
_.transacao(@source, forma_pagamento: pg).autorizar
|
209
209
|
.must_equal Cieloz::RequisicaoTransacao::AUTORIZAR_SE_AUTENTICADA
|
210
210
|
}
|
@@ -44,17 +44,19 @@ describe Cieloz::Requisicao do
|
|
44
44
|
let(:xml) { expected_xml(opts) { xml_for :ec, dir, binding } }
|
45
45
|
|
46
46
|
it "serializes" do
|
47
|
-
|
47
|
+
subject.stub :valid?, false do # avoid http request
|
48
48
|
subject.submit # @dados_ec is set on submission
|
49
|
-
assert_equal xml, subject.to_xml
|
50
49
|
end
|
50
|
+
assert_equal xml, subject.to_xml
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
54
|
describe "request posting" do
|
55
55
|
it "sends to test web service" do
|
56
|
-
|
56
|
+
Cieloz::Configuracao.reset!
|
57
|
+
VCR.use_cassette 'requisicao_test_request_posting' do
|
57
58
|
res = subject.submit
|
59
|
+
|
58
60
|
assert_equal({}, subject.errors.messages)
|
59
61
|
refute_nil res.codigo
|
60
62
|
refute_nil res.mensagem
|
@@ -65,16 +65,15 @@ describe Cieloz::RequisicaoTransacao do
|
|
65
65
|
subject.capturar_automaticamente
|
66
66
|
subject.campo_livre = "debug"
|
67
67
|
|
68
|
-
|
69
|
-
VCR.use_cassette("requisicao_transacao_test_request_posting") do
|
68
|
+
VCR.use_cassette "requisicao_transacao_test_request_posting" do
|
70
69
|
res = subject.submit
|
71
|
-
end
|
72
70
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
71
|
+
assert_equal({}, subject.errors.messages)
|
72
|
+
assert_equal Cieloz::Requisicao::Transacao, res.class
|
73
|
+
assert_equal tid, res.tid
|
74
|
+
assert_equal status_txn, res.status
|
75
|
+
assert_equal url_cielo, res.url_autenticacao
|
76
|
+
end
|
78
77
|
end
|
79
78
|
end
|
80
79
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
describe Cieloz::Requisicao::DadosEc do
|
4
|
-
it {
|
5
|
-
it {
|
4
|
+
it { must_validate_presence_of :numero }
|
5
|
+
it { must_validate_presence_of :chave }
|
6
6
|
end
|
7
7
|
|
8
8
|
describe Cieloz::RequisicaoTransacao::DadosPortador do
|
@@ -12,23 +12,29 @@ describe Cieloz::RequisicaoTransacao::DadosPortador do
|
|
12
12
|
_.new(codigo_seguranca: "123").codigo_seguranca.wont_be_nil
|
13
13
|
end
|
14
14
|
|
15
|
-
it {
|
15
|
+
it { must_ensure_length_of :nome_portador, is_at_most: 50 }
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
it {
|
17
|
+
let(:invalid_number) {
|
18
|
+
I18n.t 'activemodel.errors.models.cieloz/requisicao_transacao/dados_portador.attributes.numero.invalid'
|
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 }
|
21
24
|
|
22
25
|
it {
|
23
26
|
(100..9999).step(123).each {|val|
|
24
|
-
|
27
|
+
must_allow_value :codigo_seguranca, val
|
25
28
|
}
|
26
29
|
}
|
27
30
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
it {
|
31
|
+
let(:invalid_security_number) {
|
32
|
+
I18n.t 'activemodel.errors.models.cieloz/requisicao_transacao/dados_portador.attributes.codigo_seguranca.invalid'
|
33
|
+
}
|
34
|
+
it { wont_allow_value :codigo_seguranca, 99, message: invalid_security_number }
|
35
|
+
it { wont_allow_value :codigo_seguranca, 10000, message: invalid_security_number }
|
36
|
+
it { wont_allow_value :codigo_seguranca, "ab1", message: invalid_security_number }
|
37
|
+
it { wont_allow_value :codigo_seguranca, "abc1", message: invalid_security_number }
|
32
38
|
|
33
39
|
def mm_values range
|
34
40
|
yyyy = 2013
|
@@ -38,9 +44,7 @@ describe Cieloz::RequisicaoTransacao::DadosPortador do
|
|
38
44
|
it "validates mês validade" do
|
39
45
|
year = Date.today.year
|
40
46
|
(1..12).each {|mes|
|
41
|
-
|
42
|
-
subject.valid?
|
43
|
-
assert_nil subject.errors.messages[:validade]
|
47
|
+
must_allow_value :validade, "#{year}#{"%02d" % mes}"
|
44
48
|
}
|
45
49
|
((0..9).to_a + (13..99).to_a).each {|mes|
|
46
50
|
subject.validade = "#{year}#{"%d" % mes}"
|
@@ -58,9 +62,7 @@ describe Cieloz::RequisicaoTransacao::DadosPortador do
|
|
58
62
|
it "validates ano validade" do
|
59
63
|
year = Date.today.year
|
60
64
|
(year..year+10).each {|ano|
|
61
|
-
|
62
|
-
subject.valid?
|
63
|
-
assert_nil subject.errors.messages[:validade]
|
65
|
+
must_allow_value :validade, "#{year}01"
|
64
66
|
}
|
65
67
|
(year-10..year-1).each {|ano|
|
66
68
|
subject.validade = "#{ano}01"
|
@@ -123,14 +125,13 @@ describe Cieloz::RequisicaoTransacao::DadosPortador do
|
|
123
125
|
end
|
124
126
|
|
125
127
|
describe Cieloz::RequisicaoTransacao::DadosPedido do
|
126
|
-
it {
|
127
|
-
it {
|
128
|
+
it { must_validate_presence_of :numero }
|
129
|
+
it { must_ensure_length_of :numero, is_at_most: 20 }
|
128
130
|
|
129
|
-
it {
|
130
|
-
it {
|
131
|
-
it { must validate_numericality_of(:valor).only_integer }
|
131
|
+
it { must_validate_presence_of :valor }
|
132
|
+
it { must_validate_numericality_of :valor, only_integer: true }
|
132
133
|
|
133
|
-
it "dont validate valor if it's blank" do
|
134
|
+
it "dont validate valor numericality if it's blank" do
|
134
135
|
subject.valor = ""
|
135
136
|
refute subject.valid?
|
136
137
|
assert_equal [I18n.t('errors.messages.blank')], subject.errors[:valor]
|
@@ -140,13 +141,13 @@ describe Cieloz::RequisicaoTransacao::DadosPedido do
|
|
140
141
|
assert_equal [I18n.t('errors.messages.not_a_number')], subject.errors[:valor]
|
141
142
|
end
|
142
143
|
|
143
|
-
it {
|
144
|
-
it {
|
144
|
+
it { must_validate_presence_of :moeda }
|
145
|
+
it { must_validate_presence_of :data_hora }
|
145
146
|
|
146
|
-
it {
|
147
|
-
it {
|
147
|
+
it { must_ensure_length_of :descricao, is_at_most: 1024 }
|
148
|
+
it { must_ensure_length_of :soft_descriptor, is_at_most: 13 }
|
148
149
|
|
149
|
-
it {
|
150
|
+
it { must_ensure_inclusion_of :idioma, in_array: subject.class::IDIOMAS }
|
150
151
|
|
151
152
|
it "is validated inside RequisicaoTransacao" do
|
152
153
|
txn = Cieloz::RequisicaoTransacao.new dados_pedido: subject
|
@@ -158,13 +159,17 @@ end
|
|
158
159
|
describe Cieloz::RequisicaoTransacao::FormaPagamento do
|
159
160
|
let(:all_flags) { Cieloz::Bandeiras::ALL }
|
160
161
|
|
162
|
+
let(:invalid_flag) {
|
163
|
+
I18n.t 'activemodel.errors.models.cieloz/requisicao_transacao/forma_pagamento.attributes.bandeira.invalid'
|
164
|
+
}
|
165
|
+
|
161
166
|
describe "debito validation" do
|
162
167
|
let(:supported_flags) { subject.class::BANDEIRAS_DEBITO }
|
163
168
|
|
164
169
|
it "validates bandeira is VISA or MASTERCARD" do
|
165
170
|
supported_flags.each { |flag|
|
166
171
|
subject.debito flag
|
167
|
-
|
172
|
+
must_ensure_inclusion_of :bandeira, in_array: supported_flags, message: invalid_flag
|
168
173
|
}
|
169
174
|
end
|
170
175
|
|
@@ -181,7 +186,7 @@ describe Cieloz::RequisicaoTransacao::FormaPagamento do
|
|
181
186
|
it "validates bandeiras for credito" do
|
182
187
|
all_flags.each { |flag|
|
183
188
|
subject.credito flag
|
184
|
-
|
189
|
+
must_ensure_inclusion_of :bandeira, in_array: all_flags, message: invalid_flag
|
185
190
|
}
|
186
191
|
end
|
187
192
|
|
@@ -199,7 +204,7 @@ describe Cieloz::RequisicaoTransacao::FormaPagamento do
|
|
199
204
|
supported_flags = subject.class::BANDEIRAS_PARCELAMENTO
|
200
205
|
|
201
206
|
subject.parcelado Cieloz::Bandeiras::DISCOVER, 2
|
202
|
-
|
207
|
+
must_ensure_inclusion_of :bandeira, in_array: supported_flags, message: invalid_flag
|
203
208
|
end
|
204
209
|
|
205
210
|
let(:flag) { all_flags.first }
|
@@ -255,41 +260,45 @@ end
|
|
255
260
|
describe Cieloz::RequisicaoTransacao do
|
256
261
|
let(:_) { subject.class }
|
257
262
|
|
258
|
-
it {
|
259
|
-
it {
|
263
|
+
it { must_validate_presence_of :dados_pedido }
|
264
|
+
it { must_validate_presence_of :forma_pagamento }
|
260
265
|
|
261
266
|
it "somente autenticar requires url_retorno" do
|
262
267
|
subject.somente_autenticar
|
263
|
-
|
268
|
+
must_validate_presence_of :url_retorno
|
264
269
|
end
|
265
270
|
|
266
271
|
it "autorizar somente autenticada requires url_retorno" do
|
267
272
|
subject.autorizar_somente_autenticada
|
268
|
-
|
273
|
+
must_validate_presence_of :url_retorno
|
269
274
|
end
|
270
275
|
|
271
276
|
it "autorizar nao autenticada requires url_retorno" do
|
272
277
|
subject.autorizar_nao_autenticada
|
273
|
-
|
278
|
+
must_validate_presence_of :url_retorno
|
274
279
|
end
|
275
280
|
|
276
281
|
it "autorizacao direta doesnt require url_retorno" do
|
277
282
|
subject.autorizacao_direta
|
278
|
-
|
283
|
+
wont_validate_presence_of :url_retorno
|
279
284
|
end
|
280
285
|
|
281
|
-
it {
|
286
|
+
it { must_ensure_length_of :url_retorno, is_at_most: 1024 }
|
282
287
|
|
283
288
|
it "doesnt validate url_retorno length for autorizacao direta" do
|
284
289
|
subject.autorizacao_direta
|
285
|
-
|
290
|
+
wont_ensure_length_of :url_retorno, is_at_least: 1, is_at_most: 1024
|
286
291
|
end
|
287
292
|
|
293
|
+
|
294
|
+
let(:invalid_auth_mode) {
|
295
|
+
I18n.t 'activemodel.errors.models.cieloz/requisicao_transacao.attributes.autorizar.inclusion'
|
296
|
+
}
|
288
297
|
it {
|
289
|
-
|
298
|
+
must_ensure_inclusion_of :autorizar, in_array: [
|
290
299
|
_::SOMENTE_AUTENTICAR, _::AUTORIZAR_SE_AUTENTICADA,
|
291
300
|
_::AUTORIZAR_NAO_AUTENTICADA, _::AUTORIZACAO_DIRETA, _::RECORRENTE
|
292
|
-
]
|
301
|
+
], message: invalid_auth_mode
|
293
302
|
}
|
294
303
|
|
295
304
|
it "doesnt support autorizacao_direta on debito operations" do
|
@@ -348,9 +357,12 @@ describe Cieloz::RequisicaoTransacao do
|
|
348
357
|
}
|
349
358
|
end
|
350
359
|
|
351
|
-
it {
|
360
|
+
it {
|
361
|
+
must_ensure_inclusion_of :capturar, in_array: ["true", "false"], message:
|
362
|
+
I18n.t('activemodel.errors.models.cieloz/requisicao_transacao.attributes.capturar.inclusion')
|
363
|
+
}
|
352
364
|
|
353
|
-
it {
|
365
|
+
it { must_ensure_length_of :campo_livre, is_at_most: 128 }
|
354
366
|
|
355
367
|
it "extracts bin from DadosPortador" do
|
356
368
|
# no DadosPortador - bin should be nil
|
@@ -363,18 +375,18 @@ describe Cieloz::RequisicaoTransacao do
|
|
363
375
|
|
364
376
|
it "validates dados portador on mode Buy Page Loja" do
|
365
377
|
Cieloz::Configuracao.store_mode!
|
366
|
-
|
378
|
+
must_validate_presence_of :dados_portador
|
367
379
|
end
|
368
380
|
|
369
381
|
describe "Buy Page Cielo" do
|
370
382
|
it "wont validate dados portador if mode is nil" do
|
371
383
|
Cieloz::Configuracao.reset!
|
372
|
-
|
384
|
+
wont_validate_presence_of :dados_portador
|
373
385
|
end
|
374
386
|
|
375
387
|
it "wont validate dados portador on hosted mode" do
|
376
388
|
Cieloz::Configuracao.cielo_mode!
|
377
|
-
|
389
|
+
wont_validate_presence_of :dados_portador
|
378
390
|
end
|
379
391
|
end
|
380
392
|
|
@@ -382,8 +394,8 @@ describe Cieloz::RequisicaoTransacao do
|
|
382
394
|
subject.dados_pedido = subject.class::DadosPedido.new numero: 123,
|
383
395
|
valor: 1400, idioma: "PT", moeda: "986", data_hora: Time.now
|
384
396
|
|
385
|
-
subject.forma_pagamento = subject
|
386
|
-
|
397
|
+
subject.forma_pagamento = subject
|
398
|
+
.class::FormaPagamento.new.parcelado Cieloz::Bandeiras::VISA, 3
|
387
399
|
|
388
400
|
refute subject.valid?
|
389
401
|
msg = "Installment should be greater than or equal to R$ 5,00"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fábio Luiz Nery de Miranda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -95,35 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - '>='
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - '>='
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: bourne
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - '='
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: 1.3.0
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - '='
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: 1.3.0
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: shoulda-matchers
|
98
|
+
name: webmock
|
127
99
|
requirement: !ruby/object:Gem::Requirement
|
128
100
|
requirements:
|
129
101
|
- - '>='
|
@@ -137,7 +109,7 @@ dependencies:
|
|
137
109
|
- !ruby/object:Gem::Version
|
138
110
|
version: '0'
|
139
111
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
112
|
+
name: debugger
|
141
113
|
requirement: !ruby/object:Gem::Requirement
|
142
114
|
requirements:
|
143
115
|
- - '>='
|
@@ -194,7 +166,6 @@ files:
|
|
194
166
|
- readme/supported_products.png
|
195
167
|
- readme/termo_de_adesao_de_risco.pdf
|
196
168
|
- readme/verified_by_visa.png
|
197
|
-
- test/fixtures/vcr_cassettes/requisicao_test_complex_attributes.yml
|
198
169
|
- test/fixtures/vcr_cassettes/requisicao_test_request_posting.yml
|
199
170
|
- test/fixtures/vcr_cassettes/requisicao_transacao_test_request_posting.yml
|
200
171
|
- test/integration/integration_test.rb
|
@@ -240,7 +211,6 @@ signing_key:
|
|
240
211
|
specification_version: 4
|
241
212
|
summary: ''
|
242
213
|
test_files:
|
243
|
-
- test/fixtures/vcr_cassettes/requisicao_test_complex_attributes.yml
|
244
214
|
- test/fixtures/vcr_cassettes/requisicao_test_request_posting.yml
|
245
215
|
- test/fixtures/vcr_cassettes/requisicao_transacao_test_request_posting.yml
|
246
216
|
- test/integration/integration_test.rb
|
@@ -1,45 +0,0 @@
|
|
1
|
-
---
|
2
|
-
http_interactions:
|
3
|
-
- request:
|
4
|
-
method: post
|
5
|
-
uri: https://ecommerce.cielo.com.br/servicos/ecommwsec.do
|
6
|
-
body:
|
7
|
-
encoding: UTF-8
|
8
|
-
string: mensagem=<?xml version="1.0" encoding="UTF-8"?><requisicao id="1" versao="1.2.0"><dados-ec><numero>123</numero><chave>abc123</chave></dados-ec></requisicao>
|
9
|
-
headers:
|
10
|
-
Accept-Encoding:
|
11
|
-
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
-
Accept:
|
13
|
-
- '*/*'
|
14
|
-
User-Agent:
|
15
|
-
- Ruby
|
16
|
-
response:
|
17
|
-
status:
|
18
|
-
code: 200
|
19
|
-
message: OK
|
20
|
-
headers:
|
21
|
-
Date:
|
22
|
-
- Sat, 10 Aug 2013 17:53:03 GMT
|
23
|
-
Content-Length:
|
24
|
-
- '389'
|
25
|
-
Set-Cookie:
|
26
|
-
- JSESSIONID=YjvcSG2QTWBbfT1VN3CFVCnWJlhBvwJkZk5DbNv7lv1rYL1vM1pP!-1396492505;
|
27
|
-
path=/
|
28
|
-
- cielo_cbmp=2233422090.37151.0000; path=/
|
29
|
-
Content-Type:
|
30
|
-
- text/xml; charset=ISO-8859-1
|
31
|
-
body:
|
32
|
-
encoding: ASCII-8BIT
|
33
|
-
string: !binary |-
|
34
|
-
PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iSVNPLTg4NTktMSI/Pgo8
|
35
|
-
ZXJybyB4bWxucz0iaHR0cDovL2Vjb21tZXJjZS5jYm1wLmNvbS5iciI+PGNv
|
36
|
-
ZGlnbz4wMDE8L2NvZGlnbz48bWVuc2FnZW0+PCFbQ0RBVEFbCk8gWE1MIGlu
|
37
|
-
Zm9ybWFkbyBu428g6SB2YWxpZG86Ci0gSW52YWxpZCB0eXBlOiAnPGVjb206
|
38
|
-
cmVxdWlzaWNhbyBpZD0iMSIgdmVyc2FvPSIxLjIuMCIgeG1sbnM6ZWNvbT0i
|
39
|
-
aHR0cDovL2Vjb21tZXJjZS5jYm1wLmNvbS5iciI+PGVjb206ZGFkb3MtZWM+
|
40
|
-
PGVjb206bnVtZXJvPjEyMzwvZWNvbTpudW1lcm8+PGVjb206Y2hhdmU+YWJj
|
41
|
-
MTIzPC9lY29tOmNoYXZlPjwvZWNvbTpkYWRvcy1lYz48L2Vjb206cmVxdWlz
|
42
|
-
aWNhbz4nCl1dPjwvbWVuc2FnZW0+PC9lcnJvPgo=
|
43
|
-
http_version:
|
44
|
-
recorded_at: Sat, 10 Aug 2013 17:53:05 GMT
|
45
|
-
recorded_with: VCR 2.5.0
|