stone_ecommerce 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/gateway/Gateway.rb +55 -157
- data/spec/integration/gateway_spec.rb +1 -1
- data/stone_ecommerce.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YWFiNTRjYThjMDg0OWY1Y2U4MTVlZmQ4NzFiMjgyZmUyZmZmYjY0Mw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTAwN2I5MjBlNTBhOThmNzZiNzlmMTNjZmZiZDZmODNhYjAzZDIzYw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
N2IwYTA0Y2YwNWIzYzBiZjQ3M2UzYmJmNTVmYTg0NGUxM2Q5MjVjNGRjNThh
|
10
|
+
ZTRhOWRhYWMwMzM5NzJlNWVjNTMwZTkzZjdiMzcyYjFiZjUwYThjMDNjNzQ5
|
11
|
+
ODVlMWVkNjFiOTk4NDcyMDJmOTQ4NzhhNzIzOGI3MDVjNmQyYzI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OWRiMGFkMmE5OGVkMTJmOGQ3ODU4MWNhZmU0NWY2Y2U5NjNkNjJkMGNmOTRi
|
14
|
+
NTkzZTMzNmRkZDY2OTA0ZTliMjFiNzgzNjgwOGY5MTFkZTJhZTU1ZDA2NDk5
|
15
|
+
YWZjZWRmZGUzZWQ1ZjRiMjhmNjA3ZDQ3MmI1MjFlZTcxMmZhYTU=
|
data/lib/gateway/Gateway.rb
CHANGED
@@ -4,15 +4,9 @@ module Gateway
|
|
4
4
|
class Gateway
|
5
5
|
extend Gem::Deprecate
|
6
6
|
|
7
|
-
attr_reader :
|
7
|
+
attr_reader :service_environment
|
8
8
|
|
9
|
-
attr_reader :
|
10
|
-
|
11
|
-
def initialize(environment=:sandbox, merchantKey)
|
12
|
-
@serviceEnvironment = environment
|
13
|
-
@merchantKey = merchantKey
|
14
|
-
@@SERVICE_HEADERS = {:MerchantKey => "#{@merchantKey}", :Accept => 'application/json', :"Content-Type" => 'application/json'}
|
15
|
-
end
|
9
|
+
attr_reader :merchant_key
|
16
10
|
|
17
11
|
# URL de producao
|
18
12
|
@@SERVICE_URL_PRODUCTION = 'https://transaction.stone.com.br'
|
@@ -24,27 +18,50 @@ module Gateway
|
|
24
18
|
@@SERVICE_URL_SANDBOX = 'https://transaction.stone.com.br'
|
25
19
|
|
26
20
|
# URL do postnotification de producao
|
27
|
-
@@
|
21
|
+
@@SERVICE_URL_REPORT_FILE_PRODUCTION = ''
|
28
22
|
|
29
23
|
# URL do postnotification de sandbox
|
30
|
-
@@
|
24
|
+
@@SERVICE_URL_REPORT_FILE_SANDBOX = ''
|
25
|
+
|
26
|
+
# Service Url
|
27
|
+
@@SERVICE_URL = ''
|
28
|
+
|
29
|
+
# Service Url Notification
|
30
|
+
@@SERVICE_URL_REPORT_FILE = ''
|
31
|
+
|
32
|
+
def initialize(environment=:sandbox, merchant_key)
|
33
|
+
@service_environment = environment
|
34
|
+
|
35
|
+
if @service_environment == :staging
|
36
|
+
@@SERVICE_URL = @@SERVICE_URL_STAGING
|
37
|
+
@@SERVICE_URL_REPORT_FILE = @@SERVICE_URL_REPORT_FILE_PRODUCTION
|
38
|
+
|
39
|
+
# se for producao, faz a chamada por aqui
|
40
|
+
elsif @service_environment == :production
|
41
|
+
@@SERVICE_URL = @@SERVICE_URL_PRODUCTION
|
42
|
+
@@SERVICE_URL_REPORT_FILE = @@SERVICE_URL_REPORT_FILE_PRODUCTION
|
43
|
+
|
44
|
+
# se for sandbox
|
45
|
+
elsif @service_environment == :sandbox
|
46
|
+
@@SERVICE_URL = @@SERVICE_URL_SANDBOX
|
47
|
+
@@SERVICE_URL_REPORT_FILE = @@SERVICE_URL_REPORT_FILE_SANDBOX
|
48
|
+
end
|
49
|
+
|
50
|
+
@merchant_key = merchant_key
|
51
|
+
@@SERVICE_HEADERS = {:MerchantKey => "#{@merchant_key}", :Accept => 'application/json', :"Content-Type" => 'application/json'}
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.new_with_urls (environment_url=@@SERVICE_URL_SANDBOX, report_file_url=@@SERVICE_URL_REPORT_FILE_SANDBOX, merchant_key)
|
55
|
+
@@SERVICE_URL = environment_url
|
56
|
+
@@SERVICE_URL_REPORT_FILE = report_file_url
|
57
|
+
self.new(nil, merchant_key)
|
58
|
+
end
|
31
59
|
|
32
60
|
# permite que o integrador adicione uma busca por transacoes utilizando alguns criterios
|
33
61
|
def Query(querySaleRequestEnum, key)
|
34
62
|
# try, tenta fazer o request
|
35
63
|
begin
|
36
|
-
|
37
|
-
if @serviceEnvironment == :staging
|
38
|
-
getRequest(@@SERVICE_URL_STAGING + '/Sale/Query/' + querySaleRequestEnum + '=' + key)
|
39
|
-
|
40
|
-
# se for producao, faz a chamada por aqui
|
41
|
-
elsif @serviceEnvironment == :production
|
42
|
-
getRequest(@@SERVICE_URL_PRODUCTION + '/Sale/Query/' + querySaleRequestEnum + '=' + key)
|
43
|
-
|
44
|
-
# se for sandbox
|
45
|
-
elsif @serviceEnvironment == :sandbox
|
46
|
-
getRequest(@@SERVICE_URL_SANDBOX + '/Sale/Query/' + querySaleRequestEnum + '=' + key)
|
47
|
-
end
|
64
|
+
getRequest(@@SERVICE_URL + '/Sale/Query/' + querySaleRequestEnum + '=' + key)
|
48
65
|
|
49
66
|
# se der algum erro, trata aqui
|
50
67
|
rescue Exception => e
|
@@ -212,14 +229,7 @@ module Gateway
|
|
212
229
|
return e.message
|
213
230
|
end
|
214
231
|
|
215
|
-
|
216
|
-
url = @@SERVICE_URL_STAGING + '/Sale/'
|
217
|
-
elsif @serviceEnvironment == :production
|
218
|
-
url = @@SERVICE_URL_PRODUCTION + '/Sale/'
|
219
|
-
elsif @serviceEnvironment == :sandbox
|
220
|
-
url = @@SERVICE_URL_SANDBOX + '/Sale/'
|
221
|
-
end
|
222
|
-
postRequest(saleHash.to_json, url)
|
232
|
+
postRequest(saleHash.to_json, @@SERVICE_URL + '/Sale/')
|
223
233
|
end
|
224
234
|
|
225
235
|
# permite forcar a retentativa manualmente de uma transacao (podendo ser tambem uma recorrencia) nao autorizada
|
@@ -243,14 +253,8 @@ module Gateway
|
|
243
253
|
rescue Exception => e
|
244
254
|
return e.message
|
245
255
|
end
|
246
|
-
|
247
|
-
|
248
|
-
elsif @serviceEnvironment == :production
|
249
|
-
url = @@SERVICE_URL_PRODUCTION + '/Sale/Retry'
|
250
|
-
elsif @serviceEnvironment == :sandbox
|
251
|
-
url = @@SERVICE_URL_SANDBOX + '/Sale/Retry'
|
252
|
-
end
|
253
|
-
postRequest(saleHash.to_json, url)
|
256
|
+
|
257
|
+
postRequest(saleHash.to_json, @@SERVICE_URL + '/Sale/Retry')
|
254
258
|
end
|
255
259
|
|
256
260
|
# eh uma forma de desfazer uma transação com cartao de credito mesmo a transacao sendo capturada
|
@@ -268,14 +272,8 @@ module Gateway
|
|
268
272
|
rescue Exception => e
|
269
273
|
return e.message
|
270
274
|
end
|
271
|
-
|
272
|
-
|
273
|
-
elsif @serviceEnvironment == :production
|
274
|
-
url = @@SERVICE_URL_PRODUCTION + '/Sale/Cancel'
|
275
|
-
elsif @serviceEnvironment == :sandbox
|
276
|
-
url = @@SERVICE_URL_SANDBOX + '/Sale/Cancel'
|
277
|
-
end
|
278
|
-
postRequest(saleHash.to_json, url)
|
275
|
+
|
276
|
+
postRequest(saleHash.to_json, @@SERVICE_URL + '/Sale/Cancel')
|
279
277
|
end
|
280
278
|
|
281
279
|
# confirmacao de uma transacao de cartao de credito que ja fora autorizada
|
@@ -293,14 +291,8 @@ module Gateway
|
|
293
291
|
rescue Exception => e
|
294
292
|
return e.message
|
295
293
|
end
|
296
|
-
|
297
|
-
|
298
|
-
elsif @serviceEnvironment == :production
|
299
|
-
url = @@SERVICE_URL_PRODUCTION + '/Sale/Capture'
|
300
|
-
elsif @serviceEnvironment == :sandbox
|
301
|
-
url = @@SERVICE_URL_SANDBOX + '/Sale/Capture'
|
302
|
-
end
|
303
|
-
postRequest(saleHash.to_json, url)
|
294
|
+
|
295
|
+
postRequest(saleHash.to_json, @@SERVICE_URL + '/Sale/Capture')
|
304
296
|
end
|
305
297
|
|
306
298
|
# faz um parse do xml de post notificaton
|
@@ -317,16 +309,7 @@ module Gateway
|
|
317
309
|
# faz uma requisicao e retorna uma string com o transaction report file
|
318
310
|
def TransactionReportFile(date)
|
319
311
|
begin
|
320
|
-
|
321
|
-
url = @@SERVICE_URL_NOTIFICATION_PRODUCTION + date.strftime("%Y%m%d")
|
322
|
-
elsif @serviceEnvironment == :production
|
323
|
-
url = @@SERVICE_URL_NOTIFICATION_PRODUCTION + date.strftime("%Y%m%d")
|
324
|
-
elsif @serviceEnvironment == :sandbox
|
325
|
-
url = @@SERVICE_URL_NOTIFICATION_SANDBOX + date.strftime("%Y%m%d")
|
326
|
-
end
|
327
|
-
|
328
|
-
response = getReportFile(url)
|
329
|
-
|
312
|
+
response = getReportFile(@@SERVICE_URL_REPORT_FILE + '/TransactionReportFile/GetStream?fileDate=' + date.strftime("%Y%m%d"))
|
330
313
|
rescue RestClient::ExceptionWithResponse => err
|
331
314
|
return err.response
|
332
315
|
end
|
@@ -373,19 +356,7 @@ module Gateway
|
|
373
356
|
def GetCreditCardWithBuyerKey(buyer_key)
|
374
357
|
# try, tenta fazer o request
|
375
358
|
begin
|
376
|
-
|
377
|
-
# se for homologacao faz a chamada por aqui
|
378
|
-
if @serviceEnvironment == :staging
|
379
|
-
response = getRequest(@@SERVICE_URL_STAGING + '/CreditCard/BuyerKey=' + buyer_key)
|
380
|
-
|
381
|
-
# se for producao, faz a chamada por aqui
|
382
|
-
elsif @serviceEnvironment == :production
|
383
|
-
response = getRequest(@@SERVICE_URL_PRODUCTION + '/CreditCard/BuyerKey=' + buyer_key)
|
384
|
-
|
385
|
-
# se for sandbox, faz a chamada por aqui
|
386
|
-
elsif @serviceEnvironment == :sandbox
|
387
|
-
response = getRequest(@@SERVICE_URL_SANDBOX + '/CreditCard/BuyerKey=' + buyer_key)
|
388
|
-
end
|
359
|
+
response = getRequest(@@SERVICE_URL + '/CreditCard/BuyerKey=' + buyer_key)
|
389
360
|
|
390
361
|
# se der algum erro, trata aqui
|
391
362
|
rescue Exception => e
|
@@ -400,18 +371,7 @@ module Gateway
|
|
400
371
|
def GetCreditCard(instant_buy_key)
|
401
372
|
# try, tenta fazer o request
|
402
373
|
begin
|
403
|
-
|
404
|
-
if @serviceEnvironment == :staging
|
405
|
-
getRequest(@@SERVICE_URL_STAGING + '/CreditCard/' + instant_buy_key)
|
406
|
-
|
407
|
-
# se for producao, faz a chamada por aqui
|
408
|
-
elsif @serviceEnvironment == :production
|
409
|
-
getRequest(@@SERVICE_URL_PRODUCTION + '/CreditCard/' + instant_buy_key)
|
410
|
-
|
411
|
-
# se for sandbox
|
412
|
-
elsif @serviceEnvironment == :sandbox
|
413
|
-
getRequest(@@SERVICE_URL_SANDBOX + '/CreditCard/' + instant_buy_key)
|
414
|
-
end
|
374
|
+
getRequest(@@SERVICE_URL + '/CreditCard/' + instant_buy_key)
|
415
375
|
|
416
376
|
# se der algum erro, trata aqui
|
417
377
|
rescue Exception => e
|
@@ -429,20 +389,7 @@ module Gateway
|
|
429
389
|
sale_hash['BillingAddress'] = nil
|
430
390
|
end
|
431
391
|
|
432
|
-
|
433
|
-
if @serviceEnvironment == :staging
|
434
|
-
url = @@SERVICE_URL_STAGING + '/CreditCard/'
|
435
|
-
|
436
|
-
# se for producao, faz a chamada por aqui
|
437
|
-
elsif @serviceEnvironment == :production
|
438
|
-
url = @@SERVICE_URL_PRODUCTION + '/CreditCard/'
|
439
|
-
|
440
|
-
# se for sandbox, faz a chamada por aqui
|
441
|
-
elsif @serviceEnvironment == :sandbox
|
442
|
-
url = @@SERVICE_URL_SANDBOX + '/CreditCard/'
|
443
|
-
end
|
444
|
-
|
445
|
-
response = postRequest(sale_hash.to_json, url)
|
392
|
+
response = postRequest(sale_hash.to_json, @@SERVICE_URL + '/CreditCard/')
|
446
393
|
|
447
394
|
# se der algum erro, trata aqui
|
448
395
|
rescue Exception => e
|
@@ -457,20 +404,7 @@ module Gateway
|
|
457
404
|
begin
|
458
405
|
sale_hash = update_instant_buy_data_request.to_json
|
459
406
|
|
460
|
-
|
461
|
-
if @serviceEnvironment == :staging
|
462
|
-
url = @@SERVICE_URL_STAGING + '/CreditCard/' + instant_buy_key
|
463
|
-
|
464
|
-
# se for producao, faz a chamada por aqui
|
465
|
-
elsif @serviceEnvironment == :production
|
466
|
-
url = @@SERVICE_URL_PRODUCTION + '/CreditCard/' + instant_buy_key
|
467
|
-
|
468
|
-
# se for sandbox, faz a chamada por aqui
|
469
|
-
elsif @serviceEnvironment == :sandbox
|
470
|
-
url = @@SERVICE_URL_SANDBOX + '/CreditCard/' + instant_buy_key
|
471
|
-
end
|
472
|
-
|
473
|
-
response = patchRequest(sale_hash.to_json, url)
|
407
|
+
response = patchRequest(sale_hash.to_json, @@SERVICE_URL + '/CreditCard/' + instant_buy_key)
|
474
408
|
# se der algum erro, trata aqui
|
475
409
|
rescue Exception => e
|
476
410
|
return e.message
|
@@ -483,18 +417,7 @@ module Gateway
|
|
483
417
|
def DeleteCreditCard(instant_buy_key)
|
484
418
|
# try, tenta fazer o request
|
485
419
|
begin
|
486
|
-
|
487
|
-
if @serviceEnvironment == :staging
|
488
|
-
deleteRequest(@@SERVICE_URL_STAGING + '/CreditCard/' + instant_buy_key)
|
489
|
-
|
490
|
-
# se for producao, faz a chamada por aqui
|
491
|
-
elsif @serviceEnvironment == :production
|
492
|
-
deleteRequest(@@SERVICE_URL_PRODUCTION + '/CreditCard/' + instant_buy_key)
|
493
|
-
|
494
|
-
# se for sandbox
|
495
|
-
elsif @serviceEnvironment == :sandbox
|
496
|
-
deleteRequest(@@SERVICE_URL_SANDBOX + '/CreditCard/' + instant_buy_key)
|
497
|
-
end
|
420
|
+
deleteRequest(@@SERVICE_URL + '/CreditCard/' + instant_buy_key)
|
498
421
|
|
499
422
|
# se der algum erro, trata aqui
|
500
423
|
rescue Exception => e
|
@@ -506,19 +429,7 @@ module Gateway
|
|
506
429
|
def GetBuyer(buyer_key)
|
507
430
|
# try, tenta fazer o request
|
508
431
|
begin
|
509
|
-
|
510
|
-
# se for homologacao faz a chamada por aqui
|
511
|
-
if @serviceEnvironment == :staging
|
512
|
-
response = getRequest(@@SERVICE_URL_STAGING + '/Buyer/' + buyer_key)
|
513
|
-
|
514
|
-
# se for producao, faz a chamada por aqui
|
515
|
-
elsif @serviceEnvironment == :production
|
516
|
-
response = getRequest(@@SERVICE_URL_PRODUCTION + '/Buyer/' + buyer_key)
|
517
|
-
|
518
|
-
# se for sandbox, faz a chamada por aqui
|
519
|
-
elsif @serviceEnvironment == :sandbox
|
520
|
-
response = getRequest(@@SERVICE_URL_SANDBOX + '/Buyer/' + buyer_key)
|
521
|
-
end
|
432
|
+
response = getRequest(@@SERVICE_URL + '/Buyer/' + buyer_key)
|
522
433
|
|
523
434
|
# se der algum erro, trata aqui
|
524
435
|
rescue Exception => e
|
@@ -543,20 +454,7 @@ module Gateway
|
|
543
454
|
end
|
544
455
|
end
|
545
456
|
|
546
|
-
|
547
|
-
if @serviceEnvironment == :staging
|
548
|
-
url = @@SERVICE_URL_STAGING + '/Buyer/'
|
549
|
-
|
550
|
-
# se for producao, faz a chamada por aqui
|
551
|
-
elsif @serviceEnvironment == :production
|
552
|
-
url = @@SERVICE_URL_PRODUCTION + '/Buyer/'
|
553
|
-
|
554
|
-
# se for sandbox, faz a chamada por aqui
|
555
|
-
elsif @serviceEnvironment == :sandbox
|
556
|
-
url = @@SERVICE_URL_SANDBOX + '/Buyer/'
|
557
|
-
end
|
558
|
-
|
559
|
-
response = postRequest(sale_hash.to_json, url)
|
457
|
+
response = postRequest(sale_hash.to_json, @@SERVICE_URL + '/Buyer/')
|
560
458
|
rescue Exception => e
|
561
459
|
return e.message
|
562
460
|
end
|
@@ -617,7 +515,7 @@ module Gateway
|
|
617
515
|
|
618
516
|
def getReportFile(url)
|
619
517
|
begin
|
620
|
-
response = RestClient.get(url, headers={:MerchantKey => "#{@
|
518
|
+
response = RestClient.get(url, headers={:MerchantKey => "#{@merchant_key}"})
|
621
519
|
rescue RestClient::ExceptionWithResponse => err
|
622
520
|
return err.response
|
623
521
|
end
|
@@ -705,7 +705,7 @@ RSpec.describe Gateway do
|
|
705
705
|
credit_card_transaction.CreditCard.ExpMonth = 10
|
706
706
|
credit_card_transaction.CreditCard.ExpYear = 2018
|
707
707
|
credit_card_transaction.CreditCard.SecurityCode = '123'
|
708
|
-
credit_card_transaction.CreditCard.HolderName = 'Luke Skywalker'
|
708
|
+
credit_card_transaction.CreditCard.HolderName = 'Luke Skywalker' + DateTime.now().to_s
|
709
709
|
credit_card_transaction.AmountInCents = 100
|
710
710
|
credit_card_transaction.Options.PaymentMethodCode = 1
|
711
711
|
|
data/stone_ecommerce.gemspec
CHANGED
@@ -2,7 +2,7 @@ Gem::Specification.new do |s|
|
|
2
2
|
s.name = 'stone_ecommerce'
|
3
3
|
s.summary = 'Stone Ruby Client Library'
|
4
4
|
s.description = 'Ruby library for integrating with the Stone payment web services.'
|
5
|
-
s.version = '1.
|
5
|
+
s.version = '1.4.0' # Major.Minor.Revision
|
6
6
|
s.author = 'Stone Pagamentos'
|
7
7
|
s.email = 'meajuda@stone.com.br'
|
8
8
|
s.homepage = 'http://stone.com.br/'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stone_ecommerce
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stone Pagamentos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|