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