stone_ecommerce 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 +202 -0
- data/README.md +64 -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 +442 -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/stone_ecommerce.rb +70 -0
- data/spec/integration/gateway_spec.rb +616 -0
- data/spec/integration/test_helper.rb +69 -0
- data/spec/spec_helper.rb +96 -0
- data/stone_ecommerce.gemspec +19 -0
- metadata +247 -0
@@ -0,0 +1,442 @@
|
|
1
|
+
require_relative '../../lib/stone_ecommerce'
|
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://transaction.stone.com.br'
|
17
|
+
|
18
|
+
# URL de homologacao
|
19
|
+
@@SERVICE_URL_STAGING = ''
|
20
|
+
|
21
|
+
# URL de sandbox
|
22
|
+
@@SERVICE_URL_SANDBOX = ''
|
23
|
+
|
24
|
+
# URL do postnotification de producao
|
25
|
+
@@SERVICE_URL_NOTIFICATION_PRODUCTION = ''
|
26
|
+
|
27
|
+
# URL do postnotification de sandbox
|
28
|
+
@@SERVICE_URL_NOTIFICATION_SANDBOX = ''
|
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
|
+
|
234
|
+
if retrySaleRequest.Options.to_json.any?
|
235
|
+
retry_options = retrySaleRequest.Options.to_json
|
236
|
+
saleHash['Options'] = retry_options
|
237
|
+
else
|
238
|
+
saleHash['Options'] = nil
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
rescue Exception => e
|
243
|
+
return e.message
|
244
|
+
end
|
245
|
+
if @serviceEnvironment == :staging
|
246
|
+
url = @@SERVICE_URL_STAGING + '/Sale/Retry'
|
247
|
+
elsif @serviceEnvironment == :production
|
248
|
+
url = @@SERVICE_URL_PRODUCTION + '/Sale/Retry'
|
249
|
+
elsif @serviceEnvironment == :sandbox
|
250
|
+
url = @@SERVICE_URL_SANDBOX + '/Sale/Retry'
|
251
|
+
end
|
252
|
+
postRequest(saleHash.to_json, url)
|
253
|
+
end
|
254
|
+
|
255
|
+
# eh uma forma de desfazer uma transação com cartao de credito mesmo a transacao sendo capturada
|
256
|
+
def Cancel(cancelSaleRequest)
|
257
|
+
saleHash = cancelSaleRequest.to_json
|
258
|
+
saleHash['CreditCardTransactionCollection'] = []
|
259
|
+
|
260
|
+
begin
|
261
|
+
if cancelSaleRequest.CreditCardTransactionCollection != nil
|
262
|
+
cancelSaleRequest.CreditCardTransactionCollection.each do |creditCard|
|
263
|
+
c = creditCard.to_json
|
264
|
+
saleHash['CreditCardTransactionCollection'] << c
|
265
|
+
end
|
266
|
+
end
|
267
|
+
rescue Exception => e
|
268
|
+
return e.message
|
269
|
+
end
|
270
|
+
if @serviceEnvironment == :staging
|
271
|
+
url = @@SERVICE_URL_STAGING + '/Sale/Cancel'
|
272
|
+
elsif @serviceEnvironment == :production
|
273
|
+
url = @@SERVICE_URL_PRODUCTION + '/Sale/Cancel'
|
274
|
+
elsif @serviceEnvironment == :sandbox
|
275
|
+
url = @@SERVICE_URL_SANDBOX + '/Sale/Cancel'
|
276
|
+
end
|
277
|
+
postRequest(saleHash.to_json, url)
|
278
|
+
end
|
279
|
+
|
280
|
+
# confirmacao de uma transacao de cartao de credito que ja fora autorizada
|
281
|
+
def Capture(captureRequest)
|
282
|
+
saleHash = captureRequest.to_json
|
283
|
+
saleHash['CreditCardTransactionCollection'] = []
|
284
|
+
|
285
|
+
begin
|
286
|
+
if captureRequest.CreditCardTransactionCollection != nil
|
287
|
+
captureRequest.CreditCardTransactionCollection.each do |creditCard|
|
288
|
+
c = creditCard.to_json
|
289
|
+
saleHash['CreditCardTransactionCollection'] << c
|
290
|
+
end
|
291
|
+
end
|
292
|
+
rescue Exception => e
|
293
|
+
return e.message
|
294
|
+
end
|
295
|
+
if @serviceEnvironment == :staging
|
296
|
+
url = @@SERVICE_URL_STAGING + '/Sale/Capture'
|
297
|
+
elsif @serviceEnvironment == :production
|
298
|
+
url = @@SERVICE_URL_PRODUCTION + '/Sale/Capture'
|
299
|
+
elsif @serviceEnvironment == :sandbox
|
300
|
+
url = @@SERVICE_URL_SANDBOX + '/Sale/Capture'
|
301
|
+
end
|
302
|
+
postRequest(saleHash.to_json, url)
|
303
|
+
end
|
304
|
+
|
305
|
+
# faz um parse do xml de post notificaton
|
306
|
+
def ParseXmlToNotification(xml)
|
307
|
+
begin
|
308
|
+
response = PostNotification.ParseNotification(xml)
|
309
|
+
rescue Exception => err
|
310
|
+
return err.message
|
311
|
+
end
|
312
|
+
|
313
|
+
return response
|
314
|
+
end
|
315
|
+
|
316
|
+
# faz uma requisicao e retorna uma string com o transaction report file
|
317
|
+
def TransactionReportFile(date)
|
318
|
+
begin
|
319
|
+
if @serviceEnvironment == :staging
|
320
|
+
url = @@SERVICE_URL_NOTIFICATION_PRODUCTION + date.strftime("%Y%m%d")
|
321
|
+
elsif @serviceEnvironment == :production
|
322
|
+
url = @@SERVICE_URL_NOTIFICATION_PRODUCTION + date.strftime("%Y%m%d")
|
323
|
+
elsif @serviceEnvironment == :sandbox
|
324
|
+
url = @@SERVICE_URL_NOTIFICATION_SANDBOX + date.strftime("%Y%m%d")
|
325
|
+
end
|
326
|
+
|
327
|
+
response = getReportFile(url)
|
328
|
+
|
329
|
+
rescue RestClient::ExceptionWithResponse => err
|
330
|
+
return err.response
|
331
|
+
end
|
332
|
+
return response
|
333
|
+
end
|
334
|
+
|
335
|
+
# faz o download do transaction report file e salva no computador em .txt
|
336
|
+
def TransactionReportFileDownloader(date, file_name, path)
|
337
|
+
begin
|
338
|
+
path = path + file_name + '.txt'
|
339
|
+
|
340
|
+
response = TransactionReportFile(date)
|
341
|
+
|
342
|
+
File.write(path, response)
|
343
|
+
rescue RestClient::ExceptionWithResponse => err
|
344
|
+
return err.response
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
# faz o parse da string recebida do transaction report file e retorna um hash
|
349
|
+
def TransactionReportFileParser(file_to_parse)
|
350
|
+
transaction_report_file = TransactionReportFile.new
|
351
|
+
begin
|
352
|
+
response = transaction_report_file.TransactionReportFileParser(file_to_parse)
|
353
|
+
rescue Exception => err
|
354
|
+
return err
|
355
|
+
end
|
356
|
+
return response
|
357
|
+
end
|
358
|
+
|
359
|
+
# faz uma requisicao com instant buy key
|
360
|
+
def InstantBuyKey(instant_buy_key)
|
361
|
+
# try, tenta fazer o request
|
362
|
+
begin
|
363
|
+
|
364
|
+
# se for homologacao faz a chamada por aqui
|
365
|
+
if @serviceEnvironment == :staging
|
366
|
+
getRequest(@@SERVICE_URL_STAGING + '/CreditCard/' + instant_buy_key)
|
367
|
+
|
368
|
+
# se for producao, faz a chamada por aqui
|
369
|
+
elsif @serviceEnvironment == :production
|
370
|
+
getRequest(@@SERVICE_URL_PRODUCTION + '/CreditCard/' + instant_buy_key)
|
371
|
+
|
372
|
+
# se for sandbox
|
373
|
+
elsif @serviceEnvironment == :sandbox
|
374
|
+
getRequest(@@SERVICE_URL_SANDBOX + '/CreditCard/' + instant_buy_key)
|
375
|
+
end
|
376
|
+
|
377
|
+
# se der algum erro, trata aqui
|
378
|
+
rescue Exception => e
|
379
|
+
return e.message
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
# faz uma requisicao com buyer key
|
384
|
+
def BuyerKey(buyer_key)
|
385
|
+
# try, tenta fazer o request
|
386
|
+
begin
|
387
|
+
|
388
|
+
# se for homologacao faz a chamada por aqui
|
389
|
+
if @serviceEnvironment == :staging
|
390
|
+
response = getRequest(@@SERVICE_URL_STAGING + '/CreditCard/' + buyer_key + '/BuyerKey')
|
391
|
+
|
392
|
+
# se for producao, faz a chamada por aqui
|
393
|
+
elsif @serviceEnvironment == :production
|
394
|
+
response = getRequest(@@SERVICE_URL_PRODUCTION + '/CreditCard/' + buyer_key + '/BuyerKey')
|
395
|
+
|
396
|
+
# se for sandbox, faz a chamada por aqui
|
397
|
+
elsif @serviceEnvironment == :sandbox
|
398
|
+
response = getRequest(@@SERVICE_URL_SANDBOX + '/CreditCard/' + buyer_key + '/BuyerKey')
|
399
|
+
end
|
400
|
+
|
401
|
+
# se der algum erro, trata aqui
|
402
|
+
rescue Exception => e
|
403
|
+
return e.message
|
404
|
+
end
|
405
|
+
|
406
|
+
# se nao houver erros, retorna o objeto
|
407
|
+
response
|
408
|
+
end
|
409
|
+
|
410
|
+
# funcao de post generica
|
411
|
+
def postRequest(payload, url)
|
412
|
+
response = nil
|
413
|
+
begin
|
414
|
+
response = RestClient.post(url, payload, headers=@@SERVICE_HEADERS)
|
415
|
+
rescue RestClient::ExceptionWithResponse => err
|
416
|
+
return err.response
|
417
|
+
end
|
418
|
+
json_response = JSON.load response
|
419
|
+
json_response
|
420
|
+
end
|
421
|
+
|
422
|
+
# funcao get generica
|
423
|
+
def getRequest(url)
|
424
|
+
response = nil
|
425
|
+
begin
|
426
|
+
response = RestClient.get(url, headers=@@SERVICE_HEADERS)
|
427
|
+
rescue RestClient::ExceptionWithResponse => err
|
428
|
+
return err.response
|
429
|
+
end
|
430
|
+
json_response = JSON.load response
|
431
|
+
json_response
|
432
|
+
end
|
433
|
+
|
434
|
+
def getReportFile(url)
|
435
|
+
begin
|
436
|
+
response = RestClient.get(url, headers={:MerchantKey => "#{@merchantKey}"})
|
437
|
+
rescue RestClient::ExceptionWithResponse => err
|
438
|
+
return err.response
|
439
|
+
end
|
440
|
+
return response
|
441
|
+
end
|
442
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class CreditCardData
|
2
|
+
# N�mero mascardo do cart�o de cr�dito
|
3
|
+
attr_accessor :MaskedCreditCardNumber
|
4
|
+
|
5
|
+
# Bandeira do cart�o de cr�dito
|
6
|
+
attr_accessor :CreditCardBrand
|
7
|
+
|
8
|
+
@@CreditCardBrandEnum = {
|
9
|
+
:Visa => '1',
|
10
|
+
:MasterCard => '2',
|
11
|
+
:HiperCard => '3',
|
12
|
+
:Amex => '4',
|
13
|
+
:Diners => '5',
|
14
|
+
:Elo => '6',
|
15
|
+
:Aura => '7',
|
16
|
+
:Discover => '8',
|
17
|
+
:CasaShow => '9',
|
18
|
+
:Havan => '10',
|
19
|
+
:HugCard => '11',
|
20
|
+
:AndarAki => '12',
|
21
|
+
:LeaderCard => '13',
|
22
|
+
:Submarino => '14'
|
23
|
+
}
|
24
|
+
|
25
|
+
# Chave do cart�o de cr�dito. Utilizada para identificar um cart�o de cr�dito no gateway
|
26
|
+
attr_accessor :InstantBuyerKey
|
27
|
+
|
28
|
+
# Informa se o cart�o de cr�dito expirou
|
29
|
+
attr_accessor :IsExpiredCreditCard
|
30
|
+
|
31
|
+
def initialize
|
32
|
+
@CreditCardBrand = self.CreditCardBrandEnum
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_json
|
36
|
+
hash = {}
|
37
|
+
instance_variables.each {|var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
|
38
|
+
hash
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class GetInstantBuyDataResponse
|
2
|
+
# Lista de cart�es de cr�dito
|
3
|
+
attr_accessor :CreditCardDataCollection
|
4
|
+
|
5
|
+
# Total de cart�es de cr�dito retornados
|
6
|
+
attr_accessor :CreditCardDataCount
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@CreditCardDataCollection = 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,18 @@
|
|
1
|
+
class OnlineDebitTransactionReportFile
|
2
|
+
attr_accessor :Order
|
3
|
+
attr_accessor :TransactionKey
|
4
|
+
attr_accessor :TransactionReference
|
5
|
+
attr_accessor :Bank
|
6
|
+
attr_accessor :Status
|
7
|
+
attr_accessor :AmountInCents
|
8
|
+
attr_accessor :AmountPaidInCents
|
9
|
+
attr_accessor :PaymentDate
|
10
|
+
attr_accessor :BankReturnCode
|
11
|
+
attr_accessor :BankPaymentDate
|
12
|
+
attr_accessor :Signature
|
13
|
+
attr_accessor :TransactionKeyToBank
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@Order = OrderTransactionReportFile.new
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class BoletoTransactionParser
|
2
|
+
def Parse(elements)
|
3
|
+
@@DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'
|
4
|
+
|
5
|
+
if elements.length < 18
|
6
|
+
throw('The expected parameter count is 18')
|
7
|
+
end
|
8
|
+
|
9
|
+
boleto_transaction = BoletoTransactionReportFile.new
|
10
|
+
boleto_transaction.Order.OrderKey = elements[1]
|
11
|
+
boleto_transaction.Order.OrderReference = elements[2]
|
12
|
+
boleto_transaction.Order.MerchantKey = elements[3]
|
13
|
+
boleto_transaction.Order.MerchantName = elements[4]
|
14
|
+
|
15
|
+
boleto_transaction.TransactionKey = elements[5]
|
16
|
+
boleto_transaction.TransactionReference = elements[6]
|
17
|
+
boleto_transaction.Status = elements[7]
|
18
|
+
boleto_transaction.NossoNumero = elements[8]
|
19
|
+
boleto_transaction.BankNumber = elements[9]
|
20
|
+
boleto_transaction.Agency = elements[10]
|
21
|
+
boleto_transaction.Account = elements[11]
|
22
|
+
boleto_transaction.BarCode = elements[12]
|
23
|
+
boleto_transaction.ExpirationDate = DateTime.strptime(elements[13],'%m/%d/%Y %H:%M:%S').strftime(@@DATETIME_FORMAT)
|
24
|
+
boleto_transaction.AmountInCents = elements[14].to_i
|
25
|
+
boleto_transaction.AmountPaidInCents = (elements[15].to_s == '') == false ? elements[15].to_i : 0
|
26
|
+
boleto_transaction.PaymentDate = (elements[16].to_s == '') == false ? DateTime.strptime(elements[16], '%m/%d/%Y %H:%M:%S').strftime(@@DATETIME_FORMAT) : nil
|
27
|
+
boleto_transaction.CreditDate = (elements[17].chomp.to_s == '') == false ? DateTime.strptime(elements[17], '%m/%d/%Y %H:%M:%S').strftime(@@DATETIME_FORMAT) : nil
|
28
|
+
|
29
|
+
return boleto_transaction
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class CreditCardTransactionParser
|
2
|
+
def Parse(elements)
|
3
|
+
@@DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'
|
4
|
+
|
5
|
+
if elements.length < 27
|
6
|
+
throw('The expected parameter count is 27')
|
7
|
+
end
|
8
|
+
|
9
|
+
credit_card_transaction = CreditCardTransactionReportFile.new
|
10
|
+
credit_card_transaction.Order.OrderKey = elements[1]
|
11
|
+
credit_card_transaction.Order.OrderReference = elements[2]
|
12
|
+
credit_card_transaction.Order.MerchantKey = elements[3]
|
13
|
+
credit_card_transaction.Order.MerchantName = elements[4]
|
14
|
+
|
15
|
+
credit_card_transaction.TransactionKey = elements[5]
|
16
|
+
credit_card_transaction.TransactionKeyToAcquirer = elements[6]
|
17
|
+
credit_card_transaction.CreditCardTransactionReference = elements[7]
|
18
|
+
credit_card_transaction.CreditCardBrand = elements[8]
|
19
|
+
credit_card_transaction.CreditCardNumber = elements[9]
|
20
|
+
credit_card_transaction.InstallmentCount = (elements[10].to_s == '') == false ? elements[10].to_i : 0
|
21
|
+
credit_card_transaction.AcquirerName = elements[11]
|
22
|
+
credit_card_transaction.Status = elements[12]
|
23
|
+
credit_card_transaction.AmountInCents = (elements[13].to_s == '') == false ? elements[13].to_i : 0
|
24
|
+
credit_card_transaction.IataAmountInCents = (elements[14].to_s == '') == false ? elements[14].to_i : 0
|
25
|
+
credit_card_transaction.AuthorizationCode = elements[15]
|
26
|
+
credit_card_transaction.TransactionIdentifier = elements[16]
|
27
|
+
credit_card_transaction.UniqueSequentialNumber = elements[17]
|
28
|
+
credit_card_transaction.AuthorizedAmountInCents = (elements[18].to_s == '') == false ? elements[18].to_i : 0
|
29
|
+
credit_card_transaction.CapturedAmountInCents = (elements[19].to_s == '') == false ? elements[19].to_i : 0
|
30
|
+
credit_card_transaction.VoidedAmountInCents = (elements[20].to_s == '') == false ? elements[20].to_i : 0
|
31
|
+
credit_card_transaction.RefundedAmountInCents = (elements[21].to_s == '') == false ? elements[21].to_i : 0
|
32
|
+
credit_card_transaction.AcquirerAuthorizationReturnCode = elements[22]
|
33
|
+
credit_card_transaction.AuthorizedDate = (elements[23].to_s == '') == false ? DateTime.strptime(elements[23], '%Y-%m-%dT%H:%M:%S').strftime(@@DATETIME_FORMAT) : nil
|
34
|
+
credit_card_transaction.CapturedDate = (elements[24].to_s == '') == false ? DateTime.strptime(elements[24], '%Y-%m-%dT%H:%M:%S').strftime(@@DATETIME_FORMAT) : nil
|
35
|
+
credit_card_transaction.VoidedDate = (elements[25].to_s == '') == false ? DateTime.strptime(elements[25], '%Y-%m-%dT%H:%M:%S').strftime(@@DATETIME_FORMAT) : nil
|
36
|
+
credit_card_transaction.LastProbeDate = (elements[26].chomp.to_s == '') == false ? DateTime.strptime(elements[26], '%Y-%m-%dT%H:%M:%S').strftime(@@DATETIME_FORMAT) : nil
|
37
|
+
|
38
|
+
return credit_card_transaction
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class HeaderParser
|
2
|
+
def Parse(elements)
|
3
|
+
if elements.length < 4
|
4
|
+
throw('The expected parameter count is 4')
|
5
|
+
end
|
6
|
+
|
7
|
+
header = Header.new
|
8
|
+
header.TransactionProcessedDate = Date.parse(elements[1]).strftime('%Y%m%d')
|
9
|
+
header.ReportFileCreateDate = Date.parse(elements[2]).strftime('%Y%m%d %H:%M:%S')
|
10
|
+
header.Version = elements[3].chomp
|
11
|
+
|
12
|
+
return header
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class OnlineDebitTransactionParser
|
2
|
+
def Parse(elements)
|
3
|
+
@@DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'
|
4
|
+
|
5
|
+
if elements.length < 16
|
6
|
+
throw('The expected parameter count is 16')
|
7
|
+
end
|
8
|
+
|
9
|
+
online_debit_transaction = OnlineDebitTransactionReportFile.new
|
10
|
+
|
11
|
+
online_debit_transaction.Order.OrderKey = elements[1]
|
12
|
+
online_debit_transaction.Order.OrderReference = elements[2]
|
13
|
+
online_debit_transaction.Order.MerchantKey = elements[3]
|
14
|
+
online_debit_transaction.Order.MerchantName = elements[4]
|
15
|
+
|
16
|
+
online_debit_transaction.TransactionKey = elements[5]
|
17
|
+
online_debit_transaction.TransactionReference = elements[6]
|
18
|
+
online_debit_transaction.Bank = elements[7]
|
19
|
+
online_debit_transaction.Status = elements[8]
|
20
|
+
online_debit_transaction.AmountInCents = elements[9].to_i
|
21
|
+
online_debit_transaction.AmountPaidInCents = (elements[10].to_s == '') == false ? elements[10].to_i : 0
|
22
|
+
online_debit_transaction.PaymentDate = (elements[11].to_s == '') == false ? DateTime.strptime(elements[11],'%m/%d/%Y %H:%M:%S').strftime(@@DATETIME_FORMAT) : nil
|
23
|
+
online_debit_transaction.BankReturnCode = elements[12]
|
24
|
+
online_debit_transaction.BankPaymentDate = elements[13]
|
25
|
+
online_debit_transaction.Signature = elements[14]
|
26
|
+
online_debit_transaction.TransactionKeyToBank = elements[15].chomp
|
27
|
+
|
28
|
+
return online_debit_transaction
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class TrailerParser
|
2
|
+
def Parse(elements)
|
3
|
+
if elements.length < 5
|
4
|
+
throw('The expected parameter count is 5')
|
5
|
+
end
|
6
|
+
|
7
|
+
trailer = Trailer.new
|
8
|
+
trailer.OrderDataCount = elements[1]
|
9
|
+
trailer.CreditCardTransactionDataCount = elements[2]
|
10
|
+
trailer.BoletoTransactionDataCount = elements[3]
|
11
|
+
trailer.OnlineDebitTransactionDataCount = elements[4].chomp
|
12
|
+
|
13
|
+
return trailer
|
14
|
+
end
|
15
|
+
end
|