cieloz 0.0.2
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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +170 -0
- data/Rakefile +16 -0
- data/cieloz.gemspec +34 -0
- data/config/locales/en.yml +11 -0
- data/config/locales/pt-BR.yml +11 -0
- data/lib/cieloz/bandeiras.rb +22 -0
- data/lib/cieloz/builder.rb +71 -0
- data/lib/cieloz/configuracao.rb +64 -0
- data/lib/cieloz/helpers.rb +35 -0
- data/lib/cieloz/homologacao.rb +16 -0
- data/lib/cieloz/requisicao/dados_ec.rb +14 -0
- data/lib/cieloz/requisicao/resposta/erro.rb +11 -0
- data/lib/cieloz/requisicao/resposta/transacao.rb +11 -0
- data/lib/cieloz/requisicao/resposta.rb +35 -0
- data/lib/cieloz/requisicao.rb +69 -0
- data/lib/cieloz/requisicao_tid.rb +23 -0
- data/lib/cieloz/requisicao_transacao/dados_pedido.rb +32 -0
- data/lib/cieloz/requisicao_transacao/dados_portador.rb +79 -0
- data/lib/cieloz/requisicao_transacao/forma_pagamento.rb +94 -0
- data/lib/cieloz/requisicao_transacao.rb +126 -0
- data/lib/cieloz/version.rb +3 -0
- data/lib/cieloz.rb +24 -0
- data/readme/cielo_developer_guide_2.0.3.pdf +0 -0
- data/readme/cielo_guia_seguranca_ecommerce.pdf +0 -0
- data/readme/cielo_payment_states.png +0 -0
- data/readme/contrato_de_afiliacao_ao_sistema_cielo.pdf +0 -0
- data/readme/credentials.png +0 -0
- data/readme/dicas_preventivas_para_vendas_mais_seguras.pdf +0 -0
- data/readme/email_cielo.pdf +0 -0
- data/readme/lista_de_documentos_necessarios_para_afiliacao_de_vendas_pela_internet_pessoa_juridica.pdf +0 -0
- data/readme/mastercard_securecodedemo.swf +0 -0
- data/readme/supported_products.png +0 -0
- data/readme/termo_de_adesao_de_risco.pdf +0 -0
- data/readme/verified_by_visa.png +0 -0
- data/test/integration/integration_test.rb +104 -0
- data/test/minitest_helper.rb +65 -0
- data/test/unit/bandeiras_operacoes_test.rb +25 -0
- data/test/unit/builder_test.rb +212 -0
- data/test/unit/configuracao_test.rb +85 -0
- data/test/unit/requisicao_autorizacao_tid_test.rb +19 -0
- data/test/unit/requisicao_cancelamento_test.rb +25 -0
- data/test/unit/requisicao_captura_test.rb +25 -0
- data/test/unit/requisicao_consulta_test.rb +19 -0
- data/test/unit/requisicao_test.rb +84 -0
- data/test/unit/requisicao_transacao_test.rb +82 -0
- data/test/unit/validations_test.rb +358 -0
- data/test/unit/xml/dados-ec.xml +4 -0
- data/test/unit/xml/dados-pagamento.xml +5 -0
- data/test/unit/xml/dados-pedido.xml +9 -0
- data/test/unit/xml/dados-portador.xml +7 -0
- data/test/unit/xml/dados-simple_attrs.xml +4 -0
- data/test/unit/xml/erro.xml +5 -0
- data/test/unit/xml/transacao.xml +19 -0
- metadata +280 -0
@@ -0,0 +1,212 @@
|
|
1
|
+
describe Cieloz::Builder do
|
2
|
+
let(:_) { Cieloz }
|
3
|
+
|
4
|
+
before do
|
5
|
+
Cieloz::Configuracao.soft_descriptor = "config"
|
6
|
+
|
7
|
+
@source = Object.new
|
8
|
+
def @source.numero ; 123456 end
|
9
|
+
def @source.valor ; 7890 end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "Pedido building" do
|
13
|
+
let(:now) { Time.now }
|
14
|
+
|
15
|
+
before do
|
16
|
+
Time.stub :now, now do
|
17
|
+
@pedido = _.pedido @source
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "missing opts" do
|
22
|
+
it "asks for pedido / numero and valor attributes" do
|
23
|
+
@pedido.numero.must_equal @source.numero
|
24
|
+
@pedido.valor.must_equal @source.valor
|
25
|
+
end
|
26
|
+
|
27
|
+
it "populates config values for data_hora, idioma, moeda and soft_descriptor" do
|
28
|
+
@pedido.descricao.must_be_nil
|
29
|
+
@pedido.data_hora.must_equal now
|
30
|
+
@pedido.moeda.must_equal Cieloz::Configuracao.moeda
|
31
|
+
@pedido.idioma.must_equal Cieloz::Configuracao.idioma
|
32
|
+
@pedido.soft_descriptor.must_equal Cieloz::Configuracao.soft_descriptor
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "opts given" do
|
37
|
+
before do
|
38
|
+
def @source.number ; 24680 end
|
39
|
+
def @source.value ; 13579 end
|
40
|
+
def @source.description ; "abc" end
|
41
|
+
def @source.time ; Time.at 0 end
|
42
|
+
def @source.currency ; 123 end
|
43
|
+
def @source.language ; "EN" end
|
44
|
+
def @source.soft_desc ; "xyz" end
|
45
|
+
end
|
46
|
+
|
47
|
+
it "maps attribute names" do
|
48
|
+
mappings = {
|
49
|
+
numero: :number,
|
50
|
+
valor: :value,
|
51
|
+
descricao: :description,
|
52
|
+
data_hora: :time,
|
53
|
+
moeda: :currency,
|
54
|
+
idioma: :language,
|
55
|
+
soft_descriptor: :soft_desc
|
56
|
+
}
|
57
|
+
pedido = _.pedido @source, mappings
|
58
|
+
|
59
|
+
mappings.each { |k,v| pedido.send(k).must_equal @source.send(v) }
|
60
|
+
end
|
61
|
+
|
62
|
+
it "gets given opts values" do
|
63
|
+
opts = {
|
64
|
+
numero: "abc",
|
65
|
+
valor: 123,
|
66
|
+
descricao: "description",
|
67
|
+
data_hora: 1.day.ago,
|
68
|
+
moeda: 321,
|
69
|
+
idioma: "ES",
|
70
|
+
soft_descriptor: "soft_desc"
|
71
|
+
}
|
72
|
+
pedido = _.pedido @source, opts
|
73
|
+
|
74
|
+
opts.each { |k,v| pedido.send(k).must_equal opts[k] }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "valor handling" do
|
79
|
+
it "preserves valor if it's an integer" do
|
80
|
+
_.pedido(@source).valor.must_equal @source.valor
|
81
|
+
end
|
82
|
+
|
83
|
+
it "converts valor to integer number of cents if it's a float" do
|
84
|
+
def @source.valor ; 123.451 end
|
85
|
+
_.pedido(@source).valor.must_equal 12345
|
86
|
+
|
87
|
+
def @source.valor ; 123.456 end
|
88
|
+
_.pedido(@source).valor.must_equal 12346
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "Pagamento Building" do
|
94
|
+
before do
|
95
|
+
def @source.operacao ; :visa end
|
96
|
+
def @source.parcelas ; 2 end
|
97
|
+
end
|
98
|
+
|
99
|
+
it "asks for operacao / parcelas attributes when missing opts" do
|
100
|
+
pg = _.pagamento @source
|
101
|
+
pg.bandeira.must_equal "visa"
|
102
|
+
pg.parcelas.must_equal @source.parcelas
|
103
|
+
end
|
104
|
+
|
105
|
+
it "maps operacao / numero when opts are given" do
|
106
|
+
def @source.operation ; :mastercard end
|
107
|
+
def @source.installments ; 6 end
|
108
|
+
|
109
|
+
opts = { operacao: :operation, parcelas: :installments }
|
110
|
+
pg = _.pagamento @source, opts
|
111
|
+
|
112
|
+
pg.bandeira.must_equal @source.operation.to_s
|
113
|
+
pg.parcelas.must_equal @source.installments
|
114
|
+
end
|
115
|
+
|
116
|
+
it "get given operacao / numero values" do
|
117
|
+
opts = { operacao: "amex", parcelas: 9 }
|
118
|
+
pg = _.pagamento @source, opts
|
119
|
+
|
120
|
+
pg.bandeira.must_equal opts[:operacao]
|
121
|
+
pg.parcelas.must_equal opts[:parcelas]
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe "Transacao Building" do
|
126
|
+
let(:mappings) {
|
127
|
+
{
|
128
|
+
dados_pedido: _.pedido(@source),
|
129
|
+
forma_pagamento: _.pagamento(@source)
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
before do
|
134
|
+
@captura = Cieloz::Configuracao.captura_automatica
|
135
|
+
Cieloz::Configuracao.captura_automatica = true
|
136
|
+
Cieloz::Configuracao.url_retorno = "http://call.back"
|
137
|
+
|
138
|
+
def @source.operacao ; :visa end
|
139
|
+
def @source.parcelas ; 2 end
|
140
|
+
def @source.dados_portador ; @portador end
|
141
|
+
def @source.dados_pedido ; @pedido end
|
142
|
+
def @source.forma_pagamento ; @pagamento end
|
143
|
+
|
144
|
+
@portador = _.portador(@source)
|
145
|
+
@pedido = _.pedido(@source)
|
146
|
+
@pagamento = _.pagamento(@source)
|
147
|
+
|
148
|
+
@source.instance_variable_set :@portador, @portador
|
149
|
+
@source.instance_variable_set :@pedido, @pedido
|
150
|
+
@source.instance_variable_set :@pagamento, @pagamento
|
151
|
+
end
|
152
|
+
|
153
|
+
after do
|
154
|
+
Cieloz::Configuracao.captura_automatica = @captura
|
155
|
+
end
|
156
|
+
|
157
|
+
it "populates config values for url_retorno / captura_automatica when missing opts" do
|
158
|
+
txn = _.transacao @source
|
159
|
+
|
160
|
+
txn.url_retorno.must_equal Cieloz::Configuracao.url_retorno
|
161
|
+
txn.capturar.must_equal Cieloz::Configuracao.captura_automatica.to_s
|
162
|
+
end
|
163
|
+
|
164
|
+
it "maps attributes when opts are given" do
|
165
|
+
obj_mappings = {
|
166
|
+
dados_portador: :card_owner,
|
167
|
+
dados_pedido: :order,
|
168
|
+
forma_pagamento: :payment,
|
169
|
+
}
|
170
|
+
val_mappings = {
|
171
|
+
url_retorno: :callback_url,
|
172
|
+
capturar: :auto_capture,
|
173
|
+
campo_livre: :notes
|
174
|
+
}
|
175
|
+
|
176
|
+
def @source.card_owner ; @portador end
|
177
|
+
def @source.order ; @pedido end
|
178
|
+
def @source.payment ; @pagamento end
|
179
|
+
def @source.callback_url ; "http://ca.ll" end
|
180
|
+
def @source.auto_capture ; "true" end
|
181
|
+
def @source.notes ; "notes" end
|
182
|
+
|
183
|
+
txn = _.transacao @source, obj_mappings.merge(val_mappings)
|
184
|
+
obj_mappings.each { |k,v| txn.send(k).must_be_same_as @source.send(v) }
|
185
|
+
val_mappings.each { |k,v| txn.send(k).must_equal @source.send(v) }
|
186
|
+
end
|
187
|
+
|
188
|
+
it "gets given attribute values" do
|
189
|
+
values = {
|
190
|
+
dados_portador: @portador,
|
191
|
+
dados_pedido: @pedido,
|
192
|
+
forma_pagamento: @pagamento,
|
193
|
+
url_retorno: "http://call",
|
194
|
+
capturar: "false",
|
195
|
+
campo_livre: "livre"
|
196
|
+
}
|
197
|
+
txn = _.transacao @source, values
|
198
|
+
values.each { |k,v| txn.send(k).must_equal v }
|
199
|
+
end
|
200
|
+
|
201
|
+
it "triggers pagamento.operacao" do
|
202
|
+
_.transacao(@source).autorizar
|
203
|
+
.must_equal Cieloz::RequisicaoTransacao::AUTORIZACAO_DIRETA
|
204
|
+
|
205
|
+
["verified_by_visa", "mastercard_securecode"].each {|opr|
|
206
|
+
pg = _.pagamento @source, operacao: opr, parcelas: 2
|
207
|
+
_.transacao(@source, forma_pagamento: pg).autorizar
|
208
|
+
.must_equal Cieloz::RequisicaoTransacao::AUTORIZAR_SE_AUTENTICADA
|
209
|
+
}
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
describe Cieloz::Configuracao do
|
2
|
+
let(:_) { Cieloz::Configuracao }
|
3
|
+
let(:hash) { { numero: 123, chave: "abc123" } }
|
4
|
+
|
5
|
+
before do
|
6
|
+
_.reset!
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "defaults" do
|
10
|
+
it { _.moeda.must_equal 986 }
|
11
|
+
it { _.idioma.must_equal "PT" }
|
12
|
+
it { _.max_parcelas.must_equal 3 }
|
13
|
+
it { _.max_adm_parcelas.must_equal 10 }
|
14
|
+
it { _.captura_automatica.must_equal false }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "settings" do
|
18
|
+
before do
|
19
|
+
@cur, @lang, @max, @max_adm, @cap = _.moeda, _.idioma,
|
20
|
+
_.max_parcelas, _.max_adm_parcelas, _.captura_automatica
|
21
|
+
|
22
|
+
_.moeda = 123
|
23
|
+
_.idioma = "EN"
|
24
|
+
_.max_parcelas = 6
|
25
|
+
_.max_adm_parcelas = 12
|
26
|
+
_.captura_automatica = true
|
27
|
+
end
|
28
|
+
|
29
|
+
it { _.moeda.must_equal 123 }
|
30
|
+
it { _.idioma.must_equal "EN" }
|
31
|
+
it { _.max_parcelas.must_equal 6 }
|
32
|
+
it { _.max_adm_parcelas.must_equal 12 }
|
33
|
+
it { _.captura_automatica.must_equal true }
|
34
|
+
|
35
|
+
after do
|
36
|
+
_.moeda = @cur
|
37
|
+
_.idioma = @lang
|
38
|
+
_.max_parcelas = @max
|
39
|
+
_.max_adm_parcelas = @max_adm
|
40
|
+
_.captura_automatica = @cap
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "credenciais" do
|
45
|
+
describe "not set" do
|
46
|
+
it "defaults to Homologacao::Credenciais::CIELO" do
|
47
|
+
_.credenciais.must_equal Cieloz::Homologacao::Credenciais::CIELO
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns Homologacao::LOJA at store_mode" do
|
51
|
+
_.store_mode!
|
52
|
+
_.credenciais.must_equal Cieloz::Homologacao::Credenciais::LOJA
|
53
|
+
end
|
54
|
+
|
55
|
+
it "returns Homologacao::CIELO at cielo_mode" do
|
56
|
+
_.cielo_mode!
|
57
|
+
_.credenciais.must_equal Cieloz::Homologacao::Credenciais::CIELO
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "set" do
|
62
|
+
before { _.credenciais = hash }
|
63
|
+
|
64
|
+
it "returns DadosEc with credenciais attributes" do
|
65
|
+
_.credenciais.numero.must_equal hash[:numero]
|
66
|
+
_.credenciais.chave.must_equal hash[:chave]
|
67
|
+
end
|
68
|
+
|
69
|
+
it "returns the same DadosEc in subsequent calls" do
|
70
|
+
_.credenciais.must_equal _.credenciais
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "host" do
|
76
|
+
it "returns homologation host when credenciais is not set" do
|
77
|
+
_.host.must_equal Cieloz::Homologacao::HOST
|
78
|
+
end
|
79
|
+
|
80
|
+
it "returns production host when credenciais is set" do
|
81
|
+
_.credenciais = hash
|
82
|
+
_.host.must_equal Cieloz::Configuracao::HOST
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
describe Cieloz::RequisicaoAutorizacaoTid do
|
4
|
+
let(:_) { subject.class }
|
5
|
+
let(:dir) { File.dirname __FILE__ }
|
6
|
+
let(:opts) { { root: "requisicao-autorizacao-tid" } }
|
7
|
+
let(:ec) { _::DadosEc.new Cieloz::Homologacao::Credenciais::CIELO }
|
8
|
+
|
9
|
+
it "serializes tid" do
|
10
|
+
tid = 12345
|
11
|
+
subject.tid = tid
|
12
|
+
assert_equal expected_xml(opts) { "<tid>#{tid}</tid>" }, subject.to_xml
|
13
|
+
end
|
14
|
+
|
15
|
+
it "serializes dados-ec" do
|
16
|
+
subject.dados_ec = ec
|
17
|
+
assert_equal expected_xml(opts) { xml_for :ec, dir, binding }, subject.to_xml
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
describe Cieloz::RequisicaoCancelamento do
|
4
|
+
let(:_) { subject.class }
|
5
|
+
let(:dir) { File.dirname __FILE__ }
|
6
|
+
let(:opts) { { root: "requisicao-cancelamento" } }
|
7
|
+
let(:ec) { _::DadosEc.new Cieloz::Homologacao::Credenciais::CIELO }
|
8
|
+
|
9
|
+
it "serializes tid" do
|
10
|
+
tid = 12345
|
11
|
+
subject.tid = tid
|
12
|
+
assert_equal expected_xml(opts) { "<tid>#{tid}</tid>" }, subject.to_xml
|
13
|
+
end
|
14
|
+
|
15
|
+
it "serializes dados-ec" do
|
16
|
+
subject.dados_ec = ec
|
17
|
+
assert_equal expected_xml(opts) { xml_for :ec, dir, binding }, subject.to_xml
|
18
|
+
end
|
19
|
+
|
20
|
+
it "serializes valor" do
|
21
|
+
val = 123
|
22
|
+
subject.valor = val
|
23
|
+
assert_equal expected_xml(opts) { "<valor>#{val}</valor>" }, subject.to_xml
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
describe Cieloz::RequisicaoCaptura do
|
4
|
+
let(:_) { subject.class }
|
5
|
+
let(:dir) { File.dirname __FILE__ }
|
6
|
+
let(:opts) { { root: "requisicao-captura" } }
|
7
|
+
let(:ec) { _::DadosEc.new Cieloz::Homologacao::Credenciais::CIELO }
|
8
|
+
|
9
|
+
it "serializes tid" do
|
10
|
+
tid = 12345
|
11
|
+
subject.tid = tid
|
12
|
+
assert_equal expected_xml(opts) { "<tid>#{tid}</tid>" }, subject.to_xml
|
13
|
+
end
|
14
|
+
|
15
|
+
it "serializes dados-ec" do
|
16
|
+
subject.dados_ec = ec
|
17
|
+
assert_equal expected_xml(opts) { xml_for :ec, dir, binding }, subject.to_xml
|
18
|
+
end
|
19
|
+
|
20
|
+
it "serializes valor" do
|
21
|
+
val = 123
|
22
|
+
subject.valor = val
|
23
|
+
assert_equal expected_xml(opts) { "<valor>#{val}</valor>" }, subject.to_xml
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
describe Cieloz::RequisicaoConsulta do
|
4
|
+
let(:_) { subject.class }
|
5
|
+
let(:dir) { File.dirname __FILE__ }
|
6
|
+
let(:opts) { { root: "requisicao-consulta" } }
|
7
|
+
let(:ec) { _::DadosEc.new Cieloz::Homologacao::Credenciais::CIELO }
|
8
|
+
|
9
|
+
it "serializes tid" do
|
10
|
+
tid = 12345
|
11
|
+
subject.tid = tid
|
12
|
+
assert_equal expected_xml(opts) { "<tid>#{tid}</tid>" }, subject.to_xml
|
13
|
+
end
|
14
|
+
|
15
|
+
it "serializes dados-ec" do
|
16
|
+
subject.dados_ec = ec
|
17
|
+
assert_equal expected_xml(opts) { xml_for :ec, dir, binding }, subject.to_xml
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
describe Cieloz::Requisicao do
|
4
|
+
let(:_) { subject.class }
|
5
|
+
let(:id) { "1" }
|
6
|
+
let(:versao) { "1.2.0" }
|
7
|
+
let(:opts) { { root: "requisicao", id: id, versao: versao } }
|
8
|
+
|
9
|
+
let(:dir) { File.dirname __FILE__ }
|
10
|
+
|
11
|
+
before do
|
12
|
+
subject.id = id
|
13
|
+
subject.versao = versao
|
14
|
+
end
|
15
|
+
|
16
|
+
it "serializes" do
|
17
|
+
assert_equal expected_xml(opts), subject.to_xml
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "value attributes" do
|
21
|
+
before do
|
22
|
+
subject.class_eval do
|
23
|
+
attr_accessor :foo
|
24
|
+
|
25
|
+
def attributes
|
26
|
+
{ foo: @foo }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:foo) { "Informações Extras" }
|
32
|
+
|
33
|
+
it "serializes" do
|
34
|
+
subject.foo = foo
|
35
|
+
|
36
|
+
xml = expected_xml(opts) { "<foo>#{foo}</foo>" }
|
37
|
+
assert_equal xml, subject.to_xml
|
38
|
+
end
|
39
|
+
|
40
|
+
it "ignores nils" do
|
41
|
+
subject.foo = nil
|
42
|
+
assert_equal expected_xml(opts), subject.to_xml
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "complex attributes" do
|
47
|
+
let(:attributes) { { numero: 123, chave: "M3str4" } }
|
48
|
+
let(:ec) { _::DadosEc.new attributes }
|
49
|
+
let(:xml) { expected_xml(opts) { xml_for :ec, dir, binding } }
|
50
|
+
|
51
|
+
it "serializes" do
|
52
|
+
subject.dados_ec = ec
|
53
|
+
assert_equal xml, subject.to_xml
|
54
|
+
end
|
55
|
+
|
56
|
+
it "ignores nils" do
|
57
|
+
attributes.merge! ignore_me: nil
|
58
|
+
subject.dados_ec = ec
|
59
|
+
assert_equal xml, subject.to_xml
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "request posting" do
|
64
|
+
let(:err) { "101" }
|
65
|
+
let(:msg) { "Invalid" }
|
66
|
+
let(:fake_response) { render_template dir, "erro.xml", binding }
|
67
|
+
|
68
|
+
before do
|
69
|
+
FakeWeb.register_uri :post, Cieloz::Configuracao.url, body: fake_response
|
70
|
+
end
|
71
|
+
|
72
|
+
it "sends to test web service" do
|
73
|
+
subject.dados_ec = _::DadosEc.new Cieloz::Homologacao::Credenciais::CIELO
|
74
|
+
erro = subject.submit
|
75
|
+
assert_equal({}, subject.errors.messages)
|
76
|
+
assert_equal err, erro.codigo
|
77
|
+
assert_equal "Invalid", erro.mensagem
|
78
|
+
end
|
79
|
+
|
80
|
+
after do
|
81
|
+
FakeWeb.clean_registry
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
describe Cieloz::RequisicaoTransacao do
|
2
|
+
let(:_) { subject.class }
|
3
|
+
let(:dir) { File.dirname __FILE__ }
|
4
|
+
let(:opts) { { root: "requisicao-transacao" } }
|
5
|
+
|
6
|
+
let(:ec) { _::DadosEc.new Cieloz::Homologacao::Credenciais::CIELO }
|
7
|
+
let(:portador) { _::DadosPortador::TEST::VISA }
|
8
|
+
|
9
|
+
let(:now) { Time.now }
|
10
|
+
let(:pedido) {
|
11
|
+
_::DadosPedido.new numero: 123, valor: 5000, moeda: 986,
|
12
|
+
data_hora: now, descricao: "teste", idioma: "PT", soft_descriptor: "13letterstest"
|
13
|
+
}
|
14
|
+
let(:pagamento) { _::FormaPagamento.new.credito "visa" }
|
15
|
+
|
16
|
+
it "serializes dados-ec" do
|
17
|
+
subject.dados_ec = ec
|
18
|
+
assert_equal expected_xml(opts) { xml_for :ec, dir, binding }, subject.to_xml
|
19
|
+
end
|
20
|
+
|
21
|
+
it "serializes dados-portador" do
|
22
|
+
subject.dados_portador = portador
|
23
|
+
assert_equal expected_xml(opts) { xml_for :portador, dir, binding }, subject.to_xml
|
24
|
+
end
|
25
|
+
|
26
|
+
it "serializes dados-pedido" do
|
27
|
+
subject.dados_pedido = pedido
|
28
|
+
assert_equal expected_xml(opts) { xml_for :pedido, dir, binding }, subject.to_xml
|
29
|
+
end
|
30
|
+
|
31
|
+
it "serializes forma-pagamento" do
|
32
|
+
subject.forma_pagamento = pagamento
|
33
|
+
assert_equal expected_xml(opts) { xml_for :pagamento, dir, binding }, subject.to_xml
|
34
|
+
end
|
35
|
+
|
36
|
+
it "serializes simple attributes" do
|
37
|
+
subject.url_retorno = "http://callback.acti.on"
|
38
|
+
subject.autorizacao_direta
|
39
|
+
subject.capturar_automaticamente
|
40
|
+
subject.campo_livre = "I want to break free"
|
41
|
+
assert_equal expected_xml(opts) { xml_for :simple_attrs, dir, binding }, subject.to_xml
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "request posting" do
|
45
|
+
let(:status_txn) { "0" }
|
46
|
+
let(:tid) { "1001734898090FD31001" }
|
47
|
+
let(:url_cielo) {
|
48
|
+
"https://qasecommerce.cielo.com.br/web/index.cbmp?id=690ef010bfa77778f23da1a982d5d4cc"
|
49
|
+
}
|
50
|
+
let(:fake_response) { render_template dir, "transacao.xml", binding }
|
51
|
+
|
52
|
+
before do
|
53
|
+
portador.nome_portador = "Jose da Silva"
|
54
|
+
FakeWeb.register_uri :post, Cieloz::Configuracao.url, body: fake_response
|
55
|
+
end
|
56
|
+
|
57
|
+
after do
|
58
|
+
FakeWeb.clean_registry
|
59
|
+
end
|
60
|
+
|
61
|
+
it "sends to test web service" do
|
62
|
+
Cieloz::Configuracao.reset!
|
63
|
+
subject.id = SecureRandom.uuid
|
64
|
+
subject.versao = "1.2.0"
|
65
|
+
subject.dados_ec = ec
|
66
|
+
# txn.dados_portador = portador # buy page loja only!
|
67
|
+
subject.dados_pedido = pedido
|
68
|
+
subject.forma_pagamento = pagamento
|
69
|
+
subject.url_retorno = "http://localhost:3000/cielo/callback"
|
70
|
+
subject.autorizacao_direta
|
71
|
+
subject.capturar_automaticamente
|
72
|
+
subject.campo_livre = "debug"
|
73
|
+
|
74
|
+
res = subject.submit
|
75
|
+
assert_equal({}, subject.errors.messages)
|
76
|
+
assert_equal Cieloz::Requisicao::Transacao, res.class
|
77
|
+
assert_equal tid, res.tid
|
78
|
+
assert_equal status_txn, res.status
|
79
|
+
assert_equal url_cielo, res.url_autenticacao
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|