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