mundipagg_sdk 1.0.2 → 1.0.3

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.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +61 -61
  3. data/lib/gateway/Address/billing_address.rb +32 -32
  4. data/lib/gateway/Address/buyer_address.rb +36 -36
  5. data/lib/gateway/Address/delivery_address.rb +32 -32
  6. data/lib/gateway/AntiFraud/anti_fraud_analysis_result.rb +47 -47
  7. data/lib/gateway/AntiFraud/query_sale_anti_fraud_analysis_data.rb +51 -51
  8. data/lib/gateway/AntiFraud/query_sale_anti_fraud_analysis_history_data.rb +41 -41
  9. data/lib/gateway/BaseRequest.rb +10 -10
  10. data/lib/gateway/BaseResponse.rb +17 -17
  11. data/lib/gateway/BoletoTransaction/boleto_transaction.rb +43 -43
  12. data/lib/gateway/BoletoTransaction/boleto_transaction_data.rb +43 -43
  13. data/lib/gateway/BoletoTransaction/boleto_transaction_options.rb +14 -14
  14. data/lib/gateway/BoletoTransaction/boleto_transaction_report_file.rb +19 -19
  15. data/lib/gateway/BoletoTransaction/boleto_transaction_result.rb +34 -34
  16. data/lib/gateway/CreditCardTransaction/credit_card.rb +29 -29
  17. data/lib/gateway/CreditCardTransaction/credit_card_transaction.rb +31 -31
  18. data/lib/gateway/CreditCardTransaction/credit_card_transaction_data.rb +103 -103
  19. data/lib/gateway/CreditCardTransaction/credit_card_transaction_options.rb +26 -26
  20. data/lib/gateway/CreditCardTransaction/credit_card_transaction_report_file.rb +28 -28
  21. data/lib/gateway/CreditCardTransaction/manage_credit_card_transaction.rb +11 -11
  22. data/lib/gateway/CreditCardTransaction/retry_sale_credit_card_transaction.rb +12 -12
  23. data/lib/gateway/ErrorItem.rb +17 -17
  24. data/lib/gateway/ErrorReport.rb +18 -18
  25. data/lib/gateway/Gateway.rb +441 -444
  26. data/lib/gateway/InstantBuy/credit_card_data.rb +40 -40
  27. data/lib/gateway/InstantBuy/get_instant_buy_data_response.rb +17 -17
  28. data/lib/gateway/Merchant/merchant.rb +10 -10
  29. data/lib/gateway/OnlineDebit/online_debit_transaction_report_file.rb +17 -17
  30. data/lib/gateway/Order/order.rb +10 -10
  31. data/lib/gateway/Order/order_transaction_report_file.rb +5 -5
  32. data/lib/gateway/Parsers/boleto_transaction_parser.rb +30 -30
  33. data/lib/gateway/Parsers/credit_card_transaction_parser.rb +39 -39
  34. data/lib/gateway/Parsers/header_parser.rb +13 -13
  35. data/lib/gateway/Parsers/online_debit_transaction_parser.rb +29 -29
  36. data/lib/gateway/Parsers/trailer_parser.rb +14 -14
  37. data/lib/gateway/Person/buyer.rb +32 -32
  38. data/lib/gateway/Person/person.rb +46 -46
  39. data/lib/gateway/Recurrency/recurrency.rb +22 -22
  40. data/lib/gateway/Sale/create_sale_request.rb +35 -35
  41. data/lib/gateway/Sale/create_sale_response.rb +24 -24
  42. data/lib/gateway/Sale/manage_sale_request.rb +16 -16
  43. data/lib/gateway/Sale/manage_sale_response.rb +14 -14
  44. data/lib/gateway/Sale/query_sale_request.rb +35 -35
  45. data/lib/gateway/Sale/query_sale_response.rb +17 -17
  46. data/lib/gateway/Sale/request_data.rb +19 -19
  47. data/lib/gateway/Sale/retry_sale_options.rb +13 -13
  48. data/lib/gateway/Sale/retry_sale_request.rb +21 -21
  49. data/lib/gateway/Sale/retry_sale_response.rb +13 -13
  50. data/lib/gateway/Sale/sale_data.rb +32 -32
  51. data/lib/gateway/Sale/sale_order_data.rb +16 -16
  52. data/lib/gateway/SalesOption.rb +17 -17
  53. data/lib/gateway/ShoppingCart/shopping_cart.rb +25 -25
  54. data/lib/gateway/ShoppingCart/shopping_cart_item.rb +22 -22
  55. data/lib/gateway/Trailer.rb +5 -5
  56. data/lib/gateway/address.rb +24 -24
  57. data/lib/gateway/header.rb +4 -4
  58. data/lib/gateway/post_notification.rb +28 -28
  59. data/lib/gateway/transaction_report_file.rb +44 -44
  60. data/lib/mundipagg_sdk.rb +70 -70
  61. data/mundipagg_sdk.gemspec +18 -18
  62. data/spec/integration/gateway_spec.rb +733 -651
  63. data/spec/integration/test_helper.rb +68 -68
  64. metadata +2 -2
@@ -1,13 +1,13 @@
1
- class RetrySaleCreditCardTransaction
2
-
3
- attr_accessor :TransactionKey
4
-
5
- attr_accessor :SecurityCode
6
-
7
- def to_json
8
- hash = {}
9
- instance_variables.each {|var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
10
- hash
11
- end
12
-
1
+ class RetrySaleCreditCardTransaction
2
+
3
+ attr_accessor :TransactionKey
4
+
5
+ attr_accessor :SecurityCode
6
+
7
+ def to_json
8
+ hash = {}
9
+ instance_variables.each {|var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
10
+ hash
11
+ end
12
+
13
13
  end
@@ -1,17 +1,17 @@
1
- class ErrorItem
2
-
3
- attr_accessor :ErrorCode
4
-
5
- attr_accessor :ErrorField
6
-
7
- attr_accessor :Description
8
-
9
- attr_accessor :SeverityCode
10
-
11
- def to_json
12
- hash = {}
13
- instance_variables.each {|var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
14
- hash
15
- end
16
-
17
- end
1
+ class ErrorItem
2
+
3
+ attr_accessor :ErrorCode
4
+
5
+ attr_accessor :ErrorField
6
+
7
+ attr_accessor :Description
8
+
9
+ attr_accessor :SeverityCode
10
+
11
+ def to_json
12
+ hash = {}
13
+ instance_variables.each {|var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
14
+ hash
15
+ end
16
+
17
+ end
@@ -1,18 +1,18 @@
1
- class ErrorReport
2
-
3
- attr_accessor :Category
4
-
5
- attr_accessor :ErrorItemCollection
6
-
7
-
8
- def initialize
9
- @ErrorItemCollection = Array.new;
10
- end
11
-
12
- def to_json
13
- hash = {}
14
- instance_variables.each {|var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
15
- hash
16
- end
17
-
18
- end
1
+ class ErrorReport
2
+
3
+ attr_accessor :Category
4
+
5
+ attr_accessor :ErrorItemCollection
6
+
7
+
8
+ def initialize
9
+ @ErrorItemCollection = Array.new;
10
+ end
11
+
12
+ def to_json
13
+ hash = {}
14
+ instance_variables.each {|var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
15
+ hash
16
+ end
17
+
18
+ end
@@ -1,444 +1,441 @@
1
- require_relative '../../lib/mundipagg_sdk'
2
-
3
- class Gateway
4
-
5
- attr_reader :serviceEnvironment
6
-
7
- attr_reader :merchantKey
8
-
9
- def initialize(environment=:staging, merchantKey)
10
- @serviceEnvironment = environment
11
- @merchantKey = merchantKey
12
- @@SERVICE_HEADERS = {:MerchantKey => "#{@merchantKey}", :Accept => 'application/json', :"Content-Type" => 'application/json'}
13
- end
14
-
15
- # URL de producao
16
- @@SERVICE_URL_PRODUCTION = 'https://transactionv2.mundipaggone.com'
17
-
18
- # URL de homologacao
19
- @@SERVICE_URL_STAGING = 'https://stagingv2.mundipaggone.com'
20
-
21
- # URL de sandbox
22
- @@SERVICE_URL_SANDBOX = 'https://sandbox.mundipaggone.com'
23
-
24
- # URL do postnotification de producao
25
- @@SERVICE_URL_NOTIFICATION_PRODUCTION = 'https://api.mundipaggone.com/TransactionReportFile/GetStream?fileDate='
26
-
27
- # URL do postnotification de sandbox
28
- @@SERVICE_URL_NOTIFICATION_SANDBOX = 'https://apisandbox.mundipaggone.com/TransactionReportFile/GetStream?fileDate='
29
-
30
- # permite que o integrador adicione uma busca por transacoes utilizando alguns criterios
31
- def Query(querySaleRequestEnum, key)
32
- # try, tenta fazer o request
33
- begin
34
- # se for homologacao faz a chamada por aqui
35
- if @serviceEnvironment == :staging
36
- getRequest(@@SERVICE_URL_STAGING + '/Sale/Query/' + querySaleRequestEnum + '=' + key)
37
-
38
- # se for producao, faz a chamada por aqui
39
- elsif @serviceEnvironment == :production
40
- getRequest(@@SERVICE_URL_PRODUCTION + '/Sale/Query/' + querySaleRequestEnum + '=' + key)
41
-
42
- # se for sandbox
43
- elsif @serviceEnvironment == :sandbox
44
- getRequest(@@SERVICE_URL_SANDBOX + '/Sale/Query/' + querySaleRequestEnum + '=' + key)
45
- end
46
-
47
- # se der algum erro, trata aqui
48
- rescue Exception => e
49
- return e.message
50
- end
51
- end
52
-
53
- # criar uma transacao na plataforma One utilizando um ou mais meios de pagamento
54
- def CreateSale(createSaleRequest)
55
-
56
- saleHash = createSaleRequest.to_json
57
-
58
- saleHash['BoletoTransactionCollection'] = []
59
-
60
- saleHash['CreditCardTransactionCollection'] = []
61
-
62
- saleHash['ShoppingCartCollection'] = []
63
-
64
- begin
65
- # transforma a colecao de boleto em json
66
- if createSaleRequest.BoletoTransactionCollection.any? == false || createSaleRequest.BoletoTransactionCollection.nil?
67
- saleHash['BoletoTransactionCollection'] = nil
68
-
69
- else
70
- createSaleRequest.BoletoTransactionCollection.each_with_index do |boleto, index|
71
- b = boleto.to_json
72
- saleHash['BoletoTransactionCollection'] << b
73
-
74
- if boleto.Options.to_json.any?
75
- boleto_options = boleto.Options.to_json
76
- saleHash['BoletoTransactionCollection'][index]['Options'] = boleto_options
77
- else
78
- saleHash['BoletoTransactionCollection'][index]['Options'] = nil
79
- end
80
-
81
- if boleto.BillingAddress.to_json.any?
82
- boleto_billing_address = boleto.BillingAddress.to_json
83
- saleHash['BoletoTransactionCollection'][index]['BillingAddress'] = boleto_billing_address
84
- else
85
- saleHash['BoletoTransactionCollection'][index]['BillingAddress'] = nil
86
- end
87
- end
88
- end
89
-
90
- # transforma a colecao de cartao de credito em json
91
- if createSaleRequest.CreditCardTransactionCollection.any? == false || createSaleRequest.CreditCardTransactionCollection.nil?
92
- saleHash['CreditCardTransactionCollection'] = nil
93
- else
94
- createSaleRequest.CreditCardTransactionCollection.each_with_index do |creditCard, index|
95
- c = creditCard.to_json
96
- saleHash['CreditCardTransactionCollection'] << c
97
-
98
- if creditCard.Options.to_json.any?
99
- credit_card_options = creditCard.Options.to_json
100
- saleHash['CreditCardTransactionCollection'][index]['Options'] = credit_card_options
101
- else
102
- saleHash['CreditCardTransactionCollection'][index]['Options'] = nil
103
- end
104
-
105
- if creditCard.Recurrency.to_json.any?
106
- credit_card_recurrency = creditCard.Recurrency.to_json
107
- saleHash['CreditCardTransactionCollection'][index]['Recurrency'] = credit_card_recurrency
108
- else
109
- saleHash['CreditCardTransactionCollection'][index]['Recurrency'] = nil
110
- end
111
-
112
- if creditCard.CreditCard.to_json.any?
113
- credit_card_item = creditCard.CreditCard.to_json
114
- saleHash['CreditCardTransactionCollection'][index]['CreditCard'] = credit_card_item
115
-
116
- if creditCard.CreditCard.BillingAddress.to_json.any?
117
- credit_card_billing_address = creditCard.CreditCard.BillingAddress.to_json
118
- saleHash['CreditCardTransactionCollection'][index]['CreditCard']['BillingAddress'] = credit_card_billing_address
119
- else
120
- saleHash['CreditCardTransactionCollection'][index]['CreditCard']['BillingAddress'] = nil
121
- end
122
-
123
- else
124
- saleHash['CreditCardTransactionCollection'][index]['CreditCard'] = nil
125
- end
126
- end
127
- end
128
-
129
- # transforma a colecao de shoppingcart em json
130
- if createSaleRequest.ShoppingCartCollection.any? == false || createSaleRequest.ShoppingCartCollection.nil?
131
- saleHash['ShoppingCartCollection'] = nil
132
- else
133
- createSaleRequest.ShoppingCartCollection.each_with_index do |shoppingCart, index|
134
- s = shoppingCart.to_json
135
- saleHash['ShoppingCartCollection'] << s
136
-
137
- if shoppingCart.DeliveryAddress.to_json.any?
138
- delivery_address = shoppingCart.DeliveryAddress.to_json
139
- saleHash['ShoppingCartCollection'][index]['DeliveryAddress'] = delivery_address
140
- else
141
- saleHash['ShoppingCartCollection'][index]['DeliveryAddress'] = nil
142
- end
143
-
144
- if shoppingCart.ShoppingCartItemCollection.any?
145
- shoppingCart.ShoppingCartItemCollection.each do |cartItem|
146
- item = cartItem.to_json
147
- saleHash['ShoppingCartCollection'][index]['ShoppingCartItemCollection'] << item
148
- end
149
- else
150
- saleHash['ShoppingCartCollection'][index]['ShoppingCartItemCollection'] = nil
151
- end
152
- end
153
- end
154
-
155
- # transforma objeto options em json
156
- if createSaleRequest.Options.to_json.any?
157
- o = createSaleRequest.Options.to_json
158
- saleHash['Options'] = o
159
- else
160
- saleHash['Options'] = nil
161
- end
162
-
163
- # transforma objeto order em json
164
- if createSaleRequest.Order.to_json.any?
165
- order = createSaleRequest.Order.to_json
166
- saleHash['Order'] = order
167
- else
168
- saleHash['Order'] = nil
169
- end
170
-
171
- # transforma objeto merchant em json
172
- if createSaleRequest.Merchant.to_json.any?
173
- merchant = createSaleRequest.Merchant.to_json
174
- saleHash['Merchant'] = merchant
175
- else
176
- saleHash['Merchant'] = nil
177
- end
178
-
179
- # transforma objeto request data em json
180
- if createSaleRequest.RequestData.to_json.any?
181
- request_data = createSaleRequest.RequestData.to_json
182
- saleHash['RequestData'] = request_data
183
- else
184
- saleHash['RequestData'] = nil
185
- end
186
-
187
- # transforma o objeto Buyer em json
188
- if createSaleRequest.Buyer.AddressCollection.any?
189
- b = createSaleRequest.Buyer.to_json
190
- saleHash['Buyer'] = b
191
-
192
- saleHash['Buyer']['AddressCollection'] = []
193
- createSaleRequest.Buyer.AddressCollection.each do |address|
194
- a = address.to_json
195
- saleHash['Buyer']['AddressCollection'] << a
196
- end
197
- else
198
- buyer_hash = createSaleRequest.Buyer.to_json
199
- buyer_hash.delete('AddressCollection')
200
- if buyer_hash.blank? == false
201
- b = createSaleRequest.Buyer.to_json
202
- saleHash['Buyer'] = b
203
- saleHash['Buyer']['AddressCollection'] = nil
204
- else
205
- saleHash['Buyer'] = nil
206
- end
207
- end
208
-
209
- rescue Exception => e
210
- return e.message
211
- end
212
-
213
- if @serviceEnvironment == :staging
214
- url = @@SERVICE_URL_STAGING + '/Sale/'
215
- elsif @serviceEnvironment == :production
216
- url = @@SERVICE_URL_PRODUCTION + '/Sale/'
217
- elsif @serviceEnvironment == :sandbox
218
- url = @@SERVICE_URL_SANDBOX + '/Sale/'
219
- end
220
- postRequest(saleHash.to_json, url)
221
- end
222
-
223
- # permite forcar a retentativa manualmente de uma transacao (podendo ser tambem uma recorrencia) nao autorizada
224
- def Retry(retrySaleRequest)
225
- saleHash = retrySaleRequest.to_json
226
- saleHash['RetrySaleCreditCardTransactionCollection'] = []
227
-
228
- begin
229
- if retrySaleRequest.RetrySaleCreditCardTransactionCollection != nil
230
- retrySaleRequest.RetrySaleCreditCardTransactionCollection.each do |retrySale|
231
- r = retrySale.to_json
232
- saleHash['RetrySaleCreditCardTransactionCollection'] << r
233
- end
234
- end
235
- if retrySaleRequest.Options.to_json.any?
236
- retry_options = retrySaleRequest.Options.to_json
237
- saleHash['Options'] = retry_options
238
- else
239
- saleHash['Options'] = nil
240
- end
241
- rescue Exception => e
242
- return e.message
243
- end
244
- if @serviceEnvironment == :staging
245
- url = @@SERVICE_URL_STAGING + '/Sale/Retry'
246
- elsif @serviceEnvironment == :production
247
- url = @@SERVICE_URL_PRODUCTION + '/Sale/Retry'
248
- elsif @serviceEnvironment == :sandbox
249
- url = @@SERVICE_URL_SANDBOX + '/Sale/Retry'
250
- end
251
- postRequest(saleHash.to_json, url)
252
- end
253
-
254
- # eh uma forma de desfazer uma transação com cartao de credito mesmo a transacao sendo capturada
255
- def Cancel(cancelSaleRequest)
256
- saleHash = cancelSaleRequest.to_json
257
- saleHash['CreditCardTransactionCollection'] = []
258
-
259
- begin
260
- if cancelSaleRequest.CreditCardTransactionCollection != nil
261
- cancelSaleRequest.CreditCardTransactionCollection.each do |creditCard|
262
- c = creditCard.to_json
263
- saleHash['CreditCardTransactionCollection'] << c
264
- end
265
- end
266
- rescue Exception => e
267
- return e.message
268
- end
269
- if @serviceEnvironment == :staging
270
- url = @@SERVICE_URL_STAGING + '/Sale/Cancel'
271
- elsif @serviceEnvironment == :production
272
- url = @@SERVICE_URL_PRODUCTION + '/Sale/Cancel'
273
- elsif @serviceEnvironment == :sandbox
274
- url = @@SERVICE_URL_SANDBOX + '/Sale/Cancel'
275
- end
276
- postRequest(saleHash.to_json, url)
277
- end
278
-
279
- # confirmacao de uma transacao de cartao de credito que ja fora autorizada
280
- def Capture(captureRequest)
281
- saleHash = captureRequest.to_json
282
- saleHash['CreditCardTransactionCollection'] = []
283
-
284
- begin
285
- if captureRequest.CreditCardTransactionCollection != nil
286
- captureRequest.CreditCardTransactionCollection.each do |creditCard|
287
- c = creditCard.to_json
288
- saleHash['CreditCardTransactionCollection'] << c
289
- end
290
- end
291
- rescue Exception => e
292
- return e.message
293
- end
294
- if @serviceEnvironment == :staging
295
- url = @@SERVICE_URL_STAGING + '/Sale/Capture'
296
- elsif @serviceEnvironment == :production
297
- url = @@SERVICE_URL_PRODUCTION + '/Sale/Capture'
298
- elsif @serviceEnvironment == :sandbox
299
- url = @@SERVICE_URL_SANDBOX + '/Sale/Capture'
300
- end
301
- postRequest(saleHash.to_json, url)
302
- end
303
-
304
- # faz um parse do xml de post notificaton
305
- def ParseXmlToNotification(xml)
306
- begin
307
- response = PostNotification.ParseNotification(xml)
308
- rescue Exception => err
309
- return err.message
310
- end
311
-
312
- return response
313
- end
314
-
315
- # faz uma requisicao e retorna uma string com o transaction report file
316
- def TransactionReportFile(date)
317
- begin
318
- #response = RestClient.get('https://api.mundipaggone.com/TransactionReportFile/GetStream?fileDate=' + date.strftime("%Y%m%d"), headers={:MerchantKey => "#{@merchantKey}"})
319
-
320
- if @serviceEnvironment == :staging
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
-
330
- rescue RestClient::ExceptionWithResponse => err
331
- return err.response
332
- end
333
- return response
334
- end
335
-
336
- # faz o download do transaction report file e salva no computador em .txt
337
- def TransactionReportFileDownloader(date, file_name, path)
338
- begin
339
- path = path + file_name + '.txt'
340
- #response = RestClient.get('https://api.mundipaggone.com/TransactionReportFile/GetStream?fileDate=' + date.strftime("%Y%m%d"), headers={:MerchantKey => "#{@merchantKey}"})
341
-
342
- response = TransactionReportFile(date)
343
-
344
- File.write(path, response)
345
- rescue RestClient::ExceptionWithResponse => err
346
- return err.response
347
- end
348
- end
349
-
350
- # faz o parse da string recebida do transaction report file e retorna um hash
351
- def TransactionReportFileParser(file_to_parse)
352
- transaction_report_file = TransactionReportFile.new
353
- begin
354
- response = transaction_report_file.TransactionReportFileParser(file_to_parse)
355
- rescue Exception => err
356
- return err
357
- end
358
- return response
359
- end
360
-
361
- # faz uma requisicao com instant buy key
362
- def InstantBuyKey(instant_buy_key)
363
- # try, tenta fazer o request
364
- begin
365
-
366
- # se for homologacao faz a chamada por aqui
367
- if @serviceEnvironment == :staging
368
- getRequest(@@SERVICE_URL_STAGING + '/CreditCard/' + instant_buy_key)
369
-
370
- # se for producao, faz a chamada por aqui
371
- elsif @serviceEnvironment == :production
372
- getRequest(@@SERVICE_URL_PRODUCTION + '/CreditCard/' + instant_buy_key)
373
-
374
- # se for sandbox
375
- elsif @serviceEnvironment == :sandbox
376
- getRequest(@@SERVICE_URL_SANDBOX + '/CreditCard/' + instant_buy_key)
377
- end
378
-
379
- # se der algum erro, trata aqui
380
- rescue Exception => e
381
- return e.message
382
- end
383
- end
384
-
385
- # faz uma requisicao com buyer key
386
- def BuyerKey(buyer_key)
387
- # try, tenta fazer o request
388
- begin
389
-
390
- # se for homologacao faz a chamada por aqui
391
- if @serviceEnvironment == :staging
392
- response = getRequest(@@SERVICE_URL_STAGING + '/CreditCard/' + buyer_key + '/BuyerKey')
393
-
394
- # se for producao, faz a chamada por aqui
395
- elsif @serviceEnvironment == :production
396
- response = getRequest(@@SERVICE_URL_PRODUCTION + '/CreditCard/' + buyer_key + '/BuyerKey')
397
-
398
- # se for sandbox, faz a chamada por aqui
399
- elsif @serviceEnvironment == :sandbox
400
- response = getRequest(@@SERVICE_URL_SANDBOX + '/CreditCard/' + buyer_key + '/BuyerKey')
401
- end
402
-
403
- # se der algum erro, trata aqui
404
- rescue Exception => e
405
- return e.message
406
- end
407
-
408
- # se nao houver erros, retorna o objeto
409
- response
410
- end
411
-
412
- # funcao de post generica
413
- def postRequest(payload, url)
414
- response = nil
415
- begin
416
- response = RestClient.post(url, payload, headers=@@SERVICE_HEADERS)
417
- rescue RestClient::ExceptionWithResponse => err
418
- return err.response
419
- end
420
- json_response = JSON.load response
421
- json_response
422
- end
423
-
424
- # funcao get generica
425
- def getRequest(url)
426
- response = nil
427
- begin
428
- response = RestClient.get(url, headers=@@SERVICE_HEADERS)
429
- rescue RestClient::ExceptionWithResponse => err
430
- return err.response
431
- end
432
- json_response = JSON.load response
433
- json_response
434
- end
435
-
436
- def getReportFile(url)
437
- begin
438
- response = RestClient.get(url, headers={:MerchantKey => "#{@merchantKey}"})
439
- rescue RestClient::ExceptionWithResponse => err
440
- return err.response
441
- end
442
- return response
443
- end
444
- end
1
+ require_relative '../../lib/mundipagg_sdk'
2
+
3
+ class Gateway
4
+
5
+ attr_reader :serviceEnvironment
6
+
7
+ attr_reader :merchantKey
8
+
9
+ def initialize(environment=:staging, merchantKey)
10
+ @serviceEnvironment = environment
11
+ @merchantKey = merchantKey
12
+ @@SERVICE_HEADERS = {:MerchantKey => "#{@merchantKey}", :Accept => 'application/json', :"Content-Type" => 'application/json'}
13
+ end
14
+
15
+ # URL de producao
16
+ @@SERVICE_URL_PRODUCTION = 'https://transactionv2.mundipaggone.com'
17
+
18
+ # URL de homologacao
19
+ @@SERVICE_URL_STAGING = 'https://stagingv2.mundipaggone.com'
20
+
21
+ # URL de sandbox
22
+ @@SERVICE_URL_SANDBOX = 'https://sandbox.mundipaggone.com'
23
+
24
+ # URL do postnotification de producao
25
+ @@SERVICE_URL_NOTIFICATION_PRODUCTION = 'https://api.mundipaggone.com/TransactionReportFile/GetStream?fileDate='
26
+
27
+ # URL do postnotification de sandbox
28
+ @@SERVICE_URL_NOTIFICATION_SANDBOX = 'https://apisandbox.mundipaggone.com/TransactionReportFile/GetStream?fileDate='
29
+
30
+ # permite que o integrador adicione uma busca por transacoes utilizando alguns criterios
31
+ def Query(querySaleRequestEnum, key)
32
+ # try, tenta fazer o request
33
+ begin
34
+ # se for homologacao faz a chamada por aqui
35
+ if @serviceEnvironment == :staging
36
+ getRequest(@@SERVICE_URL_STAGING + '/Sale/Query/' + querySaleRequestEnum + '=' + key)
37
+
38
+ # se for producao, faz a chamada por aqui
39
+ elsif @serviceEnvironment == :production
40
+ getRequest(@@SERVICE_URL_PRODUCTION + '/Sale/Query/' + querySaleRequestEnum + '=' + key)
41
+
42
+ # se for sandbox
43
+ elsif @serviceEnvironment == :sandbox
44
+ getRequest(@@SERVICE_URL_SANDBOX + '/Sale/Query/' + querySaleRequestEnum + '=' + key)
45
+ end
46
+
47
+ # se der algum erro, trata aqui
48
+ rescue Exception => e
49
+ return e.message
50
+ end
51
+ end
52
+
53
+ # criar uma transacao na plataforma One utilizando um ou mais meios de pagamento
54
+ def CreateSale(createSaleRequest)
55
+
56
+ saleHash = createSaleRequest.to_json
57
+
58
+ saleHash['BoletoTransactionCollection'] = []
59
+
60
+ saleHash['CreditCardTransactionCollection'] = []
61
+
62
+ saleHash['ShoppingCartCollection'] = []
63
+
64
+ begin
65
+ # transforma a colecao de boleto em json
66
+ if createSaleRequest.BoletoTransactionCollection.any? == false || createSaleRequest.BoletoTransactionCollection.nil?
67
+ saleHash['BoletoTransactionCollection'] = nil
68
+
69
+ else
70
+ createSaleRequest.BoletoTransactionCollection.each_with_index do |boleto, index|
71
+ b = boleto.to_json
72
+ saleHash['BoletoTransactionCollection'] << b
73
+
74
+ if boleto.Options.to_json.any?
75
+ boleto_options = boleto.Options.to_json
76
+ saleHash['BoletoTransactionCollection'][index]['Options'] = boleto_options
77
+ else
78
+ saleHash['BoletoTransactionCollection'][index]['Options'] = nil
79
+ end
80
+
81
+ if boleto.BillingAddress.to_json.any?
82
+ boleto_billing_address = boleto.BillingAddress.to_json
83
+ saleHash['BoletoTransactionCollection'][index]['BillingAddress'] = boleto_billing_address
84
+ else
85
+ saleHash['BoletoTransactionCollection'][index]['BillingAddress'] = nil
86
+ end
87
+ end
88
+ end
89
+
90
+ # transforma a colecao de cartao de credito em json
91
+ if createSaleRequest.CreditCardTransactionCollection.any? == false || createSaleRequest.CreditCardTransactionCollection.nil?
92
+ saleHash['CreditCardTransactionCollection'] = nil
93
+ else
94
+ createSaleRequest.CreditCardTransactionCollection.each_with_index do |creditCard, index|
95
+ c = creditCard.to_json
96
+ saleHash['CreditCardTransactionCollection'] << c
97
+
98
+ if creditCard.Options.to_json.any?
99
+ credit_card_options = creditCard.Options.to_json
100
+ saleHash['CreditCardTransactionCollection'][index]['Options'] = credit_card_options
101
+ else
102
+ saleHash['CreditCardTransactionCollection'][index]['Options'] = nil
103
+ end
104
+
105
+ if creditCard.Recurrency.to_json.any?
106
+ credit_card_recurrency = creditCard.Recurrency.to_json
107
+ saleHash['CreditCardTransactionCollection'][index]['Recurrency'] = credit_card_recurrency
108
+ else
109
+ saleHash['CreditCardTransactionCollection'][index]['Recurrency'] = nil
110
+ end
111
+
112
+ if creditCard.CreditCard.to_json.any?
113
+ credit_card_item = creditCard.CreditCard.to_json
114
+ saleHash['CreditCardTransactionCollection'][index]['CreditCard'] = credit_card_item
115
+
116
+ if creditCard.CreditCard.BillingAddress.to_json.any?
117
+ credit_card_billing_address = creditCard.CreditCard.BillingAddress.to_json
118
+ saleHash['CreditCardTransactionCollection'][index]['CreditCard']['BillingAddress'] = credit_card_billing_address
119
+ else
120
+ saleHash['CreditCardTransactionCollection'][index]['CreditCard']['BillingAddress'] = nil
121
+ end
122
+
123
+ else
124
+ saleHash['CreditCardTransactionCollection'][index]['CreditCard'] = nil
125
+ end
126
+ end
127
+ end
128
+
129
+ # transforma a colecao de shoppingcart em json
130
+ if createSaleRequest.ShoppingCartCollection.any? == false || createSaleRequest.ShoppingCartCollection.nil?
131
+ saleHash['ShoppingCartCollection'] = nil
132
+ else
133
+ createSaleRequest.ShoppingCartCollection.each_with_index do |shoppingCart, index|
134
+ s = shoppingCart.to_json
135
+ saleHash['ShoppingCartCollection'] << s
136
+
137
+ if shoppingCart.DeliveryAddress.to_json.any?
138
+ delivery_address = shoppingCart.DeliveryAddress.to_json
139
+ saleHash['ShoppingCartCollection'][index]['DeliveryAddress'] = delivery_address
140
+ else
141
+ saleHash['ShoppingCartCollection'][index]['DeliveryAddress'] = nil
142
+ end
143
+
144
+ if shoppingCart.ShoppingCartItemCollection.any?
145
+ shoppingCart.ShoppingCartItemCollection.each_with_index do |cartItem, cartIndex|
146
+ item = cartItem.to_json
147
+ saleHash['ShoppingCartCollection'][index]['ShoppingCartItemCollection'][cartIndex] = item
148
+ end
149
+ else
150
+ saleHash['ShoppingCartCollection'][index]['ShoppingCartItemCollection'] = nil
151
+ end
152
+ end
153
+ end
154
+
155
+ # transforma objeto options em json
156
+ if createSaleRequest.Options.to_json.any?
157
+ o = createSaleRequest.Options.to_json
158
+ saleHash['Options'] = o
159
+ else
160
+ saleHash['Options'] = nil
161
+ end
162
+
163
+ # transforma objeto order em json
164
+ if createSaleRequest.Order.to_json.any?
165
+ order = createSaleRequest.Order.to_json
166
+ saleHash['Order'] = order
167
+ else
168
+ saleHash['Order'] = nil
169
+ end
170
+
171
+ # transforma objeto merchant em json
172
+ if createSaleRequest.Merchant.to_json.any?
173
+ merchant = createSaleRequest.Merchant.to_json
174
+ saleHash['Merchant'] = merchant
175
+ else
176
+ saleHash['Merchant'] = nil
177
+ end
178
+
179
+ # transforma objeto request data em json
180
+ if createSaleRequest.RequestData.to_json.any?
181
+ request_data = createSaleRequest.RequestData.to_json
182
+ saleHash['RequestData'] = request_data
183
+ else
184
+ saleHash['RequestData'] = nil
185
+ end
186
+
187
+ # transforma o objeto Buyer em json
188
+ if createSaleRequest.Buyer.AddressCollection.any?
189
+ b = createSaleRequest.Buyer.to_json
190
+ saleHash['Buyer'] = b
191
+
192
+ saleHash['Buyer']['AddressCollection'] = []
193
+ createSaleRequest.Buyer.AddressCollection.each do |address|
194
+ a = address.to_json
195
+ saleHash['Buyer']['AddressCollection'] << a
196
+ end
197
+ else
198
+ buyer_hash = createSaleRequest.Buyer.to_json
199
+ buyer_hash.delete('AddressCollection')
200
+ if buyer_hash.blank? == false
201
+ b = createSaleRequest.Buyer.to_json
202
+ saleHash['Buyer'] = b
203
+ saleHash['Buyer']['AddressCollection'] = nil
204
+ else
205
+ saleHash['Buyer'] = nil
206
+ end
207
+ end
208
+
209
+ rescue Exception => e
210
+ return e.message
211
+ end
212
+
213
+ if @serviceEnvironment == :staging
214
+ url = @@SERVICE_URL_STAGING + '/Sale/'
215
+ elsif @serviceEnvironment == :production
216
+ url = @@SERVICE_URL_PRODUCTION + '/Sale/'
217
+ elsif @serviceEnvironment == :sandbox
218
+ url = @@SERVICE_URL_SANDBOX + '/Sale/'
219
+ end
220
+ postRequest(saleHash.to_json, url)
221
+ end
222
+
223
+ # permite forcar a retentativa manualmente de uma transacao (podendo ser tambem uma recorrencia) nao autorizada
224
+ def Retry(retrySaleRequest)
225
+ saleHash = retrySaleRequest.to_json
226
+ saleHash['RetrySaleCreditCardTransactionCollection'] = []
227
+
228
+ begin
229
+ if retrySaleRequest.RetrySaleCreditCardTransactionCollection != nil
230
+ retrySaleRequest.RetrySaleCreditCardTransactionCollection.each do |retrySale|
231
+ r = retrySale.to_json
232
+ saleHash['RetrySaleCreditCardTransactionCollection'] << r
233
+ end
234
+ end
235
+ if retrySaleRequest.Options.to_json.any?
236
+ retry_options = retrySaleRequest.Options.to_json
237
+ saleHash['Options'] = retry_options
238
+ else
239
+ saleHash['Options'] = nil
240
+ end
241
+ rescue Exception => e
242
+ return e.message
243
+ end
244
+ if @serviceEnvironment == :staging
245
+ url = @@SERVICE_URL_STAGING + '/Sale/Retry'
246
+ elsif @serviceEnvironment == :production
247
+ url = @@SERVICE_URL_PRODUCTION + '/Sale/Retry'
248
+ elsif @serviceEnvironment == :sandbox
249
+ url = @@SERVICE_URL_SANDBOX + '/Sale/Retry'
250
+ end
251
+ postRequest(saleHash.to_json, url)
252
+ end
253
+
254
+ # eh uma forma de desfazer uma transação com cartao de credito mesmo a transacao sendo capturada
255
+ def Cancel(cancelSaleRequest)
256
+ saleHash = cancelSaleRequest.to_json
257
+ saleHash['CreditCardTransactionCollection'] = []
258
+
259
+ begin
260
+ if cancelSaleRequest.CreditCardTransactionCollection != nil
261
+ cancelSaleRequest.CreditCardTransactionCollection.each do |creditCard|
262
+ c = creditCard.to_json
263
+ saleHash['CreditCardTransactionCollection'] << c
264
+ end
265
+ end
266
+ rescue Exception => e
267
+ return e.message
268
+ end
269
+ if @serviceEnvironment == :staging
270
+ url = @@SERVICE_URL_STAGING + '/Sale/Cancel'
271
+ elsif @serviceEnvironment == :production
272
+ url = @@SERVICE_URL_PRODUCTION + '/Sale/Cancel'
273
+ elsif @serviceEnvironment == :sandbox
274
+ url = @@SERVICE_URL_SANDBOX + '/Sale/Cancel'
275
+ end
276
+ postRequest(saleHash.to_json, url)
277
+ end
278
+
279
+ # confirmacao de uma transacao de cartao de credito que ja fora autorizada
280
+ def Capture(captureRequest)
281
+ saleHash = captureRequest.to_json
282
+ saleHash['CreditCardTransactionCollection'] = []
283
+
284
+ begin
285
+ if captureRequest.CreditCardTransactionCollection != nil
286
+ captureRequest.CreditCardTransactionCollection.each do |creditCard|
287
+ c = creditCard.to_json
288
+ saleHash['CreditCardTransactionCollection'] << c
289
+ end
290
+ end
291
+ rescue Exception => e
292
+ return e.message
293
+ end
294
+ if @serviceEnvironment == :staging
295
+ url = @@SERVICE_URL_STAGING + '/Sale/Capture'
296
+ elsif @serviceEnvironment == :production
297
+ url = @@SERVICE_URL_PRODUCTION + '/Sale/Capture'
298
+ elsif @serviceEnvironment == :sandbox
299
+ url = @@SERVICE_URL_SANDBOX + '/Sale/Capture'
300
+ end
301
+ postRequest(saleHash.to_json, url)
302
+ end
303
+
304
+ # faz um parse do xml de post notificaton
305
+ def ParseXmlToNotification(xml)
306
+ begin
307
+ response = PostNotification.ParseNotification(xml)
308
+ rescue Exception => err
309
+ return err.message
310
+ end
311
+
312
+ return response
313
+ end
314
+
315
+ # faz uma requisicao e retorna uma string com o transaction report file
316
+ def TransactionReportFile(date)
317
+ begin
318
+ if @serviceEnvironment == :staging
319
+ url = @@SERVICE_URL_NOTIFICATION_PRODUCTION + date.strftime("%Y%m%d")
320
+ elsif @serviceEnvironment == :production
321
+ url = @@SERVICE_URL_NOTIFICATION_PRODUCTION + date.strftime("%Y%m%d")
322
+ elsif @serviceEnvironment == :sandbox
323
+ url = @@SERVICE_URL_NOTIFICATION_SANDBOX + date.strftime("%Y%m%d")
324
+ end
325
+
326
+ response = getReportFile(url)
327
+
328
+ rescue RestClient::ExceptionWithResponse => err
329
+ return err.response
330
+ end
331
+ return response
332
+ end
333
+
334
+ # faz o download do transaction report file e salva no computador em .txt
335
+ def TransactionReportFileDownloader(date, file_name, path)
336
+ begin
337
+ path = path + file_name + '.txt'
338
+
339
+ response = TransactionReportFile(date)
340
+
341
+ File.write(path, response)
342
+ rescue RestClient::ExceptionWithResponse => err
343
+ return err.response
344
+ end
345
+ end
346
+
347
+ # faz o parse da string recebida do transaction report file e retorna um hash
348
+ def TransactionReportFileParser(file_to_parse)
349
+ transaction_report_file = TransactionReportFile.new
350
+ begin
351
+ response = transaction_report_file.TransactionReportFileParser(file_to_parse)
352
+ rescue Exception => err
353
+ return err
354
+ end
355
+ return response
356
+ end
357
+
358
+ # faz uma requisicao com instant buy key
359
+ def InstantBuyKey(instant_buy_key)
360
+ # try, tenta fazer o request
361
+ begin
362
+
363
+ # se for homologacao faz a chamada por aqui
364
+ if @serviceEnvironment == :staging
365
+ getRequest(@@SERVICE_URL_STAGING + '/CreditCard/' + instant_buy_key)
366
+
367
+ # se for producao, faz a chamada por aqui
368
+ elsif @serviceEnvironment == :production
369
+ getRequest(@@SERVICE_URL_PRODUCTION + '/CreditCard/' + instant_buy_key)
370
+
371
+ # se for sandbox
372
+ elsif @serviceEnvironment == :sandbox
373
+ getRequest(@@SERVICE_URL_SANDBOX + '/CreditCard/' + instant_buy_key)
374
+ end
375
+
376
+ # se der algum erro, trata aqui
377
+ rescue Exception => e
378
+ return e.message
379
+ end
380
+ end
381
+
382
+ # faz uma requisicao com buyer key
383
+ def BuyerKey(buyer_key)
384
+ # try, tenta fazer o request
385
+ begin
386
+
387
+ # se for homologacao faz a chamada por aqui
388
+ if @serviceEnvironment == :staging
389
+ response = getRequest(@@SERVICE_URL_STAGING + '/CreditCard/' + buyer_key + '/BuyerKey')
390
+
391
+ # se for producao, faz a chamada por aqui
392
+ elsif @serviceEnvironment == :production
393
+ response = getRequest(@@SERVICE_URL_PRODUCTION + '/CreditCard/' + buyer_key + '/BuyerKey')
394
+
395
+ # se for sandbox, faz a chamada por aqui
396
+ elsif @serviceEnvironment == :sandbox
397
+ response = getRequest(@@SERVICE_URL_SANDBOX + '/CreditCard/' + buyer_key + '/BuyerKey')
398
+ end
399
+
400
+ # se der algum erro, trata aqui
401
+ rescue Exception => e
402
+ return e.message
403
+ end
404
+
405
+ # se nao houver erros, retorna o objeto
406
+ response
407
+ end
408
+
409
+ # funcao de post generica
410
+ def postRequest(payload, url)
411
+ response = nil
412
+ begin
413
+ response = RestClient.post(url, payload, headers=@@SERVICE_HEADERS)
414
+ rescue RestClient::ExceptionWithResponse => err
415
+ return err.response
416
+ end
417
+ json_response = JSON.load response
418
+ json_response
419
+ end
420
+
421
+ # funcao get generica
422
+ def getRequest(url)
423
+ response = nil
424
+ begin
425
+ response = RestClient.get(url, headers=@@SERVICE_HEADERS)
426
+ rescue RestClient::ExceptionWithResponse => err
427
+ return err.response
428
+ end
429
+ json_response = JSON.load response
430
+ json_response
431
+ end
432
+
433
+ def getReportFile(url)
434
+ begin
435
+ response = RestClient.get(url, headers={:MerchantKey => "#{@merchantKey}"})
436
+ rescue RestClient::ExceptionWithResponse => err
437
+ return err.response
438
+ end
439
+ return response
440
+ end
441
+ end