baby-braspag 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 13c6e3ecf69bd5dd355b5767532c41532065075d
4
- data.tar.gz: 615fc83e05cad85f928e30d082982c51c0777fd9
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YjBlNWI2NWMxYWE1MjI1ZjEwODgwMzc2NDZhM2Y4ZGY4YTIyNWI1Nw==
5
+ data.tar.gz: !binary |-
6
+ YjVmMWVhMTBlMzc4MjY3YzdhMTM5NzhjMTdjMmYyNWFkMjQ4OGI3Yg==
5
7
  SHA512:
6
- metadata.gz: 026127dec38a942f4cb32121e83153d5d74f74ad5454a9cdce55f8b5d387fcfc4776f15b453e52df4bb6d2f4169dd1467e5c90252b6b2567cbe76de35e7521ba
7
- data.tar.gz: b756eaf6c931641a8e083fab99f673a3b66300cd962a9bc3d25d1c7ca5c0fb77838c621f5d9206634a5e2c3af9a3d1ec40faba8f9036f109515068b7c6216edb
8
+ metadata.gz: !binary |-
9
+ YWY0MzM5Y2MzNWQ2MjYxYzYxYTU2ZmRlZTFhZDZmOTM3NjE5M2Q2MzlmOTJm
10
+ ZjJjMmIzYmRlOTg3ODYwNmU1YWI5YjQzMDk2ODc0MjRhZTZmNzVmNjg2Y2Vh
11
+ ZWMwNTM0MzhmZjY0MTkzZGU1ZjJlNTMwODQzMTIwMTZjODQwNTQ=
12
+ data.tar.gz: !binary |-
13
+ YTIyMjJkY2U0MzYxZTkxOTgzN2EyNWI4MGU4Nzc3YzEzZWNhYzBjOGM0ODgy
14
+ YzZlZDEwMjFjYTQzNTU4YTE1YjFjYmQyOWVjMTY4MjczNjJlY2UxYjY4ZGJl
15
+ ZGQwOGQyOTVjZTBkOGY5MjIyMGEwYzc0MmRiZjU2NWZmMjBkMWE=
@@ -1,5 +1,9 @@
1
1
  # RELEASES
2
2
 
3
+ ## 0.4.1 - 07/07/2015
4
+
5
+ 5d754a Corrigindo consulta de cartão protegido.
6
+
3
7
  ## 0.2.1 - 11/08/2014
4
8
 
5
9
  Log das operações `SaveCreditCard` e `JustClickShop` do serviço `CartaoProtegido`.
@@ -23,9 +23,7 @@ module Braspag
23
23
  :security_code => "SecurityCode"
24
24
  }
25
25
 
26
- SAVE_PROTECTED_CARD_URI = "/CartaoProtegido.asmx?wsdl"
27
- GET_PROTECTED_CARD_URI = "/CartaoProtegido.asmx/GetCreditCard"
28
- JUST_CLICK_SHOP_URI = "/CartaoProtegido.asmx?wsdl"
26
+ PROTECTED_CARD_URI = "/CartaoProtegido.asmx?wsdl"
29
27
 
30
28
  # saves credit card in Braspag PCI Compliant
31
29
  def self.save(params = {})
@@ -45,7 +43,7 @@ module Braspag
45
43
 
46
44
  Braspag.logger.info("[Braspag] #save_credit_card, data: #{data_for_logging}") if Braspag.logger
47
45
 
48
- client = savon_client(self.save_protected_card_url)
46
+ client = savon_client(self.protected_card_url)
49
47
  response = client.call(:save_credit_card, :message => data)
50
48
 
51
49
  # We do not want to let any sensitive data exposed on log files.
@@ -62,16 +60,18 @@ module Braspag
62
60
 
63
61
  raise InvalidJustClickKey unless valid_just_click_key?(just_click_key)
64
62
 
65
- data = { 'getCreditCardRequestWS' => {:loja => connection.merchant_id, :justClickKey => just_click_key} }
63
+ request_data = { 'MerchantKey' => connection.merchant_id, 'JustClickKey' => just_click_key }
64
+ data = { 'getCreditCardRequestWS' => request_data }
66
65
 
67
- response = Braspag::Poster.new(self.get_protected_card_url).do_post(:get_protected_card, data)
66
+ client = savon_client(self.protected_card_url)
67
+ response = client.call(:get_credit_card, message: data)
68
68
 
69
- response = Utils::convert_to_map(response.body, {
70
- :holder => "CardHolder",
71
- :card_number => "CardNumber",
72
- :expiration => "CardExpiration",
73
- :masked_card_number => "MaskedCardNumber"
74
- })
69
+ response = Utils::convert_to_map(response.to_s, {
70
+ :holder => 'CardHolder',
71
+ :card_number => 'CardNumber',
72
+ :expiration => 'CardExpiration',
73
+ :masked_card_number => 'MaskedCardNumber'
74
+ })
75
75
 
76
76
  raise UnknownError if response[:card_number].nil?
77
77
  response
@@ -105,7 +105,7 @@ module Braspag
105
105
 
106
106
  Braspag.logger.info("[Braspag] #just_click_shop, data: #{data_for_logging}") if Braspag.logger
107
107
 
108
- client = savon_client(self.just_click_shop_url)
108
+ client = savon_client(self.protected_card_url)
109
109
  response = client.call(:just_click_shop, :message => data)
110
110
 
111
111
  Braspag.logger.info("[Braspag] #just_click_shop returns: #{response}") if Braspag.logger
@@ -150,16 +150,8 @@ module Braspag
150
150
  (just_click_key.is_a?(String) && just_click_key.size == 36)
151
151
  end
152
152
 
153
- def self.save_protected_card_url
154
- Braspag::Connection.instance.protected_card_url + SAVE_PROTECTED_CARD_URI
155
- end
156
-
157
- def self.get_protected_card_url
158
- Braspag::Connection.instance.protected_card_url + GET_PROTECTED_CARD_URI
159
- end
160
-
161
- def self.just_click_shop_url
162
- Braspag::Connection.instance.protected_card_url + JUST_CLICK_SHOP_URI
153
+ def self.protected_card_url
154
+ Braspag::Connection.instance.protected_card_url + PROTECTED_CARD_URI
163
155
  end
164
156
 
165
157
  def self.savon_client(url)
@@ -6,6 +6,7 @@ module Braspag
6
6
 
7
7
  def self.convert_to_map(document, map = {})
8
8
  document = Nokogiri::XML(document)
9
+ document.remove_namespaces!
9
10
 
10
11
  map.each do |key, value|
11
12
  if value.is_a?(String) || value.nil?
@@ -1,3 +1,3 @@
1
1
  module Braspag
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -69,7 +69,7 @@ describe Braspag::ProtectedCreditCard do
69
69
  end
70
70
 
71
71
  before do
72
- Braspag::ProtectedCreditCard.should_receive(:save_protected_card_url)
72
+ Braspag::ProtectedCreditCard.should_receive(:protected_card_url)
73
73
  Braspag::ProtectedCreditCard.should_receive(:check_protected_card_params)
74
74
  .and_return(true)
75
75
  @connection.should_receive(:savon_client).and_return(savon_double)
@@ -158,7 +158,7 @@ describe Braspag::ProtectedCreditCard do
158
158
  before do
159
159
  Braspag::ProtectedCreditCard.should_receive(:check_protected_card_params)
160
160
  .and_return(true)
161
- Braspag::ProtectedCreditCard.should_receive(:save_protected_card_url)
161
+ Braspag::ProtectedCreditCard.should_receive(:protected_card_url)
162
162
  .and_return(save_protected_card_url)
163
163
  @connection.should_receive(:savon_client).and_return(savon_double)
164
164
  savon_double.should_receive(:call).and_return(response)
@@ -176,36 +176,71 @@ describe Braspag::ProtectedCreditCard do
176
176
  end
177
177
  end
178
178
 
179
+ class SavonClientTest
180
+ attr_accessor :response
181
+ attr_reader :method
182
+
183
+ def call(method, options, &block)
184
+ @method = method
185
+ @options = options
186
+
187
+ @response
188
+ end
189
+
190
+ def options
191
+ OpenStruct.new(@options || {})
192
+ end
193
+ end
194
+
179
195
  describe ".get" do
180
196
  let(:get_protected_card_url) { "http://braspag/bla" }
181
197
 
182
198
  let(:invalid_xml) do
183
199
  <<-EOXML
184
- <CartaoProtegidoReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
185
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
186
- xmlns="http://www.pagador.com.br/">
187
- <CardHolder>Joao Maria Souza</CardHolder>
188
- <CardNumber></CardNumber>
189
- <CardExpiration>10/12</CardExpiration>
190
- <MaskedCardNumber>******9999</MaskedCardNumber>
191
- </CartaoProtegidoReturn>
200
+ <?xml version="1.0" encoding="utf-8"?>
201
+ <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
202
+ <soap:Body>
203
+ <GetCreditCardResponse xmlns="http://www.cartaoprotegido.com.br/WebService/">
204
+ <GetCreditCardResult>
205
+ <Success>false</Success>
206
+ <CorrelationId xsi:nil="true"/>
207
+ <ErrorReportCollection>
208
+ <ErrorReport>
209
+ <ErrorCode>720</ErrorCode>
210
+ <ErrorMessage>Merchant JustClick not found</ErrorMessage>
211
+ </ErrorReport>
212
+ </ErrorReportCollection>
213
+ </GetCreditCardResult>
214
+ </GetCreditCardResponse>
215
+ </soap:Body>
216
+ </soap:Envelope>
192
217
  EOXML
193
218
  end
194
219
 
195
220
  let(:valid_xml) do
196
221
  <<-EOXML
197
- <CartaoProtegidoReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
198
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
199
- xmlns="http://www.pagador.com.br/">
200
- <CardHolder>Joao Maria Souza</CardHolder>
201
- <CardNumber>9999999999</CardNumber>
202
- <CardExpiration>10/12</CardExpiration>
203
- <MaskedCardNumber>******9999</MaskedCardNumber>
204
- </CartaoProtegidoReturn>
222
+ <?xml version="1.0" encoding="utf-8"?>
223
+ <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
224
+ <soap:Body>
225
+ <GetCreditCardResponse xmlns="http://www.cartaoprotegido.com.br/WebService/">
226
+ <GetCreditCardResult>
227
+ <Success>true</Success>
228
+ <CorrelationId xsi:nil="true"/>
229
+ <ErrorReportCollection/>
230
+ <CardHolder>TESTE HOLDER</CardHolder>
231
+ <CardNumber>0000000000000001</CardNumber>
232
+ <CardExpiration>12/2021</CardExpiration>
233
+ <MaskedCardNumber>000000******0001</MaskedCardNumber>
234
+ </GetCreditCardResult>
235
+ </GetCreditCardResponse>
236
+ </soap:Body>
237
+ </soap:Envelope>
205
238
  EOXML
206
239
  end
207
240
 
208
241
  let(:logger) { mock(:info => nil) }
242
+ let(:savon_client) { SavonClientTest.new }
243
+
209
244
  before { Braspag.logger = logger }
210
245
 
211
246
  it "should raise an error when just click key is not valid" do
@@ -219,10 +254,8 @@ describe Braspag::ProtectedCreditCard do
219
254
  end
220
255
 
221
256
  it "should raise an error when Braspag returned an invalid xml as response" do
222
- FakeWeb.register_uri(:post, get_protected_card_url, :body => invalid_xml)
223
-
224
- Braspag::ProtectedCreditCard.should_receive(:get_protected_card_url)
225
- .and_return(get_protected_card_url)
257
+ Braspag::ProtectedCreditCard.should_receive(:savon_client)
258
+ .and_return(savon_client)
226
259
 
227
260
  expect {
228
261
  Braspag::ProtectedCreditCard.get("b0b0b0b0-bbbb-4d4d-bd27-f1f1f1ededed")
@@ -230,20 +263,26 @@ describe Braspag::ProtectedCreditCard do
230
263
  end
231
264
 
232
265
  it "should return a Hash when Braspag returned a valid xml as response" do
233
- FakeWeb.register_uri(:post, get_protected_card_url, :body => valid_xml)
234
-
235
- Braspag::ProtectedCreditCard.should_receive(:get_protected_card_url)
266
+ Braspag::ProtectedCreditCard.should_receive(:protected_card_url)
236
267
  .and_return(get_protected_card_url)
237
268
 
269
+ savon_client.response = valid_xml
270
+
271
+ Braspag::ProtectedCreditCard.should_receive(:savon_client)
272
+ .and_return(savon_client)
273
+
238
274
  response = Braspag::ProtectedCreditCard.get("b0b0b0b0-bbbb-4d4d-bd27-f1f1f1ededed")
239
- response.should be_kind_of Hash
240
275
 
241
- response.should == {
242
- :holder => "Joao Maria Souza",
243
- :expiration => "10/12",
244
- :card_number => "9" * 10,
245
- :masked_card_number => "*" * 6 + "9" * 4
276
+ expect(response).to be_kind_of Hash
277
+
278
+ expected = {
279
+ :holder => "TESTE HOLDER",
280
+ :expiration => "12/2021",
281
+ :card_number => "0000000000000001",
282
+ :masked_card_number => "000000******0001"
246
283
  }
284
+
285
+ expect(response).to eq(expected)
247
286
  end
248
287
 
249
288
  end
@@ -264,22 +303,6 @@ describe Braspag::ProtectedCreditCard do
264
303
 
265
304
  let(:logger) { mock(:info => nil) }
266
305
 
267
- class SavonClientTest
268
- attr_accessor :response
269
- attr_reader :method
270
-
271
- def call(method, options, &block)
272
- @method = method
273
- @options = options
274
-
275
- @response
276
- end
277
-
278
- def options
279
- OpenStruct.new(@options || {})
280
- end
281
- end
282
-
283
306
  before do
284
307
  Braspag.stub(:logger => logger)
285
308
  @savon_client_test = SavonClientTest.new
@@ -360,11 +383,10 @@ describe Braspag::ProtectedCreditCard do
360
383
  end
361
384
  end
362
385
 
363
- it ".save_protected_card_url .get_protected_card_url" do
386
+ it ".protected_card_url" do
364
387
  @connection.stub(:protected_card_url => braspag_homologation_protected_card_url)
365
388
 
366
- Braspag::ProtectedCreditCard.save_protected_card_url.should == "#{braspag_homologation_protected_card_url}/CartaoProtegido.asmx?wsdl"
367
- Braspag::ProtectedCreditCard.get_protected_card_url.should == "#{braspag_homologation_protected_card_url}/CartaoProtegido.asmx/GetCreditCard"
389
+ expect(Braspag::ProtectedCreditCard.protected_card_url).to eq("#{braspag_homologation_protected_card_url}/CartaoProtegido.asmx?wsdl")
368
390
  end
369
391
 
370
392
  end
@@ -24,23 +24,64 @@ describe Braspag::Utils do
24
24
  XML
25
25
  end
26
26
 
27
+ let(:namespaced_document) do
28
+ <<-XML
29
+ <?xml version="1.0" encoding="utf-8"?>
30
+ <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
31
+ <soap:Body>
32
+ <GetCreditCardResponse xmlns="http://www.cartaoprotegido.com.br/WebService/">
33
+ <GetCreditCardResult>
34
+ <Success>true</Success>
35
+ <CorrelationId xsi:nil="true"/>
36
+ <ErrorReportCollection/>
37
+ <CardHolder>TESTE HOLDER</CardHolder>
38
+ <CardNumber>0000000000000001</CardNumber>
39
+ <CardExpiration>12/2021</CardExpiration>
40
+ <MaskedCardNumber>000000******0001</MaskedCardNumber>
41
+ </GetCreditCardResult>
42
+ </GetCreditCardResponse>
43
+ </soap:Body>
44
+ </soap:Envelope>
45
+ XML
46
+ end
47
+
27
48
  context "basic document and keys" do
28
- it "should return a Hash" do
49
+ it "returns a Hash" do
29
50
  keys = { :foo => nil, :meu_elemento => "bar", :outro_elemento => "baz" }
30
51
  expected = { :foo => "blabla", :meu_elemento => "bleble", :outro_elemento => nil }
31
52
 
32
- Braspag::Utils::convert_to_map(document, keys).should == expected
53
+ expect(Braspag::Utils::convert_to_map(document, keys)).to eq(expected)
33
54
  end
34
55
  end
35
56
 
36
57
  context "keys with a Proc" do
37
- it "should return a Hash" do
58
+ it "returns a Hash" do
38
59
  proc = Proc.new { "value returned by Proc" }
39
60
 
40
61
  keys = { :foo => proc, :meu_elemento => "bar", :outro_elemento => "baz" }
41
62
  expected = { :foo => "value returned by Proc", :meu_elemento => "bleble", :outro_elemento => nil }
42
63
 
43
- Braspag::Utils::convert_to_map(document, keys).should == expected
64
+ expect(Braspag::Utils::convert_to_map(document, keys)).to eq(expected)
65
+ end
66
+ end
67
+
68
+ context "when document contains namespaces" do
69
+ it "finds the correct Hash values" do
70
+ keys = {
71
+ holder: "CardHolder",
72
+ card_number: "CardNumber",
73
+ expiration: "CardExpiration",
74
+ masked_card_number: "MaskedCardNumber"
75
+ }
76
+
77
+ expected = {
78
+ :holder => "TESTE HOLDER",
79
+ :expiration => "12/2021",
80
+ :card_number => "0000000000000001",
81
+ :masked_card_number => "000000******0001"
82
+ }
83
+
84
+ expect(Braspag::Utils.convert_to_map(namespaced_document, keys)).to eq(expected)
44
85
  end
45
86
  end
46
87
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baby-braspag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - baby dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-19 00:00:00.000000000 Z
11
+ date: 2015-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpi
@@ -28,14 +28,14 @@ dependencies:
28
28
  name: json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.6.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.6.1
41
41
  - !ruby/object:Gem::Dependency
@@ -70,14 +70,14 @@ dependencies:
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ! '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ! '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
@@ -98,75 +98,75 @@ dependencies:
98
98
  name: fakeweb
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ! '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ! '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: shoulda-matchers
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '>='
115
+ - - ! '>='
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '>='
122
+ - - ! '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: guard-rspec
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - '>='
129
+ - - ! '>='
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - '>='
136
+ - - ! '>='
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: guard-bundler
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - '>='
143
+ - - ! '>='
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - '>='
150
+ - - ! '>='
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: debugger
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - '>='
157
+ - - ! '>='
158
158
  - !ruby/object:Gem::Version
159
159
  version: '0'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - '>='
164
+ - - ! '>='
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  description: baby braspag gem to use Braspag gateway
168
168
  email:
169
- - '"dev-team@baby.com.br"'
169
+ - ! '"dev-team@baby.com.br"'
170
170
  executables: []
171
171
  extensions: []
172
172
  extra_rdoc_files: []
@@ -216,17 +216,17 @@ require_paths:
216
216
  - lib
217
217
  required_ruby_version: !ruby/object:Gem::Requirement
218
218
  requirements:
219
- - - '>='
219
+ - - ! '>='
220
220
  - !ruby/object:Gem::Version
221
221
  version: '0'
222
222
  required_rubygems_version: !ruby/object:Gem::Requirement
223
223
  requirements:
224
- - - '>='
224
+ - - ! '>='
225
225
  - !ruby/object:Gem::Version
226
226
  version: '0'
227
227
  requirements: []
228
228
  rubyforge_project: baby-braspag
229
- rubygems_version: 2.4.6
229
+ rubygems_version: 2.4.5
230
230
  signing_key:
231
231
  specification_version: 4
232
232
  summary: baby braspag gem to use Braspag gateway