stone_ecommerce 1.0.3 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/lib/gateway/Address/billing_address.rb +25 -23
  3. data/lib/gateway/Address/buyer_address.rb +28 -25
  4. data/lib/gateway/Address/delivery_address.rb +24 -22
  5. data/lib/gateway/BoletoTransaction/boleto_transaction.rb +28 -30
  6. data/lib/gateway/BoletoTransaction/boleto_transaction_options.rb +14 -11
  7. data/lib/gateway/BoletoTransaction/boleto_transaction_report_file.rb +20 -17
  8. data/lib/gateway/CreditCardTransaction/credit_card.rb +19 -18
  9. data/lib/gateway/CreditCardTransaction/credit_card_transaction.rb +21 -19
  10. data/lib/gateway/CreditCardTransaction/credit_card_transaction_options.rb +17 -15
  11. data/lib/gateway/CreditCardTransaction/credit_card_transaction_report_file.rb +29 -26
  12. data/lib/gateway/CreditCardTransaction/manage_credit_card_transaction.rb +11 -8
  13. data/lib/gateway/CreditCardTransaction/retry_sale_credit_card_transaction.rb +10 -8
  14. data/lib/gateway/Gateway.rb +514 -334
  15. data/lib/gateway/InstantBuyData/create_instant_buy_data_request.rb +31 -0
  16. data/lib/gateway/InstantBuyData/update_instant_buy_data_request.rb +11 -0
  17. data/lib/gateway/Merchant/merchant.rb +10 -8
  18. data/lib/gateway/OnlineDebit/online_debit_transaction_report_file.rb +19 -16
  19. data/lib/gateway/Order/order.rb +11 -8
  20. data/lib/gateway/Order/order_transaction_report_file.rb +8 -5
  21. data/lib/gateway/Parsers/boleto_transaction_parser.rb +28 -25
  22. data/lib/gateway/Parsers/credit_card_transaction_parser.rb +37 -34
  23. data/lib/gateway/Parsers/header_parser.rb +13 -10
  24. data/lib/gateway/Parsers/online_debit_transaction_parser.rb +26 -23
  25. data/lib/gateway/Parsers/trailer_parser.rb +13 -11
  26. data/lib/gateway/Person/buyer.rb +22 -22
  27. data/lib/gateway/Person/create_buyer_request.rb +23 -0
  28. data/lib/gateway/Person/person.rb +34 -32
  29. data/lib/gateway/Recurrency/recurrency.rb +18 -16
  30. data/lib/gateway/Sale/create_sale_request.rb +26 -24
  31. data/lib/gateway/Sale/manage_sale_request.rb +13 -11
  32. data/lib/gateway/Sale/query_sale_request.rb +27 -25
  33. data/lib/gateway/Sale/request_data.rb +16 -14
  34. data/lib/gateway/Sale/retry_sale_options.rb +12 -10
  35. data/lib/gateway/Sale/retry_sale_request.rb +15 -14
  36. data/lib/gateway/Sale/sale_data.rb +0 -2
  37. data/lib/gateway/Sale/sale_order_data.rb +14 -12
  38. data/lib/gateway/SalesOption.rb +13 -11
  39. data/lib/gateway/ShoppingCart/shopping_cart.rb +18 -16
  40. data/lib/gateway/ShoppingCart/shopping_cart_item.rb +15 -13
  41. data/lib/gateway/Trailer.rb +8 -5
  42. data/lib/gateway/header.rb +7 -4
  43. data/lib/gateway/post_notification.rb +23 -20
  44. data/lib/gateway/transaction_report_file.rb +43 -40
  45. data/lib/stone_ecommerce.rb +6 -14
  46. data/spec/integration/gateway_spec.rb +376 -85
  47. data/spec/spec_helper.rb +96 -96
  48. data/stone_ecommerce.gemspec +2 -2
  49. metadata +6 -20
  50. data/lib/gateway/AntiFraud/anti_fraud_analysis_result.rb +0 -47
  51. data/lib/gateway/AntiFraud/query_sale_anti_fraud_analysis_data.rb +0 -51
  52. data/lib/gateway/AntiFraud/query_sale_anti_fraud_analysis_history_data.rb +0 -41
  53. data/lib/gateway/BaseRequest.rb +0 -11
  54. data/lib/gateway/BaseResponse.rb +0 -17
  55. data/lib/gateway/BoletoTransaction/boleto_transaction_data.rb +0 -44
  56. data/lib/gateway/BoletoTransaction/boleto_transaction_result.rb +0 -35
  57. data/lib/gateway/CreditCardTransaction/credit_card_transaction_data.rb +0 -104
  58. data/lib/gateway/ErrorItem.rb +0 -17
  59. data/lib/gateway/ErrorReport.rb +0 -18
  60. data/lib/gateway/InstantBuy/credit_card_data.rb +0 -41
  61. data/lib/gateway/InstantBuy/get_instant_buy_data_response.rb +0 -18
  62. data/lib/gateway/Sale/create_sale_response.rb +0 -25
  63. data/lib/gateway/Sale/manage_sale_response.rb +0 -15
  64. data/lib/gateway/Sale/query_sale_response.rb +0 -18
  65. data/lib/gateway/Sale/retry_sale_response.rb +0 -14
  66. data/lib/gateway/address.rb +0 -25
@@ -1,29 +1,32 @@
1
- class CreditCardTransactionReportFile
2
- attr_accessor :Order
3
- attr_accessor :TransactionKey
4
- attr_accessor :TransactionKeyToAcquirer
5
- attr_accessor :CreditCardTransactionReference
6
- attr_accessor :CreditCardBrand
7
- attr_accessor :CreditCardNumber
8
- attr_accessor :InstallmentCount
9
- attr_accessor :AcquirerName
10
- attr_accessor :Status
11
- attr_accessor :AmountInCents
12
- attr_accessor :IataAmountInCents
13
- attr_accessor :AuthorizationCode
14
- attr_accessor :TransactionIdentifier
15
- attr_accessor :UniqueSequentialNumber
16
- attr_accessor :AuthorizedAmountInCents
17
- attr_accessor :CapturedAmountInCents
18
- attr_accessor :VoidedAmountInCents
19
- attr_accessor :RefundedAmountInCents
20
- attr_accessor :AcquirerAuthorizationReturnCode
21
- attr_accessor :AuthorizedDate
22
- attr_accessor :CapturedDate
23
- attr_accessor :VoidedDate
24
- attr_accessor :LastProbeDate
1
+ module Gateway
25
2
 
26
- def initialize
27
- @Order = OrderTransactionReportFile.new
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
28
31
  end
29
32
  end
@@ -1,12 +1,15 @@
1
+ module Gateway
2
+
1
3
  # classe para usar nos metodos de cancel e capture
2
- class ManageCreditCardTransaction
3
- attr_accessor :AmountInCents
4
- attr_accessor :TransactionKey
5
- attr_accessor :TransactionReference
4
+ class ManageCreditCardTransaction
5
+ attr_accessor :AmountInCents
6
+ attr_accessor :TransactionKey
7
+ attr_accessor :TransactionReference
6
8
 
7
- def to_json
8
- hash = {}
9
- instance_variables.each {|var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
10
- hash
9
+ def to_json
10
+ hash = {}
11
+ instance_variables.each { |var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
12
+ hash
13
+ end
11
14
  end
12
15
  end
@@ -1,13 +1,15 @@
1
- class RetrySaleCreditCardTransaction
1
+ module Gateway
2
2
 
3
- attr_accessor :TransactionKey
3
+ class RetrySaleCreditCardTransaction
4
4
 
5
- attr_accessor :SecurityCode
5
+ attr_accessor :TransactionKey
6
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
7
+ attr_accessor :SecurityCode
12
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
13
15
  end
@@ -1,441 +1,621 @@
1
1
  require_relative '../../lib/stone_ecommerce'
2
+ module Gateway
2
3
 
3
- class Gateway
4
+ class Gateway
5
+ extend Gem::Deprecate
4
6
 
5
- attr_reader :serviceEnvironment
7
+ attr_reader :serviceEnvironment
6
8
 
7
- attr_reader :merchantKey
9
+ attr_reader :merchantKey
8
10
 
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
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
14
16
 
15
- # URL de producao
16
- @@SERVICE_URL_PRODUCTION = 'https://transaction.stone.com.br'
17
+ # URL de producao
18
+ @@SERVICE_URL_PRODUCTION = 'https://transaction.stone.com.br'
17
19
 
18
- # URL de homologacao
19
- @@SERVICE_URL_STAGING = ''
20
+ # URL de homologacao
21
+ @@SERVICE_URL_STAGING = ''
20
22
 
21
- # URL de sandbox
22
- @@SERVICE_URL_SANDBOX = ''
23
+ # URL de sandbox
24
+ @@SERVICE_URL_SANDBOX = 'https://transaction.stone.com.br'
23
25
 
24
- # URL do postnotification de producao
25
- @@SERVICE_URL_NOTIFICATION_PRODUCTION = ''
26
+ # URL do postnotification de producao
27
+ @@SERVICE_URL_NOTIFICATION_PRODUCTION = ''
26
28
 
27
- # URL do postnotification de sandbox
28
- @@SERVICE_URL_NOTIFICATION_SANDBOX = ''
29
+ # URL do postnotification de sandbox
30
+ @@SERVICE_URL_NOTIFICATION_SANDBOX = ''
29
31
 
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)
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)
37
39
 
38
- # se for producao, faz a chamada por aqui
39
- elsif @serviceEnvironment == :production
40
- getRequest(@@SERVICE_URL_PRODUCTION + '/Sale/Query/' + querySaleRequestEnum + '=' + key)
40
+ # se for producao, faz a chamada por aqui
41
+ elsif @serviceEnvironment == :production
42
+ getRequest(@@SERVICE_URL_PRODUCTION + '/Sale/Query/' + querySaleRequestEnum + '=' + key)
41
43
 
42
- # se for sandbox
43
- elsif @serviceEnvironment == :sandbox
44
- getRequest(@@SERVICE_URL_SANDBOX + '/Sale/Query/' + querySaleRequestEnum + '=' + key)
45
- end
44
+ # se for sandbox
45
+ elsif @serviceEnvironment == :sandbox
46
+ getRequest(@@SERVICE_URL_SANDBOX + '/Sale/Query/' + querySaleRequestEnum + '=' + key)
47
+ end
46
48
 
47
- # se der algum erro, trata aqui
48
- rescue Exception => e
49
- return e.message
49
+ # se der algum erro, trata aqui
50
+ rescue Exception => e
51
+ return e.message
52
+ end
50
53
  end
51
- end
52
54
 
53
- # criar uma transacao na plataforma One utilizando um ou mais meios de pagamento
54
- def CreateSale(createSaleRequest)
55
+ # criar uma transacao na plataforma One utilizando um ou mais meios de pagamento
56
+ def CreateSale(createSaleRequest)
55
57
 
56
- saleHash = createSaleRequest.to_json
58
+ saleHash = createSaleRequest.to_json
57
59
 
58
- saleHash['BoletoTransactionCollection'] = []
60
+ saleHash['BoletoTransactionCollection'] = []
59
61
 
60
- saleHash['CreditCardTransactionCollection'] = []
62
+ saleHash['CreditCardTransactionCollection'] = []
61
63
 
62
- saleHash['ShoppingCartCollection'] = []
64
+ saleHash['ShoppingCartCollection'] = []
63
65
 
64
- begin
65
- # transforma a colecao de boleto em json
66
- if createSaleRequest.BoletoTransactionCollection.any? == false || createSaleRequest.BoletoTransactionCollection.nil?
67
- saleHash['BoletoTransactionCollection'] = nil
66
+ begin
67
+ # transforma a colecao de boleto em json
68
+ if createSaleRequest.BoletoTransactionCollection.any? == false || createSaleRequest.BoletoTransactionCollection.nil?
69
+ saleHash['BoletoTransactionCollection'] = nil
68
70
 
69
- else
70
- createSaleRequest.BoletoTransactionCollection.each_with_index do |boleto, index|
71
- b = boleto.to_json
72
- saleHash['BoletoTransactionCollection'] << b
71
+ else
72
+ createSaleRequest.BoletoTransactionCollection.each_with_index do |boleto, index|
73
+ b = boleto.to_json
74
+ saleHash['BoletoTransactionCollection'] << b
73
75
 
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
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
80
82
 
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
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
86
89
  end
87
90
  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
91
 
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
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
111
99
 
112
- if creditCard.CreditCard.to_json.any?
113
- credit_card_item = creditCard.CreditCard.to_json
114
- saleHash['CreditCardTransactionCollection'][index]['CreditCard'] = credit_card_item
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
115
106
 
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
107
+ if creditCard.Recurrency.to_json.any?
108
+ credit_card_recurrency = creditCard.Recurrency.to_json
109
+ saleHash['CreditCardTransactionCollection'][index]['Recurrency'] = credit_card_recurrency
119
110
  else
120
- saleHash['CreditCardTransactionCollection'][index]['CreditCard']['BillingAddress'] = nil
111
+ saleHash['CreditCardTransactionCollection'][index]['Recurrency'] = nil
121
112
  end
122
113
 
123
- else
124
- saleHash['CreditCardTransactionCollection'][index]['CreditCard'] = nil
125
- end
126
- end
127
- end
114
+ if creditCard.CreditCard.to_json.any?
115
+ credit_card_item = creditCard.CreditCard.to_json
116
+ saleHash['CreditCardTransactionCollection'][index]['CreditCard'] = credit_card_item
128
117
 
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
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
143
124
 
144
- if shoppingCart.ShoppingCartItemCollection.any?
145
- shoppingCart.ShoppingCartItemCollection.each_with_index do |cartItem, cartIndex|
146
- item = cartItem.to_json
147
- saleHash['ShoppingCartCollection'][index]['ShoppingCartItemCollection'][cartIndex] = item
125
+ else
126
+ saleHash['CreditCardTransactionCollection'][index]['CreditCard'] = nil
148
127
  end
149
- else
150
- saleHash['ShoppingCartCollection'][index]['ShoppingCartItemCollection'] = nil
151
128
  end
152
129
  end
153
- end
154
130
 
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
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
162
138
 
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
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
170
145
 
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
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
178
156
 
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
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
186
172
 
187
- # transforma o objeto Buyer em json
188
- if createSaleRequest.Buyer.AddressCollection.any?
189
- b = createSaleRequest.Buyer.to_json
190
- saleHash['Buyer'] = b
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
191
180
 
192
- saleHash['Buyer']['AddressCollection'] = []
193
- createSaleRequest.Buyer.AddressCollection.each do |address|
194
- a = address.to_json
195
- saleHash['Buyer']['AddressCollection'] << a
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
196
187
  end
197
- else
198
- buyer_hash = createSaleRequest.Buyer.to_json
199
- buyer_hash.delete('AddressCollection')
200
- if buyer_hash.blank? == false
188
+
189
+ # transforma o objeto Buyer em json
190
+ if createSaleRequest.Buyer.AddressCollection.any?
201
191
  b = createSaleRequest.Buyer.to_json
202
192
  saleHash['Buyer'] = b
203
- saleHash['Buyer']['AddressCollection'] = nil
193
+
194
+ saleHash['Buyer']['AddressCollection'] = []
195
+ createSaleRequest.Buyer.AddressCollection.each do |address|
196
+ a = address.to_json
197
+ saleHash['Buyer']['AddressCollection'] << a
198
+ end
204
199
  else
205
- saleHash['Buyer'] = nil
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
206
209
  end
210
+
211
+ rescue Exception => e
212
+ return e.message
207
213
  end
208
214
 
209
- rescue Exception => e
210
- return e.message
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)
211
223
  end
212
224
 
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/'
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)
219
254
  end
220
- postRequest(saleHash.to_json, url)
221
- end
222
255
 
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'] = []
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'] = []
227
260
 
228
- begin
229
- if retrySaleRequest.RetrySaleCreditCardTransactionCollection != nil
230
- retrySaleRequest.RetrySaleCreditCardTransactionCollection.each do |retrySale|
231
- r = retrySale.to_json
232
- saleHash['RetrySaleCreditCardTransactionCollection'] << r
261
+ begin
262
+ if cancelSaleRequest.CreditCardTransactionCollection != nil
263
+ cancelSaleRequest.CreditCardTransactionCollection.each do |creditCard|
264
+ c = creditCard.to_json
265
+ saleHash['CreditCardTransactionCollection'] << c
266
+ end
233
267
  end
268
+ rescue Exception => e
269
+ return e.message
234
270
  end
235
- if retrySaleRequest.Options.to_json.any?
236
- retry_options = retrySaleRequest.Options.to_json
237
- saleHash['Options'] = retry_options
238
- else
239
- saleHash['Options'] = nil
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'
240
277
  end
241
- rescue Exception => e
242
- return e.message
243
- end
244
- if @serviceEnvironment == :staging
245
- url = @@SERVICE_URL_STAGING + '/Sale/Retry'
246
- elsif @serviceEnvironment == :production
247
- url = @@SERVICE_URL_PRODUCTION + '/Sale/Retry'
248
- elsif @serviceEnvironment == :sandbox
249
- url = @@SERVICE_URL_SANDBOX + '/Sale/Retry'
278
+ postRequest(saleHash.to_json, url)
250
279
  end
251
- postRequest(saleHash.to_json, url)
252
- end
253
280
 
254
- # eh uma forma de desfazer uma transação com cartao de credito mesmo a transacao sendo capturada
255
- def Cancel(cancelSaleRequest)
256
- saleHash = cancelSaleRequest.to_json
257
- saleHash['CreditCardTransactionCollection'] = []
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'] = []
258
285
 
259
- begin
260
- if cancelSaleRequest.CreditCardTransactionCollection != nil
261
- cancelSaleRequest.CreditCardTransactionCollection.each do |creditCard|
262
- c = creditCard.to_json
263
- saleHash['CreditCardTransactionCollection'] << c
286
+ begin
287
+ if captureRequest.CreditCardTransactionCollection != nil
288
+ captureRequest.CreditCardTransactionCollection.each do |creditCard|
289
+ c = creditCard.to_json
290
+ saleHash['CreditCardTransactionCollection'] << c
291
+ end
264
292
  end
293
+ rescue Exception => e
294
+ return e.message
265
295
  end
266
- rescue Exception => e
267
- return e.message
268
- end
269
- if @serviceEnvironment == :staging
270
- url = @@SERVICE_URL_STAGING + '/Sale/Cancel'
271
- elsif @serviceEnvironment == :production
272
- url = @@SERVICE_URL_PRODUCTION + '/Sale/Cancel'
273
- elsif @serviceEnvironment == :sandbox
274
- url = @@SERVICE_URL_SANDBOX + '/Sale/Cancel'
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)
275
304
  end
276
- postRequest(saleHash.to_json, url)
277
- end
278
305
 
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'] = []
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
283
316
 
284
- begin
285
- if captureRequest.CreditCardTransactionCollection != nil
286
- captureRequest.CreditCardTransactionCollection.each do |creditCard|
287
- c = creditCard.to_json
288
- saleHash['CreditCardTransactionCollection'] << c
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")
289
326
  end
327
+
328
+ response = getReportFile(url)
329
+
330
+ rescue RestClient::ExceptionWithResponse => err
331
+ return err.response
290
332
  end
291
- rescue Exception => e
292
- return e.message
333
+ return response
293
334
  end
294
- if @serviceEnvironment == :staging
295
- url = @@SERVICE_URL_STAGING + '/Sale/Capture'
296
- elsif @serviceEnvironment == :production
297
- url = @@SERVICE_URL_PRODUCTION + '/Sale/Capture'
298
- elsif @serviceEnvironment == :sandbox
299
- url = @@SERVICE_URL_SANDBOX + '/Sale/Capture'
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
300
347
  end
301
- postRequest(saleHash.to_json, url)
302
- end
303
348
 
304
- # faz um parse do xml de post notificaton
305
- def ParseXmlToNotification(xml)
306
- begin
307
- response = PostNotification.ParseNotification(xml)
308
- rescue Exception => err
309
- return err.message
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
310
358
  end
311
359
 
312
- return response
313
- end
360
+ # DEPRECATED
361
+ def InstantBuyKey(instant_buy_key)
362
+ GetCreditCard(instant_buy_key)
363
+ end
364
+ deprecate :InstantBuyKey, :GetCreditCard, 2016, 04
314
365
 
315
- # faz uma requisicao e retorna uma string com o transaction report file
316
- def TransactionReportFile(date)
317
- begin
318
- if @serviceEnvironment == :staging
319
- url = @@SERVICE_URL_NOTIFICATION_PRODUCTION + date.strftime("%Y%m%d")
320
- elsif @serviceEnvironment == :production
321
- url = @@SERVICE_URL_NOTIFICATION_PRODUCTION + date.strftime("%Y%m%d")
322
- elsif @serviceEnvironment == :sandbox
323
- url = @@SERVICE_URL_NOTIFICATION_SANDBOX + date.strftime("%Y%m%d")
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
324
393
  end
325
394
 
326
- response = getReportFile(url)
395
+ # se nao houver erros, retorna o objeto
396
+ response
397
+ end
327
398
 
328
- rescue RestClient::ExceptionWithResponse => err
329
- return err.response
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
330
420
  end
331
- return response
332
- end
333
421
 
334
- # faz o download do transaction report file e salva no computador em .txt
335
- def TransactionReportFileDownloader(date, file_name, path)
336
- begin
337
- path = path + file_name + '.txt'
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/'
338
439
 
339
- response = TransactionReportFile(date)
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)
340
446
 
341
- File.write(path, response)
342
- rescue RestClient::ExceptionWithResponse => err
343
- return err.response
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
344
480
  end
345
- end
346
481
 
347
- # faz o parse da string recebida do transaction report file e retorna um hash
348
- def TransactionReportFileParser(file_to_parse)
349
- transaction_report_file = TransactionReportFile.new
350
- begin
351
- response = transaction_report_file.TransactionReportFileParser(file_to_parse)
352
- rescue Exception => err
353
- return err
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
354
503
  end
355
- return response
356
- end
357
504
 
358
- # faz uma requisicao com instant buy key
359
- def InstantBuyKey(instant_buy_key)
360
- # try, tenta fazer o request
361
- begin
505
+ # Busca um buyer
506
+ def GetBuyer(buyer_key)
507
+ # try, tenta fazer o request
508
+ begin
362
509
 
363
- # se for homologacao faz a chamada por aqui
364
- if @serviceEnvironment == :staging
365
- getRequest(@@SERVICE_URL_STAGING + '/CreditCard/' + instant_buy_key)
510
+ # se for homologacao faz a chamada por aqui
511
+ if @serviceEnvironment == :staging
512
+ response = getRequest(@@SERVICE_URL_STAGING + '/Buyer/' + buyer_key)
366
513
 
367
- # se for producao, faz a chamada por aqui
368
- elsif @serviceEnvironment == :production
369
- getRequest(@@SERVICE_URL_PRODUCTION + '/CreditCard/' + instant_buy_key)
514
+ # se for producao, faz a chamada por aqui
515
+ elsif @serviceEnvironment == :production
516
+ response = getRequest(@@SERVICE_URL_PRODUCTION + '/Buyer/' + buyer_key)
370
517
 
371
- # se for sandbox
372
- elsif @serviceEnvironment == :sandbox
373
- getRequest(@@SERVICE_URL_SANDBOX + '/CreditCard/' + instant_buy_key)
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
374
526
  end
375
527
 
376
- # se der algum erro, trata aqui
377
- rescue Exception => e
378
- return e.message
528
+ # se nao houver erros, retorna o objeto
529
+ response
379
530
  end
380
- end
381
531
 
382
- # faz uma requisicao com buyer key
383
- def BuyerKey(buyer_key)
384
- # try, tenta fazer o request
385
- begin
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/'
386
549
 
387
- # se for homologacao faz a chamada por aqui
388
- if @serviceEnvironment == :staging
389
- response = getRequest(@@SERVICE_URL_STAGING + '/CreditCard/' + buyer_key + '/BuyerKey')
550
+ # se for producao, faz a chamada por aqui
551
+ elsif @serviceEnvironment == :production
552
+ url = @@SERVICE_URL_PRODUCTION + '/Buyer/'
390
553
 
391
- # se for producao, faz a chamada por aqui
392
- elsif @serviceEnvironment == :production
393
- response = getRequest(@@SERVICE_URL_PRODUCTION + '/CreditCard/' + buyer_key + '/BuyerKey')
554
+ # se for sandbox, faz a chamada por aqui
555
+ elsif @serviceEnvironment == :sandbox
556
+ url = @@SERVICE_URL_SANDBOX + '/Buyer/'
557
+ end
394
558
 
395
- # se for sandbox, faz a chamada por aqui
396
- elsif @serviceEnvironment == :sandbox
397
- response = getRequest(@@SERVICE_URL_SANDBOX + '/CreditCard/' + buyer_key + '/BuyerKey')
559
+ response = postRequest(sale_hash.to_json, url)
560
+ rescue Exception => e
561
+ return e.message
398
562
  end
563
+ response
564
+ end
399
565
 
400
- # se der algum erro, trata aqui
401
- rescue Exception => e
402
- return e.message
566
+ # funcao de post generica
567
+ def postRequest(payload, url)
568
+ response = nil
569
+ begin
570
+ response = RestClient.post(url, payload, headers=@@SERVICE_HEADERS)
571
+ rescue RestClient::ExceptionWithResponse => err
572
+ return err.response
573
+ end
574
+ json_response = JSON.load response
575
+ json_response
403
576
  end
404
577
 
405
- # se nao houver erros, retorna o objeto
406
- response
407
- end
578
+ # funcao patch generica
579
+ def patchRequest(payload, url)
580
+ begin
581
+ response = RestClient.patch(url, payload, headers=@@SERVICE_HEADERS)
582
+ rescue RestClient::ExceptionWithResponse => err
583
+ return err.response
584
+ end
585
+ json_response = JSON.load response
586
+ json_response
587
+ end
408
588
 
409
- # funcao de post generica
410
- def postRequest(payload, url)
411
- response = nil
412
- begin
413
- response = RestClient.post(url, payload, headers=@@SERVICE_HEADERS)
414
- rescue RestClient::ExceptionWithResponse => err
415
- return err.response
589
+ # funcao de delete generica
590
+ def deleteRequest(url)
591
+ begin
592
+ response = RestClient.delete(url, headers=@@SERVICE_HEADERS)
593
+ rescue RestClient::ExceptionWithResponse => err
594
+ return err.response
595
+ end
596
+ json_response = JSON.load response
597
+ json_response
416
598
  end
417
- json_response = JSON.load response
418
- json_response
419
- end
420
599
 
421
- # funcao get generica
422
- def getRequest(url)
423
- response = nil
424
- begin
425
- response = RestClient.get(url, headers=@@SERVICE_HEADERS)
426
- rescue RestClient::ExceptionWithResponse => err
427
- return err.response
600
+ # funcao get generica
601
+ def getRequest(url)
602
+ response = nil
603
+ begin
604
+ response = RestClient.get(url, headers=@@SERVICE_HEADERS)
605
+ rescue RestClient::ExceptionWithResponse => err
606
+ return err.response
607
+ end
608
+ json_response = JSON.load response
609
+ json_response
428
610
  end
429
- json_response = JSON.load response
430
- json_response
431
- end
432
611
 
433
- def getReportFile(url)
434
- begin
435
- response = RestClient.get(url, headers={:MerchantKey => "#{@merchantKey}"})
436
- rescue RestClient::ExceptionWithResponse => err
437
- return err.response
612
+ def getReportFile(url)
613
+ begin
614
+ response = RestClient.get(url, headers={:MerchantKey => "#{@merchantKey}"})
615
+ rescue RestClient::ExceptionWithResponse => err
616
+ return err.response
617
+ end
618
+ return response
438
619
  end
439
- return response
440
620
  end
441
621
  end