mundipagg_api 1.3.0 → 1.3.1
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 +4 -4
- data/lib/mundipagg/MundipaggApi.rb +72 -42
- data/mundipagg-api.gemspec +1 -1
- data/spec/integration/gateway_spec.rb +68 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca60e5c2427004bb2f91e75ce0ce051699345bfc
|
4
|
+
data.tar.gz: 7c1361a4186f8218e08406be78e01ed74c6795bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebf6a8047ba0de4887fdf33b3dec12e2eb3259345ccc0e7bcacfc166151bde54345593d723ab3f3df1bd00b3ce8f3dd2510231c3b7bd9efb26a4eaeef902a14e
|
7
|
+
data.tar.gz: 591550134c8c17c7768fb4432726270547a109d8bc1464e93fc49a406d5d444c951954eccf7b473ffb22f9e8d085a93223b378fb5e4c51222a83ac417cc50975
|
@@ -18,28 +18,30 @@ class MundipaggApi
|
|
18
18
|
# URL de homologacao
|
19
19
|
@@SERVICE_URL_STAGING = 'https://stagingv2.mundipaggone.com'
|
20
20
|
|
21
|
+
# URL de sandbox
|
22
|
+
@@SERVICE_URL_SANDBOX = 'https://sandbox.mundipaggone.com'
|
23
|
+
|
21
24
|
# permite que o integrador adicione uma busca por transacoes utilizando alguns criterios
|
22
25
|
def Query(querySaleRequestEnum, key)
|
23
26
|
# try, tenta fazer o request
|
24
27
|
begin
|
25
|
-
|
26
28
|
# se for homologacao faz a chamada por aqui
|
27
29
|
if @serviceEnvironment == :staging
|
28
|
-
|
30
|
+
getRequest(@@SERVICE_URL_STAGING + '/Sale/Query/' + querySaleRequestEnum + '=' + key)
|
29
31
|
|
30
32
|
# se for producao, faz a chamada por aqui
|
31
33
|
elsif @serviceEnvironment == :production
|
32
|
-
|
34
|
+
getRequest(@@SERVICE_URL_PRODUCTION + '/Sale/Query/' + querySaleRequestEnum + '=' + key)
|
35
|
+
|
36
|
+
# se for sandbox
|
37
|
+
elsif @serviceEnvironment == :sandbox
|
38
|
+
getRequest(@@SERVICE_URL_SANDBOX + '/Sale/Query/' + querySaleRequestEnum + '=' + key)
|
33
39
|
end
|
34
40
|
|
35
41
|
# se der algum erro, trata aqui
|
36
|
-
rescue
|
37
|
-
return
|
42
|
+
rescue Exception => e
|
43
|
+
return e.message
|
38
44
|
end
|
39
|
-
|
40
|
-
# se nao houver erros, trata o json e retorna o objeto
|
41
|
-
querySaleResponse = JSON.load response
|
42
|
-
querySaleResponse
|
43
45
|
end
|
44
46
|
|
45
47
|
# criar uma transacao na plataforma One utilizando um ou mais meios de pagamento
|
@@ -177,30 +179,37 @@ class MundipaggApi
|
|
177
179
|
end
|
178
180
|
|
179
181
|
# transforma o objeto Buyer em json
|
180
|
-
if createSaleRequest.Buyer.
|
182
|
+
if createSaleRequest.Buyer.AddressCollection.any?
|
181
183
|
b = createSaleRequest.Buyer.to_json
|
182
184
|
saleHash['Buyer'] = b
|
183
185
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
saleHash['Buyer']['AddressCollection'] << a
|
189
|
-
end
|
190
|
-
else
|
191
|
-
saleHash['Buyer']['AddressCollection'] = nil
|
186
|
+
saleHash['Buyer']['AddressCollection'] = []
|
187
|
+
createSaleRequest.Buyer.AddressCollection.each do |address|
|
188
|
+
a = address.to_json
|
189
|
+
saleHash['Buyer']['AddressCollection'] << a
|
192
190
|
end
|
193
191
|
else
|
194
|
-
|
192
|
+
buyer_hash = createSaleRequest.Buyer.to_json
|
193
|
+
buyer_hash.delete('AddressCollection')
|
194
|
+
if buyer_hash.blank? == false
|
195
|
+
b = createSaleRequest.Buyer.to_json
|
196
|
+
saleHash['Buyer'] = b
|
197
|
+
saleHash['Buyer']['AddressCollection'] = nil
|
198
|
+
else
|
199
|
+
saleHash['Buyer'] = nil
|
200
|
+
end
|
195
201
|
end
|
202
|
+
|
196
203
|
rescue Exception => e
|
197
|
-
|
204
|
+
return e.message
|
198
205
|
end
|
199
206
|
|
200
207
|
if @serviceEnvironment == :staging
|
201
208
|
url = @@SERVICE_URL_STAGING + '/Sale/'
|
202
209
|
elsif @serviceEnvironment == :production
|
203
210
|
url = @@SERVICE_URL_PRODUCTION + '/Sale/'
|
211
|
+
elsif @serviceEnvironment == :sandbox
|
212
|
+
url = @@SERVICE_URL_SANDBOX + '/Sale/'
|
204
213
|
end
|
205
214
|
postRequest(saleHash.to_json, url)
|
206
215
|
end
|
@@ -225,12 +234,14 @@ class MundipaggApi
|
|
225
234
|
end
|
226
235
|
end
|
227
236
|
rescue Exception => e
|
228
|
-
|
237
|
+
return e.message
|
229
238
|
end
|
230
239
|
if @serviceEnvironment == :staging
|
231
240
|
url = @@SERVICE_URL_STAGING + '/Sale/Retry'
|
232
241
|
elsif @serviceEnvironment == :production
|
233
242
|
url = @@SERVICE_URL_PRODUCTION + '/Sale/Retry'
|
243
|
+
elsif @serviceEnvironment == :sandbox
|
244
|
+
url = @@SERVICE_URL_SANDBOX + '/Sale/Retry'
|
234
245
|
end
|
235
246
|
postRequest(saleHash.to_json, url)
|
236
247
|
end
|
@@ -248,12 +259,14 @@ class MundipaggApi
|
|
248
259
|
end
|
249
260
|
end
|
250
261
|
rescue Exception => e
|
251
|
-
|
262
|
+
return e.message
|
252
263
|
end
|
253
264
|
if @serviceEnvironment == :staging
|
254
265
|
url = @@SERVICE_URL_STAGING + '/Sale/Cancel'
|
255
266
|
elsif @serviceEnvironment == :production
|
256
267
|
url = @@SERVICE_URL_PRODUCTION + '/Sale/Cancel'
|
268
|
+
elsif @serviceEnvironment == :sandbox
|
269
|
+
url = @@SERVICE_URL_SANDBOX + '/Sale/Cancel'
|
257
270
|
end
|
258
271
|
postRequest(saleHash.to_json, url)
|
259
272
|
end
|
@@ -271,12 +284,14 @@ class MundipaggApi
|
|
271
284
|
end
|
272
285
|
end
|
273
286
|
rescue Exception => e
|
274
|
-
|
287
|
+
return e.message
|
275
288
|
end
|
276
289
|
if @serviceEnvironment == :staging
|
277
290
|
url = @@SERVICE_URL_STAGING + '/Sale/Capture'
|
278
291
|
elsif @serviceEnvironment == :production
|
279
292
|
url = @@SERVICE_URL_PRODUCTION + '/Sale/Capture'
|
293
|
+
elsif @serviceEnvironment == :sandbox
|
294
|
+
url = @@SERVICE_URL_SANDBOX + '/Sale/Capture'
|
280
295
|
end
|
281
296
|
postRequest(saleHash.to_json, url)
|
282
297
|
end
|
@@ -286,7 +301,7 @@ class MundipaggApi
|
|
286
301
|
begin
|
287
302
|
response = PostNotification.ParseNotification(xml)
|
288
303
|
rescue Exception => err
|
289
|
-
return err.
|
304
|
+
return err.message
|
290
305
|
end
|
291
306
|
|
292
307
|
return response
|
@@ -318,7 +333,7 @@ class MundipaggApi
|
|
318
333
|
transaction_report_file = TransactionReportFile.new
|
319
334
|
begin
|
320
335
|
response = transaction_report_file.TransactionReportFileParser(file_to_parse)
|
321
|
-
rescue Exception=>err
|
336
|
+
rescue Exception => err
|
322
337
|
return err
|
323
338
|
end
|
324
339
|
return response
|
@@ -331,21 +346,21 @@ class MundipaggApi
|
|
331
346
|
|
332
347
|
# se for homologacao faz a chamada por aqui
|
333
348
|
if @serviceEnvironment == :staging
|
334
|
-
|
349
|
+
getRequest(@@SERVICE_URL_STAGING + '/CreditCard/' + instant_buy_key)
|
335
350
|
|
336
351
|
# se for producao, faz a chamada por aqui
|
337
352
|
elsif @serviceEnvironment == :production
|
338
|
-
|
353
|
+
getRequest(@@SERVICE_URL_PRODUCTION + '/CreditCard/' + instant_buy_key)
|
354
|
+
|
355
|
+
# se for sandbox
|
356
|
+
elsif @serviceEnvironment == :sandbox
|
357
|
+
getRequest(@@SERVICE_URL_SANDBOX + '/CreditCard/' + instant_buy_key)
|
339
358
|
end
|
340
359
|
|
341
360
|
# se der algum erro, trata aqui
|
342
|
-
rescue
|
343
|
-
return
|
361
|
+
rescue Exception => e
|
362
|
+
return e.message
|
344
363
|
end
|
345
|
-
|
346
|
-
# se nao houver erros, trata o json e retorna o objeto
|
347
|
-
instant_buy_response = JSON.load response
|
348
|
-
instant_buy_response
|
349
364
|
end
|
350
365
|
|
351
366
|
# faz uma requisicao com buyer key
|
@@ -355,21 +370,24 @@ class MundipaggApi
|
|
355
370
|
|
356
371
|
# se for homologacao faz a chamada por aqui
|
357
372
|
if @serviceEnvironment == :staging
|
358
|
-
response =
|
373
|
+
response = getRequest(@@SERVICE_URL_STAGING + '/CreditCard/' + buyer_key + '/BuyerKey')
|
359
374
|
|
360
375
|
# se for producao, faz a chamada por aqui
|
361
376
|
elsif @serviceEnvironment == :production
|
362
|
-
response =
|
377
|
+
response = getRequest(@@SERVICE_URL_PRODUCTION + '/CreditCard/' + buyer_key + '/BuyerKey')
|
378
|
+
|
379
|
+
# se for sandbox, faz a chamada por aqui
|
380
|
+
elsif @serviceEnvironment == :sandbox
|
381
|
+
response = getRequest(@@SERVICE_URL_SANDBOX + '/CreditCard/' + buyer_key + '/BuyerKey')
|
363
382
|
end
|
364
383
|
|
365
|
-
|
366
|
-
rescue
|
367
|
-
return
|
384
|
+
# se der algum erro, trata aqui
|
385
|
+
rescue Exception => e
|
386
|
+
return e.message
|
368
387
|
end
|
369
388
|
|
370
|
-
# se nao houver erros,
|
371
|
-
|
372
|
-
buyer_response
|
389
|
+
# se nao houver erros, retorna o objeto
|
390
|
+
response
|
373
391
|
end
|
374
392
|
|
375
393
|
# funcao de post generica
|
@@ -378,7 +396,19 @@ class MundipaggApi
|
|
378
396
|
begin
|
379
397
|
response = RestClient.post(url, payload, headers=@@SERVICE_HEADERS)
|
380
398
|
rescue RestClient::ExceptionWithResponse => err
|
381
|
-
return err.response
|
399
|
+
return err.response
|
400
|
+
end
|
401
|
+
json_response = JSON.load response
|
402
|
+
json_response
|
403
|
+
end
|
404
|
+
|
405
|
+
# funcao get generica
|
406
|
+
def getRequest(url)
|
407
|
+
response = nil
|
408
|
+
begin
|
409
|
+
response = RestClient.get(url, headers=@@SERVICE_HEADERS)
|
410
|
+
rescue RestClient::ExceptionWithResponse => err
|
411
|
+
return err.response
|
382
412
|
end
|
383
413
|
json_response = JSON.load response
|
384
414
|
json_response
|
data/mundipagg-api.gemspec
CHANGED
@@ -2,7 +2,7 @@ Gem::Specification.new do |s|
|
|
2
2
|
s.name = 'mundipagg_api'
|
3
3
|
s.summary = 'MundiPagg Ruby Client Library'
|
4
4
|
s.description = 'Ruby library for integrating with the MundiPagg payment web services'
|
5
|
-
s.version = '1.3.
|
5
|
+
s.version = '1.3.1' # Major.Minor.Revision
|
6
6
|
s.author = 'MundiPagg'
|
7
7
|
s.email = 'github@mundipagg.com'
|
8
8
|
s.homepage = 'http://www.mundipagg.com/'
|
@@ -2,7 +2,7 @@ require_relative '../../lib/mundipagg_api'
|
|
2
2
|
require_relative 'test_helper'
|
3
3
|
|
4
4
|
merchant_key = 'merchantKey'
|
5
|
-
gateway = MundipaggApi.new(:
|
5
|
+
gateway = MundipaggApi.new(:sandbox, merchant_key)
|
6
6
|
|
7
7
|
RSpec.describe MundipaggApi do
|
8
8
|
it 'should create a sale with boleto' do
|
@@ -173,6 +173,9 @@ RSpec.describe MundipaggApi do
|
|
173
173
|
shoppingCartCollectionItem.ShoppingCartItemCollection << shoppingCartItem
|
174
174
|
|
175
175
|
createSaleRequest = CreateSaleRequest.new
|
176
|
+
|
177
|
+
createSaleRequest.Buyer.AddressCollection = Array.new
|
178
|
+
|
176
179
|
createSaleRequest.Buyer.Birthdate = Date.new(1990, 3, 3).strftime("%Y-%m-%dT%H:%M:%S")
|
177
180
|
createSaleRequest.Buyer.DocumentNumber = '12345678901'
|
178
181
|
createSaleRequest.Buyer.DocumentType = 'CPF'
|
@@ -514,28 +517,87 @@ RSpec.describe MundipaggApi do
|
|
514
517
|
file_path = "C:\\Users\\Public\\Documents\\"
|
515
518
|
gateway.TransactionReportFileDownloader(date, file_name, file_path)
|
516
519
|
|
517
|
-
file_path = file_path +
|
520
|
+
file_path = file_path + file_name + '.txt'
|
518
521
|
file_exist = File.exist?(file_path)
|
519
522
|
expect(file_exist).to eq true
|
520
523
|
end
|
521
524
|
|
522
525
|
it 'should consult transaction with instant buy key' do
|
523
|
-
|
526
|
+
credit_card_transaction = CreditCardTransaction.new
|
527
|
+
credit_card_transaction.CreditCard.CreditCardNumber = '4111111111111111'
|
528
|
+
credit_card_transaction.CreditCard.CreditCardBrand = 'Visa'
|
529
|
+
credit_card_transaction.CreditCard.ExpMonth = 10
|
530
|
+
credit_card_transaction.CreditCard.ExpYear = 2018
|
531
|
+
credit_card_transaction.CreditCard.SecurityCode = '123'
|
532
|
+
credit_card_transaction.CreditCard.HolderName = 'Luke Skywalker'
|
533
|
+
credit_card_transaction.AmountInCents = 100
|
534
|
+
|
535
|
+
sale_request = CreateSaleRequest.new
|
536
|
+
sale_request.CreditCardTransactionCollection << credit_card_transaction
|
537
|
+
|
538
|
+
sale_response = gateway.CreateSale(sale_request)
|
539
|
+
|
540
|
+
expect(sale_response['ErrorReport']).to eq nil
|
541
|
+
|
542
|
+
instant_buy_key = sale_response['CreditCardTransactionResultCollection'][0]['CreditCard']['InstantBuyKey']
|
543
|
+
|
544
|
+
response = gateway.InstantBuyKey(instant_buy_key)
|
524
545
|
|
525
546
|
expect(response['ErrorReport']).to eq nil
|
526
547
|
end
|
527
548
|
|
528
549
|
it 'should consult transaction with buyer key' do
|
529
|
-
|
530
|
-
|
550
|
+
|
551
|
+
credit_card_transaction = CreditCardTransaction.new
|
552
|
+
credit_card_transaction.CreditCard.CreditCardNumber = '4111111111111111'
|
553
|
+
credit_card_transaction.CreditCard.CreditCardBrand = 'Visa'
|
554
|
+
credit_card_transaction.CreditCard.ExpMonth = 10
|
555
|
+
credit_card_transaction.CreditCard.ExpYear = 2018
|
556
|
+
credit_card_transaction.CreditCard.SecurityCode = '123'
|
557
|
+
credit_card_transaction.CreditCard.HolderName = 'Luke Skywalker'
|
558
|
+
credit_card_transaction.AmountInCents = 100
|
559
|
+
|
560
|
+
sale_request = CreateSaleRequest.new
|
561
|
+
sale_request.Buyer.Name = 'Anakin Skywalker'
|
562
|
+
sale_request.Buyer.Birthdate = Date.new(1994, 9, 26).strftime("%Y-%m-%dT%H:%M:%S")
|
563
|
+
sale_request.Buyer.DocumentNumber = '12345678901'
|
564
|
+
sale_request.Buyer.DocumentType = 'CPF'
|
565
|
+
sale_request.Buyer.PersonType = 'Person'
|
566
|
+
sale_request.Buyer.Gender = 'M'
|
567
|
+
sale_request.CreditCardTransactionCollection << credit_card_transaction
|
568
|
+
|
569
|
+
sale_response = gateway.CreateSale(sale_request)
|
570
|
+
|
571
|
+
expect(sale_response['ErrorReport']).to eq nil
|
572
|
+
|
573
|
+
response = gateway.BuyerKey(sale_response['BuyerKey'])
|
574
|
+
|
531
575
|
expect(response['ErrorReport']).to eq nil
|
532
576
|
end
|
533
577
|
|
534
578
|
it 'should do a credit card transaction with instant buy key' do
|
579
|
+
credit_card_transaction = CreditCardTransaction.new
|
580
|
+
credit_card_transaction.CreditCard.CreditCardNumber = '4111111111111111'
|
581
|
+
credit_card_transaction.CreditCard.CreditCardBrand = 'Visa'
|
582
|
+
credit_card_transaction.CreditCard.ExpMonth = 10
|
583
|
+
credit_card_transaction.CreditCard.ExpYear = 2018
|
584
|
+
credit_card_transaction.CreditCard.SecurityCode = '123'
|
585
|
+
credit_card_transaction.CreditCard.HolderName = 'Luke Skywalker'
|
586
|
+
credit_card_transaction.AmountInCents = 100
|
587
|
+
|
588
|
+
sale_request = CreateSaleRequest.new
|
589
|
+
sale_request.CreditCardTransactionCollection << credit_card_transaction
|
590
|
+
|
591
|
+
sale_response = gateway.CreateSale(sale_request)
|
592
|
+
|
593
|
+
expect(sale_response['ErrorReport']).to eq nil
|
594
|
+
|
595
|
+
instant_buy_key = sale_response['CreditCardTransactionResultCollection'][0]['CreditCard']['InstantBuyKey']
|
596
|
+
|
535
597
|
# coleta dados do cartao
|
536
598
|
creditCardTransaction = CreditCardTransaction.new
|
537
599
|
creditCardTransaction.AmountInCents = 100
|
538
|
-
creditCardTransaction.CreditCard.InstantBuyKey =
|
600
|
+
creditCardTransaction.CreditCard.InstantBuyKey = instant_buy_key
|
539
601
|
|
540
602
|
# cria a transacao
|
541
603
|
createSaleRequest = CreateSaleRequest.new
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mundipagg_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MundiPagg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|