mundipagg_sdk 1.3.0 → 1.4.0

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 (52) hide show
  1. checksums.yaml +13 -5
  2. data/LICENSE +190 -190
  3. data/README.md +61 -61
  4. data/lib/gateway/Address/billing_address.rb +33 -33
  5. data/lib/gateway/Address/buyer_address.rb +38 -38
  6. data/lib/gateway/Address/delivery_address.rb +34 -34
  7. data/lib/gateway/BoletoTransaction/boleto_transaction.rb +40 -40
  8. data/lib/gateway/BoletoTransaction/boleto_transaction_options.rb +16 -16
  9. data/lib/gateway/BoletoTransaction/boleto_transaction_report_file.rb +22 -22
  10. data/lib/gateway/CreditCardTransaction/credit_card.rb +30 -30
  11. data/lib/gateway/CreditCardTransaction/credit_card_transaction.rb +33 -33
  12. data/lib/gateway/CreditCardTransaction/credit_card_transaction_options.rb +28 -28
  13. data/lib/gateway/CreditCardTransaction/credit_card_transaction_report_file.rb +31 -31
  14. data/lib/gateway/CreditCardTransaction/manage_credit_card_transaction.rb +14 -14
  15. data/lib/gateway/CreditCardTransaction/retry_sale_credit_card_transaction.rb +14 -14
  16. data/lib/gateway/Gateway.rb +525 -627
  17. data/lib/gateway/InstantBuyData/create_instant_buy_data_request.rb +30 -30
  18. data/lib/gateway/InstantBuyData/update_instant_buy_data_request.rb +10 -10
  19. data/lib/gateway/Merchant/merchant.rb +12 -12
  20. data/lib/gateway/OnlineDebit/online_debit_transaction_report_file.rb +21 -21
  21. data/lib/gateway/Order/order.rb +13 -13
  22. data/lib/gateway/Order/order_transaction_report_file.rb +8 -8
  23. data/lib/gateway/Parsers/boleto_transaction_parser.rb +33 -33
  24. data/lib/gateway/Parsers/credit_card_transaction_parser.rb +42 -42
  25. data/lib/gateway/Parsers/header_parser.rb +16 -16
  26. data/lib/gateway/Parsers/online_debit_transaction_parser.rb +32 -32
  27. data/lib/gateway/Parsers/trailer_parser.rb +16 -16
  28. data/lib/gateway/Person/buyer.rb +32 -32
  29. data/lib/gateway/Person/create_buyer_request.rb +22 -22
  30. data/lib/gateway/Person/person.rb +48 -48
  31. data/lib/gateway/Recurrency/recurrency.rb +24 -24
  32. data/lib/gateway/Sale/create_sale_request.rb +37 -37
  33. data/lib/gateway/Sale/manage_sale_request.rb +18 -18
  34. data/lib/gateway/Sale/query_sale_request.rb +37 -37
  35. data/lib/gateway/Sale/request_data.rb +21 -21
  36. data/lib/gateway/Sale/retry_sale_options.rb +15 -15
  37. data/lib/gateway/Sale/retry_sale_request.rb +23 -23
  38. data/lib/gateway/Sale/sale_data.rb +30 -30
  39. data/lib/gateway/Sale/sale_order_data.rb +18 -18
  40. data/lib/gateway/SalesOption.rb +18 -18
  41. data/lib/gateway/ShoppingCart/shopping_cart.rb +27 -27
  42. data/lib/gateway/ShoppingCart/shopping_cart_item.rb +24 -24
  43. data/lib/gateway/Trailer.rb +8 -8
  44. data/lib/gateway/header.rb +7 -7
  45. data/lib/gateway/post_notification.rb +31 -31
  46. data/lib/gateway/transaction_report_file.rb +47 -47
  47. data/lib/mundipagg_sdk.rb +61 -61
  48. data/mundipagg_sdk.gemspec +20 -20
  49. data/spec/integration/gateway_spec.rb +1023 -1022
  50. data/spec/integration/test_helper.rb +68 -68
  51. data/spec/spec_helper.rb +96 -96
  52. metadata +33 -33
@@ -1,29 +1,29 @@
1
- module Gateway
2
-
3
- class CreditCardTransactionOptions
4
-
5
- attr_accessor :PaymentMethodCode
6
-
7
- attr_accessor :CurrencyIso
8
-
9
- attr_accessor :IataAmountInCents
10
-
11
- attr_accessor :CaptureDelayInMinutes
12
-
13
- attr_accessor :MerchantCategoryCode
14
-
15
- attr_accessor :SoftDescriptorText
16
-
17
- attr_accessor :InterestRate
18
-
19
- attr_accessor :ExtendedLimitEnabled
20
-
21
- attr_accessor :ExtendedLimitCode
22
-
23
- def to_json
24
- hash = {}
25
- instance_variables.each { |var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
26
- hash
27
- end
28
- end
1
+ module Gateway
2
+
3
+ class CreditCardTransactionOptions
4
+
5
+ attr_accessor :PaymentMethodCode
6
+
7
+ attr_accessor :CurrencyIso
8
+
9
+ attr_accessor :IataAmountInCents
10
+
11
+ attr_accessor :CaptureDelayInMinutes
12
+
13
+ attr_accessor :MerchantCategoryCode
14
+
15
+ attr_accessor :SoftDescriptorText
16
+
17
+ attr_accessor :InterestRate
18
+
19
+ attr_accessor :ExtendedLimitEnabled
20
+
21
+ attr_accessor :ExtendedLimitCode
22
+
23
+ def to_json
24
+ hash = {}
25
+ instance_variables.each { |var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
26
+ hash
27
+ end
28
+ end
29
29
  end
@@ -1,32 +1,32 @@
1
- module Gateway
2
-
3
- class CreditCardTransactionReportFile
4
- attr_accessor :Order
5
- attr_accessor :TransactionKey
6
- attr_accessor :TransactionKeyToAcquirer
7
- attr_accessor :CreditCardTransactionReference
8
- attr_accessor :CreditCardBrand
9
- attr_accessor :CreditCardNumber
10
- attr_accessor :InstallmentCount
11
- attr_accessor :AcquirerName
12
- attr_accessor :Status
13
- attr_accessor :AmountInCents
14
- attr_accessor :IataAmountInCents
15
- attr_accessor :AuthorizationCode
16
- attr_accessor :TransactionIdentifier
17
- attr_accessor :UniqueSequentialNumber
18
- attr_accessor :AuthorizedAmountInCents
19
- attr_accessor :CapturedAmountInCents
20
- attr_accessor :VoidedAmountInCents
21
- attr_accessor :RefundedAmountInCents
22
- attr_accessor :AcquirerAuthorizationReturnCode
23
- attr_accessor :AuthorizedDate
24
- attr_accessor :CapturedDate
25
- attr_accessor :VoidedDate
26
- attr_accessor :LastProbeDate
27
-
28
- def initialize
29
- @Order = OrderTransactionReportFile.new
30
- end
31
- end
1
+ module Gateway
2
+
3
+ class CreditCardTransactionReportFile
4
+ attr_accessor :Order
5
+ attr_accessor :TransactionKey
6
+ attr_accessor :TransactionKeyToAcquirer
7
+ attr_accessor :CreditCardTransactionReference
8
+ attr_accessor :CreditCardBrand
9
+ attr_accessor :CreditCardNumber
10
+ attr_accessor :InstallmentCount
11
+ attr_accessor :AcquirerName
12
+ attr_accessor :Status
13
+ attr_accessor :AmountInCents
14
+ attr_accessor :IataAmountInCents
15
+ attr_accessor :AuthorizationCode
16
+ attr_accessor :TransactionIdentifier
17
+ attr_accessor :UniqueSequentialNumber
18
+ attr_accessor :AuthorizedAmountInCents
19
+ attr_accessor :CapturedAmountInCents
20
+ attr_accessor :VoidedAmountInCents
21
+ attr_accessor :RefundedAmountInCents
22
+ attr_accessor :AcquirerAuthorizationReturnCode
23
+ attr_accessor :AuthorizedDate
24
+ attr_accessor :CapturedDate
25
+ attr_accessor :VoidedDate
26
+ attr_accessor :LastProbeDate
27
+
28
+ def initialize
29
+ @Order = OrderTransactionReportFile.new
30
+ end
31
+ end
32
32
  end
@@ -1,15 +1,15 @@
1
- module Gateway
2
-
3
- # classe para usar nos metodos de cancel e capture
4
- class ManageCreditCardTransaction
5
- attr_accessor :AmountInCents
6
- attr_accessor :TransactionKey
7
- attr_accessor :TransactionReference
8
-
9
- def to_json
10
- hash = {}
11
- instance_variables.each { |var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
12
- hash
13
- end
14
- end
1
+ module Gateway
2
+
3
+ # classe para usar nos metodos de cancel e capture
4
+ class ManageCreditCardTransaction
5
+ attr_accessor :AmountInCents
6
+ attr_accessor :TransactionKey
7
+ attr_accessor :TransactionReference
8
+
9
+ def to_json
10
+ hash = {}
11
+ instance_variables.each { |var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
12
+ hash
13
+ end
14
+ end
15
15
  end
@@ -1,15 +1,15 @@
1
- module Gateway
2
-
3
- class RetrySaleCreditCardTransaction
4
-
5
- attr_accessor :TransactionKey
6
-
7
- attr_accessor :SecurityCode
8
-
9
- def to_json
10
- hash = {}
11
- instance_variables.each { |var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
12
- hash
13
- end
14
- end
1
+ module Gateway
2
+
3
+ class RetrySaleCreditCardTransaction
4
+
5
+ attr_accessor :TransactionKey
6
+
7
+ attr_accessor :SecurityCode
8
+
9
+ def to_json
10
+ hash = {}
11
+ instance_variables.each { |var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
12
+ hash
13
+ end
14
+ end
15
15
  end
@@ -1,627 +1,525 @@
1
- require_relative '../../lib/mundipagg_sdk'
2
- module Gateway
3
-
4
- class Gateway
5
- extend Gem::Deprecate
6
-
7
- attr_reader :serviceEnvironment
8
-
9
- attr_reader :merchantKey
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
16
-
17
- # URL de producao
18
- @@SERVICE_URL_PRODUCTION = 'https://transactionv2.mundipaggone.com'
19
-
20
- # URL de homologacao
21
- @@SERVICE_URL_STAGING = 'https://stagingv2.mundipaggone.com'
22
-
23
- # URL de sandbox
24
- @@SERVICE_URL_SANDBOX = 'https://sandbox.mundipaggone.com'
25
-
26
- # URL do postnotification de producao
27
- @@SERVICE_URL_NOTIFICATION_PRODUCTION = 'https://api.mundipaggone.com/TransactionReportFile/GetStream?fileDate='
28
-
29
- # URL do postnotification de sandbox
30
- @@SERVICE_URL_NOTIFICATION_SANDBOX = 'https://apisandbox.mundipaggone.com/TransactionReportFile/GetStream?fileDate='
31
-
32
- # permite que o integrador adicione uma busca por transacoes utilizando alguns criterios
33
- def Query(querySaleRequestEnum, key)
34
- # try, tenta fazer o request
35
- begin
36
- # se for homologacao faz a chamada por aqui
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
48
-
49
- # se der algum erro, trata aqui
50
- rescue Exception => e
51
- return e.message
52
- end
53
- end
54
-
55
- # criar uma transacao na plataforma One utilizando um ou mais meios de pagamento
56
- def CreateSale(createSaleRequest)
57
-
58
- saleHash = createSaleRequest.to_json
59
-
60
- saleHash['BoletoTransactionCollection'] = []
61
-
62
- saleHash['CreditCardTransactionCollection'] = []
63
-
64
- saleHash['ShoppingCartCollection'] = []
65
-
66
- begin
67
- # transforma a colecao de boleto em json
68
- if createSaleRequest.BoletoTransactionCollection.any? == false || createSaleRequest.BoletoTransactionCollection.nil?
69
- saleHash['BoletoTransactionCollection'] = nil
70
-
71
- else
72
- createSaleRequest.BoletoTransactionCollection.each_with_index do |boleto, index|
73
- b = boleto.to_json
74
- saleHash['BoletoTransactionCollection'] << b
75
-
76
- if boleto.Options.to_json.any?
77
- boleto_options = boleto.Options.to_json
78
- saleHash['BoletoTransactionCollection'][index]['Options'] = boleto_options
79
- else
80
- saleHash['BoletoTransactionCollection'][index]['Options'] = nil
81
- end
82
-
83
- if boleto.BillingAddress.to_json.any?
84
- boleto_billing_address = boleto.BillingAddress.to_json
85
- saleHash['BoletoTransactionCollection'][index]['BillingAddress'] = boleto_billing_address
86
- else
87
- saleHash['BoletoTransactionCollection'][index]['BillingAddress'] = nil
88
- end
89
- end
90
- end
91
-
92
- # transforma a colecao de cartao de credito em json
93
- if createSaleRequest.CreditCardTransactionCollection.any? == false || createSaleRequest.CreditCardTransactionCollection.nil?
94
- saleHash['CreditCardTransactionCollection'] = nil
95
- else
96
- createSaleRequest.CreditCardTransactionCollection.each_with_index do |creditCard, index|
97
- c = creditCard.to_json
98
- saleHash['CreditCardTransactionCollection'] << c
99
-
100
- if creditCard.Options.to_json.any?
101
- credit_card_options = creditCard.Options.to_json
102
- saleHash['CreditCardTransactionCollection'][index]['Options'] = credit_card_options
103
- else
104
- saleHash['CreditCardTransactionCollection'][index]['Options'] = nil
105
- end
106
-
107
- if creditCard.Recurrency.to_json.any?
108
- credit_card_recurrency = creditCard.Recurrency.to_json
109
- saleHash['CreditCardTransactionCollection'][index]['Recurrency'] = credit_card_recurrency
110
- else
111
- saleHash['CreditCardTransactionCollection'][index]['Recurrency'] = nil
112
- end
113
-
114
- if creditCard.CreditCard.to_json.any?
115
- credit_card_item = creditCard.CreditCard.to_json
116
- saleHash['CreditCardTransactionCollection'][index]['CreditCard'] = credit_card_item
117
-
118
- if creditCard.CreditCard.BillingAddress.to_json.any?
119
- credit_card_billing_address = creditCard.CreditCard.BillingAddress.to_json
120
- saleHash['CreditCardTransactionCollection'][index]['CreditCard']['BillingAddress'] = credit_card_billing_address
121
- else
122
- saleHash['CreditCardTransactionCollection'][index]['CreditCard']['BillingAddress'] = nil
123
- end
124
-
125
- else
126
- saleHash['CreditCardTransactionCollection'][index]['CreditCard'] = nil
127
- end
128
- end
129
- end
130
-
131
- # transforma a colecao de shoppingcart em json
132
- if createSaleRequest.ShoppingCartCollection.any? == false || createSaleRequest.ShoppingCartCollection.nil?
133
- saleHash['ShoppingCartCollection'] = nil
134
- else
135
- createSaleRequest.ShoppingCartCollection.each_with_index do |shoppingCart, index|
136
- s = shoppingCart.to_json
137
- saleHash['ShoppingCartCollection'] << s
138
-
139
- if shoppingCart.DeliveryAddress.to_json.any?
140
- delivery_address = shoppingCart.DeliveryAddress.to_json
141
- saleHash['ShoppingCartCollection'][index]['DeliveryAddress'] = delivery_address
142
- else
143
- saleHash['ShoppingCartCollection'][index]['DeliveryAddress'] = nil
144
- end
145
-
146
- if shoppingCart.ShoppingCartItemCollection.any?
147
- shoppingCart.ShoppingCartItemCollection.each_with_index do |cartItem, cartIndex|
148
- item = cartItem.to_json
149
- saleHash['ShoppingCartCollection'][index]['ShoppingCartItemCollection'][cartIndex] = item
150
- end
151
- else
152
- saleHash['ShoppingCartCollection'][index]['ShoppingCartItemCollection'] = nil
153
- end
154
- end
155
- end
156
-
157
- # transforma objeto options em json
158
- if createSaleRequest.Options.to_json.any?
159
- o = createSaleRequest.Options.to_json
160
- saleHash['Options'] = o
161
- else
162
- saleHash['Options'] = nil
163
- end
164
-
165
- # transforma objeto order em json
166
- if createSaleRequest.Order.to_json.any?
167
- order = createSaleRequest.Order.to_json
168
- saleHash['Order'] = order
169
- else
170
- saleHash['Order'] = nil
171
- end
172
-
173
- # transforma objeto merchant em json
174
- if createSaleRequest.Merchant.to_json.any?
175
- merchant = createSaleRequest.Merchant.to_json
176
- saleHash['Merchant'] = merchant
177
- else
178
- saleHash['Merchant'] = nil
179
- end
180
-
181
- # transforma objeto request data em json
182
- if createSaleRequest.RequestData.to_json.any?
183
- request_data = createSaleRequest.RequestData.to_json
184
- saleHash['RequestData'] = request_data
185
- else
186
- saleHash['RequestData'] = nil
187
- end
188
-
189
- # transforma o objeto Buyer em json
190
- if createSaleRequest.Buyer.AddressCollection.any?
191
- b = createSaleRequest.Buyer.to_json
192
- saleHash['Buyer'] = b
193
-
194
- saleHash['Buyer']['AddressCollection'] = []
195
- createSaleRequest.Buyer.AddressCollection.each do |address|
196
- a = address.to_json
197
- saleHash['Buyer']['AddressCollection'] << a
198
- end
199
- else
200
- buyer_hash = createSaleRequest.Buyer.to_json
201
- buyer_hash.delete('AddressCollection')
202
- if buyer_hash.blank? == false
203
- b = createSaleRequest.Buyer.to_json
204
- saleHash['Buyer'] = b
205
- saleHash['Buyer']['AddressCollection'] = nil
206
- else
207
- saleHash['Buyer'] = nil
208
- end
209
- end
210
-
211
- rescue Exception => e
212
- return e.message
213
- end
214
-
215
- if @serviceEnvironment == :staging
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)
223
- end
224
-
225
- # permite forcar a retentativa manualmente de uma transacao (podendo ser tambem uma recorrencia) nao autorizada
226
- def Retry(retrySaleRequest)
227
- saleHash = retrySaleRequest.to_json
228
- saleHash['RetrySaleCreditCardTransactionCollection'] = []
229
-
230
- begin
231
- if retrySaleRequest.RetrySaleCreditCardTransactionCollection != nil
232
- retrySaleRequest.RetrySaleCreditCardTransactionCollection.each do |retrySale|
233
- r = retrySale.to_json
234
- saleHash['RetrySaleCreditCardTransactionCollection'] << r
235
- end
236
- end
237
- if retrySaleRequest.Options.to_json.any?
238
- retry_options = retrySaleRequest.Options.to_json
239
- saleHash['Options'] = retry_options
240
- else
241
- saleHash['Options'] = nil
242
- end
243
- rescue Exception => e
244
- return e.message
245
- end
246
- if @serviceEnvironment == :staging
247
- url = @@SERVICE_URL_STAGING + '/Sale/Retry'
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)
254
- end
255
-
256
- # eh uma forma de desfazer uma transação com cartao de credito mesmo a transacao sendo capturada
257
- def Cancel(cancelSaleRequest)
258
- saleHash = cancelSaleRequest.to_json
259
- saleHash['CreditCardTransactionCollection'] = []
260
-
261
- begin
262
- if cancelSaleRequest.CreditCardTransactionCollection != nil
263
- cancelSaleRequest.CreditCardTransactionCollection.each do |creditCard|
264
- c = creditCard.to_json
265
- saleHash['CreditCardTransactionCollection'] << c
266
- end
267
- end
268
- rescue Exception => e
269
- return e.message
270
- end
271
- if @serviceEnvironment == :staging
272
- url = @@SERVICE_URL_STAGING + '/Sale/Cancel'
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)
279
- end
280
-
281
- # confirmacao de uma transacao de cartao de credito que ja fora autorizada
282
- def Capture(captureRequest)
283
- saleHash = captureRequest.to_json
284
- saleHash['CreditCardTransactionCollection'] = []
285
-
286
- begin
287
- if captureRequest.CreditCardTransactionCollection != nil
288
- captureRequest.CreditCardTransactionCollection.each do |creditCard|
289
- c = creditCard.to_json
290
- saleHash['CreditCardTransactionCollection'] << c
291
- end
292
- end
293
- rescue Exception => e
294
- return e.message
295
- end
296
- if @serviceEnvironment == :staging
297
- url = @@SERVICE_URL_STAGING + '/Sale/Capture'
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)
304
- end
305
-
306
- # faz um parse do xml de post notificaton
307
- def ParseXmlToNotification(xml)
308
- begin
309
- response = PostNotification.ParseNotification(xml)
310
- rescue Exception => err
311
- return err.message
312
- end
313
-
314
- return response
315
- end
316
-
317
- # faz uma requisicao e retorna uma string com o transaction report file
318
- def TransactionReportFile(date)
319
- begin
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
-
341
- response = TransactionReportFile(date)
342
-
343
- File.write(path, response)
344
- rescue RestClient::ExceptionWithResponse => err
345
- return err.response
346
- end
347
- end
348
-
349
- # faz o parse da string recebida do transaction report file e retorna um hash
350
- def TransactionReportFileParser(file_to_parse)
351
- transaction_report_file = TransactionReportFile.new
352
- begin
353
- response = transaction_report_file.TransactionReportFileParser(file_to_parse)
354
- rescue Exception => err
355
- return err
356
- end
357
- return response
358
- end
359
-
360
- # DEPRECATED
361
- def InstantBuyKey(instant_buy_key)
362
- GetCreditCard(instant_buy_key)
363
- end
364
- deprecate :InstantBuyKey, :GetCreditCard, 2016, 04
365
-
366
- # DEPRECATED
367
- def BuyerKey(buyer_key)
368
- GetCreditCardWithBuyerKey(buyer_key)
369
- end
370
- deprecate :BuyerKey, :GetCreditCardWithBuyerKey, 2016, 04
371
-
372
- # faz um get credit card com buyer key
373
- def GetCreditCardWithBuyerKey(buyer_key)
374
- # try, tenta fazer o request
375
- 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
389
-
390
- # se der algum erro, trata aqui
391
- rescue Exception => e
392
- return e.message
393
- end
394
-
395
- # se nao houver erros, retorna o objeto
396
- response
397
- end
398
-
399
- # Faz um get no cartão de crédito
400
- def GetCreditCard(instant_buy_key)
401
- # try, tenta fazer o request
402
- begin
403
- # se for homologacao faz a chamada por aqui
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
415
-
416
- # se der algum erro, trata aqui
417
- rescue Exception => e
418
- return e.message
419
- end
420
- end
421
-
422
- # Cria um cartão de crédito
423
- def CreateCreditCard(create_instant_buy_data)
424
- sale_hash = create_instant_buy_data.to_json
425
- begin
426
- if create_instant_buy_data.BillingAddress.to_json.any?
427
- sale_hash['BillingAddress'] = create_instant_buy_data.BillingAddress.to_json
428
- else
429
- sale_hash['BillingAddress'] = nil
430
- end
431
-
432
- # se for homologacao faz a chamada por aqui
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)
446
-
447
- # se der algum erro, trata aqui
448
- rescue Exception => e
449
- return e.message
450
- end
451
- # se nao houver erros, retorna o objeto
452
- response
453
- end
454
-
455
- # Atualiza o cartão de crédito
456
- def UpdateCreditCard(instant_buy_key, update_instant_buy_data_request)
457
- begin
458
- sale_hash = update_instant_buy_data_request.to_json
459
-
460
- # se for homologacao faz a chamada por aqui
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)
474
- # se der algum erro, trata aqui
475
- rescue Exception => e
476
- return e.message
477
- end
478
- # se nao houver erros, retorna o objeto
479
- response
480
- end
481
-
482
- # Deleta um cartão de crédito
483
- def DeleteCreditCard(instant_buy_key)
484
- # try, tenta fazer o request
485
- begin
486
- # se for homologacao faz a chamada por aqui
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
498
-
499
- # se der algum erro, trata aqui
500
- rescue Exception => e
501
- return e.message
502
- end
503
- end
504
-
505
- # Busca um buyer
506
- def GetBuyer(buyer_key)
507
- # try, tenta fazer o request
508
- 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
522
-
523
- # se der algum erro, trata aqui
524
- rescue Exception => e
525
- return e.message
526
- end
527
-
528
- # se nao houver erros, retorna o objeto
529
- response
530
- end
531
-
532
- # Cria um buyer
533
- def CreateBuyer(buyer_request)
534
- sale_hash = buyer_request.to_json
535
- sale_hash['AddressCollection'] = []
536
- begin
537
- if buyer_request.AddressCollection.any? == false || buyer_request.AddressCollection.nil?
538
- sale_hash['AddressCollection'] = nil
539
- else
540
- buyer_request.AddressCollection.each do |address|
541
- a = address.to_json
542
- sale_hash['AddressCollection'] << a
543
- end
544
- end
545
-
546
- # se for homologacao faz a chamada por aqui
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)
560
- rescue Exception => e
561
- return e.message
562
- end
563
- response
564
- end
565
-
566
- # funcao de post generica
567
- def postRequest(payload, url)
568
- begin
569
- response = RestClient.post(url, payload, headers=@@SERVICE_HEADERS)
570
- rescue RestClient::ExceptionWithResponse => err
571
- response = err.response
572
- end
573
-
574
- JSON.load response
575
- rescue JSON::ParserError => err
576
- response
577
- end
578
-
579
- # funcao patch generica
580
- def patchRequest(payload, url)
581
- begin
582
- response = RestClient.patch(url, payload, headers=@@SERVICE_HEADERS)
583
- rescue RestClient::ExceptionWithResponse => err
584
- response = err.response
585
- end
586
-
587
- JSON.load response
588
- rescue JSON::ParserError => err
589
- response
590
- end
591
-
592
- # funcao de delete generica
593
- def deleteRequest(url)
594
- begin
595
- response = RestClient.delete(url, headers=@@SERVICE_HEADERS)
596
- rescue RestClient::ExceptionWithResponse => err
597
- response = err.response
598
- end
599
-
600
- JSON.load response
601
- rescue JSON::ParserError => err
602
- response
603
- end
604
-
605
- # funcao get generica
606
- def getRequest(url)
607
- begin
608
- response = RestClient.get(url, headers=@@SERVICE_HEADERS)
609
- rescue RestClient::ExceptionWithResponse => err
610
- response = err.response
611
- end
612
-
613
- JSON.load response
614
- rescue JSON::ParserError => err
615
- response
616
- end
617
-
618
- def getReportFile(url)
619
- begin
620
- response = RestClient.get(url, headers={:MerchantKey => "#{@merchantKey}"})
621
- rescue RestClient::ExceptionWithResponse => err
622
- return err.response
623
- end
624
- return response
625
- end
626
- end
627
- end
1
+ require_relative '../../lib/mundipagg_sdk'
2
+ module Gateway
3
+
4
+ class Gateway
5
+ extend Gem::Deprecate
6
+
7
+ attr_reader :service_environment
8
+
9
+ attr_reader :merchant_key
10
+
11
+ # URL de producao
12
+ @@SERVICE_URL_PRODUCTION = 'https://transactionv2.mundipaggone.com'
13
+
14
+ # URL de homologacao
15
+ @@SERVICE_URL_STAGING = 'https://stagingv2.mundipaggone.com'
16
+
17
+ # URL de sandbox
18
+ @@SERVICE_URL_SANDBOX = 'https://sandbox.mundipaggone.com'
19
+
20
+ # URL do postnotification de producao
21
+ @@SERVICE_URL_REPORT_FILE_PRODUCTION = 'https://api.mundipaggone.com'
22
+
23
+ # URL do postnotification de sandbox
24
+ @@SERVICE_URL_REPORT_FILE_SANDBOX = 'https://apisandbox.mundipaggone.com'
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
59
+
60
+ # permite que o integrador adicione uma busca por transacoes utilizando alguns criterios
61
+ def Query(querySaleRequestEnum, key)
62
+ # try, tenta fazer o request
63
+ begin
64
+ getRequest(@@SERVICE_URL + '/Sale/Query/' + querySaleRequestEnum + '=' + key)
65
+
66
+ # se der algum erro, trata aqui
67
+ rescue Exception => e
68
+ return e.message
69
+ end
70
+ end
71
+
72
+ # criar uma transacao na plataforma One utilizando um ou mais meios de pagamento
73
+ def CreateSale(createSaleRequest)
74
+
75
+ saleHash = createSaleRequest.to_json
76
+
77
+ saleHash['BoletoTransactionCollection'] = []
78
+
79
+ saleHash['CreditCardTransactionCollection'] = []
80
+
81
+ saleHash['ShoppingCartCollection'] = []
82
+
83
+ begin
84
+ # transforma a colecao de boleto em json
85
+ if createSaleRequest.BoletoTransactionCollection.any? == false || createSaleRequest.BoletoTransactionCollection.nil?
86
+ saleHash['BoletoTransactionCollection'] = nil
87
+
88
+ else
89
+ createSaleRequest.BoletoTransactionCollection.each_with_index do |boleto, index|
90
+ b = boleto.to_json
91
+ saleHash['BoletoTransactionCollection'] << b
92
+
93
+ if boleto.Options.to_json.any?
94
+ boleto_options = boleto.Options.to_json
95
+ saleHash['BoletoTransactionCollection'][index]['Options'] = boleto_options
96
+ else
97
+ saleHash['BoletoTransactionCollection'][index]['Options'] = nil
98
+ end
99
+
100
+ if boleto.BillingAddress.to_json.any?
101
+ boleto_billing_address = boleto.BillingAddress.to_json
102
+ saleHash['BoletoTransactionCollection'][index]['BillingAddress'] = boleto_billing_address
103
+ else
104
+ saleHash['BoletoTransactionCollection'][index]['BillingAddress'] = nil
105
+ end
106
+ end
107
+ end
108
+
109
+ # transforma a colecao de cartao de credito em json
110
+ if createSaleRequest.CreditCardTransactionCollection.any? == false || createSaleRequest.CreditCardTransactionCollection.nil?
111
+ saleHash['CreditCardTransactionCollection'] = nil
112
+ else
113
+ createSaleRequest.CreditCardTransactionCollection.each_with_index do |creditCard, index|
114
+ c = creditCard.to_json
115
+ saleHash['CreditCardTransactionCollection'] << c
116
+
117
+ if creditCard.Options.to_json.any?
118
+ credit_card_options = creditCard.Options.to_json
119
+ saleHash['CreditCardTransactionCollection'][index]['Options'] = credit_card_options
120
+ else
121
+ saleHash['CreditCardTransactionCollection'][index]['Options'] = nil
122
+ end
123
+
124
+ if creditCard.Recurrency.to_json.any?
125
+ credit_card_recurrency = creditCard.Recurrency.to_json
126
+ saleHash['CreditCardTransactionCollection'][index]['Recurrency'] = credit_card_recurrency
127
+ else
128
+ saleHash['CreditCardTransactionCollection'][index]['Recurrency'] = nil
129
+ end
130
+
131
+ if creditCard.CreditCard.to_json.any?
132
+ credit_card_item = creditCard.CreditCard.to_json
133
+ saleHash['CreditCardTransactionCollection'][index]['CreditCard'] = credit_card_item
134
+
135
+ if creditCard.CreditCard.BillingAddress.to_json.any?
136
+ credit_card_billing_address = creditCard.CreditCard.BillingAddress.to_json
137
+ saleHash['CreditCardTransactionCollection'][index]['CreditCard']['BillingAddress'] = credit_card_billing_address
138
+ else
139
+ saleHash['CreditCardTransactionCollection'][index]['CreditCard']['BillingAddress'] = nil
140
+ end
141
+
142
+ else
143
+ saleHash['CreditCardTransactionCollection'][index]['CreditCard'] = nil
144
+ end
145
+ end
146
+ end
147
+
148
+ # transforma a colecao de shoppingcart em json
149
+ if createSaleRequest.ShoppingCartCollection.any? == false || createSaleRequest.ShoppingCartCollection.nil?
150
+ saleHash['ShoppingCartCollection'] = nil
151
+ else
152
+ createSaleRequest.ShoppingCartCollection.each_with_index do |shoppingCart, index|
153
+ s = shoppingCart.to_json
154
+ saleHash['ShoppingCartCollection'] << s
155
+
156
+ if shoppingCart.DeliveryAddress.to_json.any?
157
+ delivery_address = shoppingCart.DeliveryAddress.to_json
158
+ saleHash['ShoppingCartCollection'][index]['DeliveryAddress'] = delivery_address
159
+ else
160
+ saleHash['ShoppingCartCollection'][index]['DeliveryAddress'] = nil
161
+ end
162
+
163
+ if shoppingCart.ShoppingCartItemCollection.any?
164
+ shoppingCart.ShoppingCartItemCollection.each_with_index do |cartItem, cartIndex|
165
+ item = cartItem.to_json
166
+ saleHash['ShoppingCartCollection'][index]['ShoppingCartItemCollection'][cartIndex] = item
167
+ end
168
+ else
169
+ saleHash['ShoppingCartCollection'][index]['ShoppingCartItemCollection'] = nil
170
+ end
171
+ end
172
+ end
173
+
174
+ # transforma objeto options em json
175
+ if createSaleRequest.Options.to_json.any?
176
+ o = createSaleRequest.Options.to_json
177
+ saleHash['Options'] = o
178
+ else
179
+ saleHash['Options'] = nil
180
+ end
181
+
182
+ # transforma objeto order em json
183
+ if createSaleRequest.Order.to_json.any?
184
+ order = createSaleRequest.Order.to_json
185
+ saleHash['Order'] = order
186
+ else
187
+ saleHash['Order'] = nil
188
+ end
189
+
190
+ # transforma objeto merchant em json
191
+ if createSaleRequest.Merchant.to_json.any?
192
+ merchant = createSaleRequest.Merchant.to_json
193
+ saleHash['Merchant'] = merchant
194
+ else
195
+ saleHash['Merchant'] = nil
196
+ end
197
+
198
+ # transforma objeto request data em json
199
+ if createSaleRequest.RequestData.to_json.any?
200
+ request_data = createSaleRequest.RequestData.to_json
201
+ saleHash['RequestData'] = request_data
202
+ else
203
+ saleHash['RequestData'] = nil
204
+ end
205
+
206
+ # transforma o objeto Buyer em json
207
+ if createSaleRequest.Buyer.AddressCollection.any?
208
+ b = createSaleRequest.Buyer.to_json
209
+ saleHash['Buyer'] = b
210
+
211
+ saleHash['Buyer']['AddressCollection'] = []
212
+ createSaleRequest.Buyer.AddressCollection.each do |address|
213
+ a = address.to_json
214
+ saleHash['Buyer']['AddressCollection'] << a
215
+ end
216
+ else
217
+ buyer_hash = createSaleRequest.Buyer.to_json
218
+ buyer_hash.delete('AddressCollection')
219
+ if buyer_hash.blank? == false
220
+ b = createSaleRequest.Buyer.to_json
221
+ saleHash['Buyer'] = b
222
+ saleHash['Buyer']['AddressCollection'] = nil
223
+ else
224
+ saleHash['Buyer'] = nil
225
+ end
226
+ end
227
+
228
+ rescue Exception => e
229
+ return e.message
230
+ end
231
+
232
+ postRequest(saleHash.to_json, @@SERVICE_URL + '/Sale/')
233
+ end
234
+
235
+ # permite forcar a retentativa manualmente de uma transacao (podendo ser tambem uma recorrencia) nao autorizada
236
+ def Retry(retrySaleRequest)
237
+ saleHash = retrySaleRequest.to_json
238
+ saleHash['RetrySaleCreditCardTransactionCollection'] = []
239
+
240
+ begin
241
+ if retrySaleRequest.RetrySaleCreditCardTransactionCollection != nil
242
+ retrySaleRequest.RetrySaleCreditCardTransactionCollection.each do |retrySale|
243
+ r = retrySale.to_json
244
+ saleHash['RetrySaleCreditCardTransactionCollection'] << r
245
+ end
246
+ end
247
+ if retrySaleRequest.Options.to_json.any?
248
+ retry_options = retrySaleRequest.Options.to_json
249
+ saleHash['Options'] = retry_options
250
+ else
251
+ saleHash['Options'] = nil
252
+ end
253
+ rescue Exception => e
254
+ return e.message
255
+ end
256
+
257
+ postRequest(saleHash.to_json, @@SERVICE_URL + '/Sale/Retry')
258
+ end
259
+
260
+ # eh uma forma de desfazer uma transação com cartao de credito mesmo a transacao sendo capturada
261
+ def Cancel(cancelSaleRequest)
262
+ saleHash = cancelSaleRequest.to_json
263
+ saleHash['CreditCardTransactionCollection'] = []
264
+
265
+ begin
266
+ if cancelSaleRequest.CreditCardTransactionCollection != nil
267
+ cancelSaleRequest.CreditCardTransactionCollection.each do |creditCard|
268
+ c = creditCard.to_json
269
+ saleHash['CreditCardTransactionCollection'] << c
270
+ end
271
+ end
272
+ rescue Exception => e
273
+ return e.message
274
+ end
275
+
276
+ postRequest(saleHash.to_json, @@SERVICE_URL + '/Sale/Cancel')
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
+
295
+ postRequest(saleHash.to_json, @@SERVICE_URL + '/Sale/Capture')
296
+ end
297
+
298
+ # faz um parse do xml de post notificaton
299
+ def ParseXmlToNotification(xml)
300
+ begin
301
+ response = PostNotification.ParseNotification(xml)
302
+ rescue Exception => err
303
+ return err.message
304
+ end
305
+
306
+ return response
307
+ end
308
+
309
+ # faz uma requisicao e retorna uma string com o transaction report file
310
+ def TransactionReportFile(date)
311
+ begin
312
+ response = getReportFile(@@SERVICE_URL_REPORT_FILE + '/TransactionReportFile/GetStream?fileDate=' + date.strftime("%Y%m%d"))
313
+ rescue RestClient::ExceptionWithResponse => err
314
+ return err.response
315
+ end
316
+ return response
317
+ end
318
+
319
+ # faz o download do transaction report file e salva no computador em .txt
320
+ def TransactionReportFileDownloader(date, file_name, path)
321
+ begin
322
+ path = path + file_name + '.txt'
323
+
324
+ response = TransactionReportFile(date)
325
+
326
+ File.write(path, response)
327
+ rescue RestClient::ExceptionWithResponse => err
328
+ return err.response
329
+ end
330
+ end
331
+
332
+ # faz o parse da string recebida do transaction report file e retorna um hash
333
+ def TransactionReportFileParser(file_to_parse)
334
+ transaction_report_file = TransactionReportFile.new
335
+ begin
336
+ response = transaction_report_file.TransactionReportFileParser(file_to_parse)
337
+ rescue Exception => err
338
+ return err
339
+ end
340
+ return response
341
+ end
342
+
343
+ # DEPRECATED
344
+ def InstantBuyKey(instant_buy_key)
345
+ GetCreditCard(instant_buy_key)
346
+ end
347
+ deprecate :InstantBuyKey, :GetCreditCard, 2016, 04
348
+
349
+ # DEPRECATED
350
+ def BuyerKey(buyer_key)
351
+ GetCreditCardWithBuyerKey(buyer_key)
352
+ end
353
+ deprecate :BuyerKey, :GetCreditCardWithBuyerKey, 2016, 04
354
+
355
+ # faz um get credit card com buyer key
356
+ def GetCreditCardWithBuyerKey(buyer_key)
357
+ # try, tenta fazer o request
358
+ begin
359
+ response = getRequest(@@SERVICE_URL + '/CreditCard/BuyerKey=' + buyer_key)
360
+
361
+ # se der algum erro, trata aqui
362
+ rescue Exception => e
363
+ return e.message
364
+ end
365
+
366
+ # se nao houver erros, retorna o objeto
367
+ response
368
+ end
369
+
370
+ # Faz um get no cartão de crédito
371
+ def GetCreditCard(instant_buy_key)
372
+ # try, tenta fazer o request
373
+ begin
374
+ getRequest(@@SERVICE_URL + '/CreditCard/' + instant_buy_key)
375
+
376
+ # se der algum erro, trata aqui
377
+ rescue Exception => e
378
+ return e.message
379
+ end
380
+ end
381
+
382
+ # Cria um cartão de crédito
383
+ def CreateCreditCard(create_instant_buy_data)
384
+ sale_hash = create_instant_buy_data.to_json
385
+ begin
386
+ if create_instant_buy_data.BillingAddress.to_json.any?
387
+ sale_hash['BillingAddress'] = create_instant_buy_data.BillingAddress.to_json
388
+ else
389
+ sale_hash['BillingAddress'] = nil
390
+ end
391
+
392
+ response = postRequest(sale_hash.to_json, @@SERVICE_URL + '/CreditCard/')
393
+
394
+ # se der algum erro, trata aqui
395
+ rescue Exception => e
396
+ return e.message
397
+ end
398
+ # se nao houver erros, retorna o objeto
399
+ response
400
+ end
401
+
402
+ # Atualiza o cartão de crédito
403
+ def UpdateCreditCard(instant_buy_key, update_instant_buy_data_request)
404
+ begin
405
+ sale_hash = update_instant_buy_data_request.to_json
406
+
407
+ response = patchRequest(sale_hash.to_json, @@SERVICE_URL + '/CreditCard/' + instant_buy_key)
408
+ # se der algum erro, trata aqui
409
+ rescue Exception => e
410
+ return e.message
411
+ end
412
+ # se nao houver erros, retorna o objeto
413
+ response
414
+ end
415
+
416
+ # Deleta um cartão de crédito
417
+ def DeleteCreditCard(instant_buy_key)
418
+ # try, tenta fazer o request
419
+ begin
420
+ deleteRequest(@@SERVICE_URL + '/CreditCard/' + instant_buy_key)
421
+
422
+ # se der algum erro, trata aqui
423
+ rescue Exception => e
424
+ return e.message
425
+ end
426
+ end
427
+
428
+ # Busca um buyer
429
+ def GetBuyer(buyer_key)
430
+ # try, tenta fazer o request
431
+ begin
432
+ response = getRequest(@@SERVICE_URL + '/Buyer/' + buyer_key)
433
+
434
+ # se der algum erro, trata aqui
435
+ rescue Exception => e
436
+ return e.message
437
+ end
438
+
439
+ # se nao houver erros, retorna o objeto
440
+ response
441
+ end
442
+
443
+ # Cria um buyer
444
+ def CreateBuyer(buyer_request)
445
+ sale_hash = buyer_request.to_json
446
+ sale_hash['AddressCollection'] = []
447
+ begin
448
+ if buyer_request.AddressCollection.any? == false || buyer_request.AddressCollection.nil?
449
+ sale_hash['AddressCollection'] = nil
450
+ else
451
+ buyer_request.AddressCollection.each do |address|
452
+ a = address.to_json
453
+ sale_hash['AddressCollection'] << a
454
+ end
455
+ end
456
+
457
+ response = postRequest(sale_hash.to_json, @@SERVICE_URL + '/Buyer/')
458
+ rescue Exception => e
459
+ return e.message
460
+ end
461
+ response
462
+ end
463
+
464
+ # funcao de post generica
465
+ def postRequest(payload, url)
466
+ begin
467
+ response = RestClient.post(url, payload, headers=@@SERVICE_HEADERS)
468
+ rescue RestClient::ExceptionWithResponse => err
469
+ response = err.response
470
+ end
471
+
472
+ JSON.load response
473
+ rescue JSON::ParserError => err
474
+ response
475
+ end
476
+
477
+ # funcao patch generica
478
+ def patchRequest(payload, url)
479
+ begin
480
+ response = RestClient.patch(url, payload, headers=@@SERVICE_HEADERS)
481
+ rescue RestClient::ExceptionWithResponse => err
482
+ response = err.response
483
+ end
484
+
485
+ JSON.load response
486
+ rescue JSON::ParserError => err
487
+ response
488
+ end
489
+
490
+ # funcao de delete generica
491
+ def deleteRequest(url)
492
+ begin
493
+ response = RestClient.delete(url, headers=@@SERVICE_HEADERS)
494
+ rescue RestClient::ExceptionWithResponse => err
495
+ response = err.response
496
+ end
497
+
498
+ JSON.load response
499
+ rescue JSON::ParserError => err
500
+ response
501
+ end
502
+
503
+ # funcao get generica
504
+ def getRequest(url)
505
+ begin
506
+ response = RestClient.get(url, headers=@@SERVICE_HEADERS)
507
+ rescue RestClient::ExceptionWithResponse => err
508
+ response = err.response
509
+ end
510
+
511
+ JSON.load response
512
+ rescue JSON::ParserError => err
513
+ response
514
+ end
515
+
516
+ def getReportFile(url)
517
+ begin
518
+ response = RestClient.get(url, headers={:MerchantKey => "#{@merchant_key}"})
519
+ rescue RestClient::ExceptionWithResponse => err
520
+ return err.response
521
+ end
522
+ return response
523
+ end
524
+ end
525
+ end