mundipagg 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +191 -191
- data/README.md +118 -118
- data/lib/mundipagg.rb +13 -13
- data/lib/mundipagg/BoletoTransaction.rb +30 -30
- data/lib/mundipagg/Buyer.rb +81 -81
- data/lib/mundipagg/BuyerAddress.rb +68 -68
- data/lib/mundipagg/CreateOrderRequest.rb +66 -66
- data/lib/mundipagg/CreditCardTransaction.rb +81 -81
- data/lib/mundipagg/ManageOrderRequest.rb +51 -51
- data/lib/mundipagg/QueryOrderRequest.rb +28 -27
- data/lib/mundipagg/Recurrency.rb +38 -38
- data/lib/mundipagg/ShoppingCart.rb +15 -15
- data/lib/mundipagg/ShoppingCartItem.rb +23 -23
- data/lib/mundipagg/gateway.rb +401 -401
- data/lib/mundipagg/post_notification.rb +30 -30
- data/lib/mundipagg/version.rb +9 -9
- data/mundipagg.gemspec +18 -18
- data/tests/features/boleto.feature +9 -9
- data/tests/features/credit_card.feature +43 -43
- data/tests/features/post_notification.feature +9 -9
- data/tests/features/step_definitions/boleto_steps.rb +50 -50
- data/tests/features/step_definitions/credit_card_steps.rb +167 -167
- data/tests/features/step_definitions/post_notification.rb +92 -92
- data/tests/features/support/env.rb +6 -6
- data/tests/test_configuration.rb +5 -5
- data/tests/test_helper.rb +68 -68
- metadata +14 -18
data/lib/mundipagg/gateway.rb
CHANGED
@@ -1,401 +1,401 @@
|
|
1
|
-
module Mundipagg
|
2
|
-
# Class that handles all webservice calls
|
3
|
-
class Gateway
|
4
|
-
|
5
|
-
# Sets the soap request log level.
|
6
|
-
# Can be: { :debug, :info, :warn, :error or :none }
|
7
|
-
# Use :debug only to inspect the Xml sent and received to the service.
|
8
|
-
# Default in test environment => :debug
|
9
|
-
# Default in production environment => :none
|
10
|
-
attr_accessor :log_level
|
11
|
-
|
12
|
-
# @return [Nori] Nori class who handle the conversion of base XML to a hash collection
|
13
|
-
# @see https://github.com/savonrb/nori
|
14
|
-
attr_reader :parser
|
15
|
-
|
16
|
-
# <i>:test</i> = Simulator enviroment, fake transaction approval;
|
17
|
-
# <i>:production</i> = Real transaction, needs real credit card.
|
18
|
-
# @return [Symbol] Webservice environment.
|
19
|
-
attr_accessor :environment
|
20
|
-
|
21
|
-
# @return [String] URL that points to the simulator WSDL
|
22
|
-
@@WEBSERVICE_TEST_URL = 'https://
|
23
|
-
|
24
|
-
# @return [String] URL that points to the production WSDL
|
25
|
-
@@WEBSERVICE_PRODUCTION_URL = 'https://transaction.mundipaggone.com/MundiPaggService.svc?wsdl'
|
26
|
-
|
27
|
-
# Initialize a class with an environment
|
28
|
-
#
|
29
|
-
# @param environment [Symbol] Sets the MundiPagg environment will be used by the client.
|
30
|
-
def initialize(environment=:test)
|
31
|
-
@parser = Nori.new(:convert_tags_to => lambda { |tag| tag })
|
32
|
-
@environment = environment
|
33
|
-
|
34
|
-
if environment == :test
|
35
|
-
@log_level = :debug
|
36
|
-
else
|
37
|
-
@log_level = :error
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
# This method makes requests to the webservice method ManageOrder.
|
44
|
-
#
|
45
|
-
# @param request [CreateOrderRequest] A ManagerOrderRequest instance containing information to capture or void a transaction or order.
|
46
|
-
# @return [Hash<Symbol, Object>] A hash collection containing the response data
|
47
|
-
def ManageOrder(request)
|
48
|
-
|
49
|
-
hash = @parser.parse('<tns:manageOrderRequest>
|
50
|
-
<mun:ManageCreditCardTransactionCollection>
|
51
|
-
</mun:ManageCreditCardTransactionCollection>
|
52
|
-
<mun:ManageOrderOperationEnum>?</mun:ManageOrderOperationEnum>
|
53
|
-
<mun:MerchantKey>?</mun:MerchantKey>
|
54
|
-
<mun:OrderKey>?</mun:OrderKey>
|
55
|
-
<mun:OrderReference>?</mun:OrderReference>
|
56
|
-
<mun:RequestKey>?</mun:RequestKey>
|
57
|
-
</tns:manageOrderRequest>')
|
58
|
-
|
59
|
-
xml_hash = hash['tns:manageOrderRequest'];
|
60
|
-
|
61
|
-
xml_hash['mun:ManageCreditCardTransactionCollection'] = {'mun:ManageCreditCardTransactionRequest'=>Array.new}
|
62
|
-
|
63
|
-
if request.transactionCollection.nil? == false and request.transactionCollection.count > 0
|
64
|
-
|
65
|
-
request.transactionCollection.each do |transaction|
|
66
|
-
|
67
|
-
xml_hash['mun:ManageCreditCardTransactionCollection']['mun:ManageCreditCardTransactionRequest'] << {
|
68
|
-
'mun:AmountInCents' => transaction.amountInCents,
|
69
|
-
'mun:TransactionKey' => transaction.transactionKey,
|
70
|
-
'mun:TransactionReference' => transaction.transactionReference
|
71
|
-
}
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
xml_hash['mun:ManageOrderOperationEnum'] = request.manageOrderOperationEnum
|
76
|
-
xml_hash['mun:MerchantKey'] = request.merchantKey
|
77
|
-
xml_hash['mun:OrderKey'] = request.orderKey
|
78
|
-
xml_hash['mun:OrderReference'] = request.orderReference
|
79
|
-
xml_hash['mun:RequestKey'] = request.requestKey
|
80
|
-
|
81
|
-
response = SendToService(hash, :manage_order)
|
82
|
-
|
83
|
-
return response
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
# This method makes requests to the webservice method QueryOrder.
|
88
|
-
#
|
89
|
-
# @param request [QueryOrderRequest] A QueryOrderRequest instance containing information to request more information about an order or transaction.
|
90
|
-
# @return [Hash<Symbol, Object>]
|
91
|
-
def QueryOrder(request)
|
92
|
-
|
93
|
-
hash = @parser.parse('<tns:queryOrderRequest>
|
94
|
-
<mun:MerchantKey>?</mun:MerchantKey>
|
95
|
-
<mun:OrderKey>?</mun:OrderKey>
|
96
|
-
<mun:OrderReference>?</mun:OrderReference>
|
97
|
-
<mun:RequestKey>?</mun:RequestKey>
|
98
|
-
</tns:queryOrderRequest>')
|
99
|
-
|
100
|
-
xml_hash = hash['tns:queryOrderRequest'];
|
101
|
-
|
102
|
-
xml_hash['mun:MerchantKey'] = request.merchantKey
|
103
|
-
xml_hash['mun:OrderKey'] = request.orderKey
|
104
|
-
xml_hash['mun:OrderReference'] = request.orderReference
|
105
|
-
xml_hash['mun:RequestKey'] = request.requestKey
|
106
|
-
|
107
|
-
response = SendToService(hash, :query_order)
|
108
|
-
|
109
|
-
return response
|
110
|
-
end
|
111
|
-
|
112
|
-
# This method makes requests to the webservice method CreateOrder.
|
113
|
-
#
|
114
|
-
# @param request [CreateOrderRequest] A CreateOrderRequest instance containing information to create a order.
|
115
|
-
# @return [Hash<Symbol, Object>] A hash collection containing the response data
|
116
|
-
def CreateOrder(request)
|
117
|
-
|
118
|
-
hash = @parser.parse('
|
119
|
-
<tns:createOrderRequest>
|
120
|
-
<mun:AmountInCents>?</mun:AmountInCents>
|
121
|
-
<mun:AmountInCentsToConsiderPaid>?</mun:AmountInCentsToConsiderPaid>
|
122
|
-
<mun:CurrencyIsoEnum>?</mun:CurrencyIsoEnum>
|
123
|
-
<mun:MerchantKey>?</mun:MerchantKey>
|
124
|
-
<mun:OrderReference>?</mun:OrderReference>
|
125
|
-
<mun:RequestKey>?</mun:RequestKey>
|
126
|
-
<mun:Buyer>
|
127
|
-
</mun:Buyer>
|
128
|
-
<mun:ShoppingCartCollection>
|
129
|
-
</mun:ShoppingCartCollection>
|
130
|
-
<mun:CreditCardTransactionCollection>
|
131
|
-
</mun:CreditCardTransactionCollection>
|
132
|
-
<mun:BoletoTransactionCollection>
|
133
|
-
</mun:BoletoTransactionCollection>
|
134
|
-
</tns:createOrderRequest>')
|
135
|
-
|
136
|
-
xml_hash = hash['tns:createOrderRequest'];
|
137
|
-
|
138
|
-
xml_hash['mun:AmountInCents'] = request.amountInCents
|
139
|
-
|
140
|
-
if request.amountInCentsToConsiderPaid == nil
|
141
|
-
xml_hash['mun:AmountInCentsToConsiderPaid'] = request.amountInCents
|
142
|
-
else
|
143
|
-
xml_hash['mun:AmountInCentsToConsiderPaid'] = request.amountInCentsToConsiderPaid
|
144
|
-
end
|
145
|
-
|
146
|
-
xml_hash['mun:CurrencyIsoEnum'] = request.currencyIsoEnum
|
147
|
-
xml_hash['mun:MerchantKey'] = request.merchantKey
|
148
|
-
xml_hash['mun:OrderReference'] = request.orderReference
|
149
|
-
xml_hash['mun:RequestKey'] = request.requestKey
|
150
|
-
|
151
|
-
if request.buyer.nil? == false
|
152
|
-
xml_hash['mun:Buyer'] = CreateBuyer(request)
|
153
|
-
end
|
154
|
-
|
155
|
-
if not request.shoppingCartCollection.nil? and request.shoppingCartCollection.count > 0
|
156
|
-
xml_hash['mun:ShoppingCartCollection'] = CreateShoppingCart(request)
|
157
|
-
end
|
158
|
-
|
159
|
-
if not request.creditCardTransactionCollection.nil? and request.creditCardTransactionCollection.count > 0
|
160
|
-
#Create credit card transaction array and assing to the contract hash
|
161
|
-
creditCardTransactionCollection = CreateCreditCardTransaction(request)
|
162
|
-
xml_hash['mun:CreditCardTransactionCollection'] = creditCardTransactionCollection
|
163
|
-
else
|
164
|
-
xml_hash['mun:CreditCardTransactionCollection'] = nil
|
165
|
-
end
|
166
|
-
|
167
|
-
if request.boletoTransactionCollection.nil? == false and request.boletoTransactionCollection.count > 0
|
168
|
-
#Create boleto transaction array and assing to the contract hash
|
169
|
-
boletoTransactionCollection = CreateBoletoTransactionRequest(request);
|
170
|
-
xml_hash['mun:BoletoTransactionCollection'] = boletoTransactionCollection
|
171
|
-
end
|
172
|
-
|
173
|
-
response = SendToService(hash, :create_order)
|
174
|
-
|
175
|
-
|
176
|
-
return response
|
177
|
-
|
178
|
-
end
|
179
|
-
|
180
|
-
|
181
|
-
# This method create a hash collection with all buyer information.
|
182
|
-
# The hash collection is a part of the data send to the webservice.
|
183
|
-
#
|
184
|
-
# @param request [CreateOrderRequest]
|
185
|
-
# @return [Hash<Symbol, Object>] Hash collection with buyer information.
|
186
|
-
# @!visibility private
|
187
|
-
def CreateBuyer(request)
|
188
|
-
|
189
|
-
buyer = {
|
190
|
-
'mun:BuyerKey' => request.buyer.buyerKey,
|
191
|
-
'mun:BuyerReference' => request.buyer.buyerReference,
|
192
|
-
'mun:Email' => request.buyer.email,
|
193
|
-
'mun:GenderEnum' => request.buyer.genderEnum,
|
194
|
-
'mun:FacebookId' => request.buyer.facebookId,
|
195
|
-
'mun:HomePhone' => request.buyer.homePhone,
|
196
|
-
'mun:IpAddress' => request.buyer.ipAddress,
|
197
|
-
'mun:MobilePhone' => request.buyer.mobilePhone,
|
198
|
-
'mun:Name' => request.buyer.name,
|
199
|
-
'mun:PersonTypeEnum' => request.buyer.personTypeEnum,
|
200
|
-
'mun:TaxDocumentNumber' => request.buyer.taxDocumentNumber,
|
201
|
-
'mun:TaxDocumentTypeEnum' => request.buyer.taxDocumentTypeEnum,
|
202
|
-
'mun:TwitterId' => request.buyer.twitterId,
|
203
|
-
'mun:WorkPhone' => request.buyer.workPhone,
|
204
|
-
'mun:BuyerAddressCollection' => nil
|
205
|
-
|
206
|
-
}
|
207
|
-
|
208
|
-
if request.buyer.addressCollection.count > 0
|
209
|
-
|
210
|
-
buyer['mun:BuyerAddressCollection'] = {'mun:BuyerAddress'=>Array.new}
|
211
|
-
|
212
|
-
request.buyer.addressCollection.each do |address|
|
213
|
-
|
214
|
-
buyer['mun:BuyerAddressCollection']['mun:BuyerAddress'] << {
|
215
|
-
'mun:AddressTypeEnum' => address.addressTypeEnum,
|
216
|
-
'mun:City' => address.city,
|
217
|
-
'mun:Complement' => address.complement,
|
218
|
-
'mun:CountryEnum' => address.countryEnum,
|
219
|
-
'mun:District' => address.district,
|
220
|
-
'mun:Number' => address.number,
|
221
|
-
'mun:State' => address.state,
|
222
|
-
'mun:Street' => address.street,
|
223
|
-
'mun:ZipCode' => address.zipCode
|
224
|
-
}
|
225
|
-
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
return buyer
|
230
|
-
end
|
231
|
-
|
232
|
-
def CreateShoppingCart(request)
|
233
|
-
|
234
|
-
shoppingCartColl = {'mun:ShoppingCart' => Array.new}
|
235
|
-
|
236
|
-
shoppingCartItemCollection = {'mun:ShoppingCartItem' => Array.new}
|
237
|
-
|
238
|
-
request.shoppingCartCollection.each do |shoppingCart|
|
239
|
-
|
240
|
-
shoppingCart.shoppingCartItemCollection.each do |shoppingCartItem|
|
241
|
-
shoppingCartItemCollection['mun:ShoppingCartItem'] << {
|
242
|
-
'mun:Description' => shoppingCartItem.description,
|
243
|
-
'mun:ItemReference' => shoppingCartItem.itemReference,
|
244
|
-
'mun:Name' => shoppingCartItem.name,
|
245
|
-
'mun:Quantity' => shoppingCartItem.quantity,
|
246
|
-
'mun:TotalCostInCents' => shoppingCartItem.totalCostInCents,
|
247
|
-
'mun:UnitCostInCents' => shoppingCartItem.unitCostInCents
|
248
|
-
}
|
249
|
-
end
|
250
|
-
|
251
|
-
shoppingCartColl['mun:ShoppingCart'] << {
|
252
|
-
'mun:FreightCostInCents' => shoppingCart.freightCostInCents,
|
253
|
-
'mun:ShoppingCartItemCollection' => shoppingCartItemCollection
|
254
|
-
}
|
255
|
-
|
256
|
-
end
|
257
|
-
|
258
|
-
return shoppingCartColl
|
259
|
-
|
260
|
-
end
|
261
|
-
|
262
|
-
# This method create a hash collection with all boleto transactions information.
|
263
|
-
# The hash collection is a part of the data send to the webservice.
|
264
|
-
#
|
265
|
-
# @param boletoRequest [Array<BoletoTransaction>] CreateOrderRequest instance
|
266
|
-
# @return [Hash<Symbol, Object>] Hash collection with one or more boleto transactions.
|
267
|
-
# @!visibility private
|
268
|
-
def CreateBoletoTransactionRequest(boletoRequest)
|
269
|
-
|
270
|
-
transactionCollection = {'mun:BoletoTransaction' => Array.new}
|
271
|
-
|
272
|
-
boletoRequest.boletoTransactionCollection.each do |boleto|
|
273
|
-
|
274
|
-
transactionCollection['mun:BoletoTransaction'] << {
|
275
|
-
'mun:AmountInCents' => boleto.amountInCents,
|
276
|
-
'mun:BankNumber' => boleto.bankNumber,
|
277
|
-
'mun:DaysToAddInBoletoExpirationDate' => boleto.daysToAddInBoletoExpirationDate,
|
278
|
-
'mun:Instructions' => boleto.instructions,
|
279
|
-
'mun:NossoNumero' => boleto.nossoNumero,
|
280
|
-
'mun:TransactionReference' => boleto.transactionReference,
|
281
|
-
|
282
|
-
}
|
283
|
-
|
284
|
-
end
|
285
|
-
|
286
|
-
return transactionCollection
|
287
|
-
end
|
288
|
-
|
289
|
-
# This method create a hash collection with all credit card transactions information.
|
290
|
-
# The hash collection is a part of the data send to the webservice.
|
291
|
-
#
|
292
|
-
# @param creditCardRequest [Array<CreditCardTransaction>] CreateOrderRequest instance
|
293
|
-
# @return [Hash<Symbol, Object>] Hash collection with one or more credit card transactions.
|
294
|
-
# @!visibility private
|
295
|
-
def CreateCreditCardTransaction(creditCardRequest)
|
296
|
-
|
297
|
-
transactionCollection = {'mun:CreditCardTransaction' => Array.new}
|
298
|
-
|
299
|
-
creditCardRequest.creditCardTransactionCollection.each do |transaction|
|
300
|
-
|
301
|
-
if environment == :test
|
302
|
-
transaction.paymentMethodCode = 1 # Simulator payment code
|
303
|
-
end
|
304
|
-
|
305
|
-
transaction_hash = if transaction.instantBuyKey
|
306
|
-
{
|
307
|
-
'mun:AmountInCents' => transaction.amountInCents,
|
308
|
-
'mun:CreditCardBrandEnum' => transaction.creditCardBrandEnum.to_s,
|
309
|
-
'mun:InstantBuyKey' => transaction.instantBuyKey,
|
310
|
-
'mun:CreditCardOperationEnum' => transaction.creditCardOperationEnum.to_s,
|
311
|
-
'mun:InstallmentCount' => transaction.installmentCount,
|
312
|
-
'mun:PaymentMethodCode' => transaction.paymentMethodCode,
|
313
|
-
'mun:TransactionReference' => transaction.transactionReference
|
314
|
-
}
|
315
|
-
else
|
316
|
-
{
|
317
|
-
'mun:AmountInCents' => transaction.amountInCents,
|
318
|
-
'mun:CreditCardBrandEnum' => transaction.creditCardBrandEnum.to_s,
|
319
|
-
'mun:CreditCardNumber' => transaction.creditCardNumber,
|
320
|
-
'mun:CreditCardOperationEnum' => transaction.creditCardOperationEnum.to_s,
|
321
|
-
'mun:ExpMonth' => transaction.expirationMonth,
|
322
|
-
'mun:ExpYear' => transaction.expirationYear,
|
323
|
-
'mun:HolderName' => transaction.holderName,
|
324
|
-
'mun:InstallmentCount' => transaction.installmentCount,
|
325
|
-
'mun:PaymentMethodCode' => transaction.paymentMethodCode,
|
326
|
-
'mun:SecurityCode' => transaction.securityCode,
|
327
|
-
'mun:TransactionReference' => transaction.transactionReference
|
328
|
-
}
|
329
|
-
end
|
330
|
-
|
331
|
-
if transaction.recurrency.nil? == false
|
332
|
-
|
333
|
-
transaction_hash['mun:Recurrency'] = {
|
334
|
-
'mun:DateToStartBilling' => transaction.recurrency.dateToStartBilling,
|
335
|
-
'mun:FrequencyEnum' => transaction.recurrency.frequencyEnum,
|
336
|
-
'mun:Interval' => transaction.recurrency.interval,
|
337
|
-
'mun:OneDollarAuth' => transaction.recurrency.oneDollarAuth,
|
338
|
-
'mun:Recurrences' => transaction.recurrency.recurrences
|
339
|
-
}
|
340
|
-
end
|
341
|
-
|
342
|
-
transactionCollection['mun:CreditCardTransaction'] << transaction_hash
|
343
|
-
end
|
344
|
-
|
345
|
-
return transactionCollection
|
346
|
-
end
|
347
|
-
|
348
|
-
|
349
|
-
# This method send the hash collectin created in this client and send it to the webservice.
|
350
|
-
#
|
351
|
-
# == Parameters:
|
352
|
-
# @param hash [Hash<Symbol, Object] Hash collection generated by Nori using the base SOAP XML.
|
353
|
-
# @param service_method [Symbol] A Symbol declaring the method that will be called. Can be <i>:create_order</i>, <i>:manage_order<i/> or <i>:query_order</i>.
|
354
|
-
# @return [Hash<Symbol, Object>] A hash collection with the service method response.
|
355
|
-
# @!visibility private
|
356
|
-
def SendToService(hash, service_method)
|
357
|
-
|
358
|
-
url = nil
|
359
|
-
|
360
|
-
if @environment == :production
|
361
|
-
url = @@WEBSERVICE_PRODUCTION_URL
|
362
|
-
else
|
363
|
-
url = @@WEBSERVICE_TEST_URL
|
364
|
-
end
|
365
|
-
savon_levels = { :none => -1, :debug => 0, :info => 1, :warn => 2, :error => 3 }
|
366
|
-
|
367
|
-
if not savon_levels.include? @log_level
|
368
|
-
@log_level = :none
|
369
|
-
end
|
370
|
-
|
371
|
-
level = :debug
|
372
|
-
enable_log = true
|
373
|
-
filters = [:CreditCardNumber,
|
374
|
-
:SecurityCode,
|
375
|
-
:MerchantKey]
|
376
|
-
|
377
|
-
if @log_level == :none
|
378
|
-
level = :error
|
379
|
-
enable_log = false
|
380
|
-
end
|
381
|
-
|
382
|
-
|
383
|
-
client = Savon.client do
|
384
|
-
wsdl url
|
385
|
-
log enable_log
|
386
|
-
log_level level
|
387
|
-
filters filters
|
388
|
-
ssl_verify_mode :none
|
389
|
-
namespaces 'xmlns:mun' => 'http://schemas.datacontract.org/2004/07/MundiPagg.One.Service.DataContracts'
|
390
|
-
end
|
391
|
-
|
392
|
-
response = client.call(service_method) do
|
393
|
-
message hash
|
394
|
-
end
|
395
|
-
|
396
|
-
return response.to_hash
|
397
|
-
end
|
398
|
-
|
399
|
-
private :CreateBoletoTransactionRequest, :CreateCreditCardTransaction, :CreateBuyer, :SendToService, :parser
|
400
|
-
end
|
401
|
-
end
|
1
|
+
module Mundipagg
|
2
|
+
# Class that handles all webservice calls
|
3
|
+
class Gateway
|
4
|
+
|
5
|
+
# Sets the soap request log level.
|
6
|
+
# Can be: { :debug, :info, :warn, :error or :none }
|
7
|
+
# Use :debug only to inspect the Xml sent and received to the service.
|
8
|
+
# Default in test environment => :debug
|
9
|
+
# Default in production environment => :none
|
10
|
+
attr_accessor :log_level
|
11
|
+
|
12
|
+
# @return [Nori] Nori class who handle the conversion of base XML to a hash collection
|
13
|
+
# @see https://github.com/savonrb/nori
|
14
|
+
attr_reader :parser
|
15
|
+
|
16
|
+
# <i>:test</i> = Simulator enviroment, fake transaction approval;
|
17
|
+
# <i>:production</i> = Real transaction, needs real credit card.
|
18
|
+
# @return [Symbol] Webservice environment.
|
19
|
+
attr_accessor :environment
|
20
|
+
|
21
|
+
# @return [String] URL that points to the simulator WSDL
|
22
|
+
@@WEBSERVICE_TEST_URL = 'https://staging.mundipaggone.com/MundiPaggService.svc?wsdl'
|
23
|
+
|
24
|
+
# @return [String] URL that points to the production WSDL
|
25
|
+
@@WEBSERVICE_PRODUCTION_URL = 'https://transaction.mundipaggone.com/MundiPaggService.svc?wsdl'
|
26
|
+
|
27
|
+
# Initialize a class with an environment
|
28
|
+
#
|
29
|
+
# @param environment [Symbol] Sets the MundiPagg environment will be used by the client.
|
30
|
+
def initialize(environment=:test)
|
31
|
+
@parser = Nori.new(:convert_tags_to => lambda { |tag| tag })
|
32
|
+
@environment = environment
|
33
|
+
|
34
|
+
if environment == :test
|
35
|
+
@log_level = :debug
|
36
|
+
else
|
37
|
+
@log_level = :error
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
# This method makes requests to the webservice method ManageOrder.
|
44
|
+
#
|
45
|
+
# @param request [CreateOrderRequest] A ManagerOrderRequest instance containing information to capture or void a transaction or order.
|
46
|
+
# @return [Hash<Symbol, Object>] A hash collection containing the response data
|
47
|
+
def ManageOrder(request)
|
48
|
+
|
49
|
+
hash = @parser.parse('<tns:manageOrderRequest>
|
50
|
+
<mun:ManageCreditCardTransactionCollection>
|
51
|
+
</mun:ManageCreditCardTransactionCollection>
|
52
|
+
<mun:ManageOrderOperationEnum>?</mun:ManageOrderOperationEnum>
|
53
|
+
<mun:MerchantKey>?</mun:MerchantKey>
|
54
|
+
<mun:OrderKey>?</mun:OrderKey>
|
55
|
+
<mun:OrderReference>?</mun:OrderReference>
|
56
|
+
<mun:RequestKey>?</mun:RequestKey>
|
57
|
+
</tns:manageOrderRequest>')
|
58
|
+
|
59
|
+
xml_hash = hash['tns:manageOrderRequest'];
|
60
|
+
|
61
|
+
xml_hash['mun:ManageCreditCardTransactionCollection'] = {'mun:ManageCreditCardTransactionRequest'=>Array.new}
|
62
|
+
|
63
|
+
if request.transactionCollection.nil? == false and request.transactionCollection.count > 0
|
64
|
+
|
65
|
+
request.transactionCollection.each do |transaction|
|
66
|
+
|
67
|
+
xml_hash['mun:ManageCreditCardTransactionCollection']['mun:ManageCreditCardTransactionRequest'] << {
|
68
|
+
'mun:AmountInCents' => transaction.amountInCents,
|
69
|
+
'mun:TransactionKey' => transaction.transactionKey,
|
70
|
+
'mun:TransactionReference' => transaction.transactionReference
|
71
|
+
}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
xml_hash['mun:ManageOrderOperationEnum'] = request.manageOrderOperationEnum
|
76
|
+
xml_hash['mun:MerchantKey'] = request.merchantKey
|
77
|
+
xml_hash['mun:OrderKey'] = request.orderKey
|
78
|
+
xml_hash['mun:OrderReference'] = request.orderReference
|
79
|
+
xml_hash['mun:RequestKey'] = request.requestKey
|
80
|
+
|
81
|
+
response = SendToService(hash, :manage_order)
|
82
|
+
|
83
|
+
return response
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
# This method makes requests to the webservice method QueryOrder.
|
88
|
+
#
|
89
|
+
# @param request [QueryOrderRequest] A QueryOrderRequest instance containing information to request more information about an order or transaction.
|
90
|
+
# @return [Hash<Symbol, Object>]
|
91
|
+
def QueryOrder(request)
|
92
|
+
|
93
|
+
hash = @parser.parse('<tns:queryOrderRequest>
|
94
|
+
<mun:MerchantKey>?</mun:MerchantKey>
|
95
|
+
<mun:OrderKey>?</mun:OrderKey>
|
96
|
+
<mun:OrderReference>?</mun:OrderReference>
|
97
|
+
<mun:RequestKey>?</mun:RequestKey>
|
98
|
+
</tns:queryOrderRequest>')
|
99
|
+
|
100
|
+
xml_hash = hash['tns:queryOrderRequest'];
|
101
|
+
|
102
|
+
xml_hash['mun:MerchantKey'] = request.merchantKey
|
103
|
+
xml_hash['mun:OrderKey'] = request.orderKey
|
104
|
+
xml_hash['mun:OrderReference'] = request.orderReference
|
105
|
+
xml_hash['mun:RequestKey'] = request.requestKey
|
106
|
+
|
107
|
+
response = SendToService(hash, :query_order)
|
108
|
+
|
109
|
+
return response
|
110
|
+
end
|
111
|
+
|
112
|
+
# This method makes requests to the webservice method CreateOrder.
|
113
|
+
#
|
114
|
+
# @param request [CreateOrderRequest] A CreateOrderRequest instance containing information to create a order.
|
115
|
+
# @return [Hash<Symbol, Object>] A hash collection containing the response data
|
116
|
+
def CreateOrder(request)
|
117
|
+
|
118
|
+
hash = @parser.parse('
|
119
|
+
<tns:createOrderRequest>
|
120
|
+
<mun:AmountInCents>?</mun:AmountInCents>
|
121
|
+
<mun:AmountInCentsToConsiderPaid>?</mun:AmountInCentsToConsiderPaid>
|
122
|
+
<mun:CurrencyIsoEnum>?</mun:CurrencyIsoEnum>
|
123
|
+
<mun:MerchantKey>?</mun:MerchantKey>
|
124
|
+
<mun:OrderReference>?</mun:OrderReference>
|
125
|
+
<mun:RequestKey>?</mun:RequestKey>
|
126
|
+
<mun:Buyer>
|
127
|
+
</mun:Buyer>
|
128
|
+
<mun:ShoppingCartCollection>
|
129
|
+
</mun:ShoppingCartCollection>
|
130
|
+
<mun:CreditCardTransactionCollection>
|
131
|
+
</mun:CreditCardTransactionCollection>
|
132
|
+
<mun:BoletoTransactionCollection>
|
133
|
+
</mun:BoletoTransactionCollection>
|
134
|
+
</tns:createOrderRequest>')
|
135
|
+
|
136
|
+
xml_hash = hash['tns:createOrderRequest'];
|
137
|
+
|
138
|
+
xml_hash['mun:AmountInCents'] = request.amountInCents
|
139
|
+
|
140
|
+
if request.amountInCentsToConsiderPaid == nil
|
141
|
+
xml_hash['mun:AmountInCentsToConsiderPaid'] = request.amountInCents
|
142
|
+
else
|
143
|
+
xml_hash['mun:AmountInCentsToConsiderPaid'] = request.amountInCentsToConsiderPaid
|
144
|
+
end
|
145
|
+
|
146
|
+
xml_hash['mun:CurrencyIsoEnum'] = request.currencyIsoEnum
|
147
|
+
xml_hash['mun:MerchantKey'] = request.merchantKey
|
148
|
+
xml_hash['mun:OrderReference'] = request.orderReference
|
149
|
+
xml_hash['mun:RequestKey'] = request.requestKey
|
150
|
+
|
151
|
+
if request.buyer.nil? == false
|
152
|
+
xml_hash['mun:Buyer'] = CreateBuyer(request)
|
153
|
+
end
|
154
|
+
|
155
|
+
if not request.shoppingCartCollection.nil? and request.shoppingCartCollection.count > 0
|
156
|
+
xml_hash['mun:ShoppingCartCollection'] = CreateShoppingCart(request)
|
157
|
+
end
|
158
|
+
|
159
|
+
if not request.creditCardTransactionCollection.nil? and request.creditCardTransactionCollection.count > 0
|
160
|
+
#Create credit card transaction array and assing to the contract hash
|
161
|
+
creditCardTransactionCollection = CreateCreditCardTransaction(request)
|
162
|
+
xml_hash['mun:CreditCardTransactionCollection'] = creditCardTransactionCollection
|
163
|
+
else
|
164
|
+
xml_hash['mun:CreditCardTransactionCollection'] = nil
|
165
|
+
end
|
166
|
+
|
167
|
+
if request.boletoTransactionCollection.nil? == false and request.boletoTransactionCollection.count > 0
|
168
|
+
#Create boleto transaction array and assing to the contract hash
|
169
|
+
boletoTransactionCollection = CreateBoletoTransactionRequest(request);
|
170
|
+
xml_hash['mun:BoletoTransactionCollection'] = boletoTransactionCollection
|
171
|
+
end
|
172
|
+
|
173
|
+
response = SendToService(hash, :create_order)
|
174
|
+
|
175
|
+
|
176
|
+
return response
|
177
|
+
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
# This method create a hash collection with all buyer information.
|
182
|
+
# The hash collection is a part of the data send to the webservice.
|
183
|
+
#
|
184
|
+
# @param request [CreateOrderRequest]
|
185
|
+
# @return [Hash<Symbol, Object>] Hash collection with buyer information.
|
186
|
+
# @!visibility private
|
187
|
+
def CreateBuyer(request)
|
188
|
+
|
189
|
+
buyer = {
|
190
|
+
'mun:BuyerKey' => request.buyer.buyerKey,
|
191
|
+
'mun:BuyerReference' => request.buyer.buyerReference,
|
192
|
+
'mun:Email' => request.buyer.email,
|
193
|
+
'mun:GenderEnum' => request.buyer.genderEnum,
|
194
|
+
'mun:FacebookId' => request.buyer.facebookId,
|
195
|
+
'mun:HomePhone' => request.buyer.homePhone,
|
196
|
+
'mun:IpAddress' => request.buyer.ipAddress,
|
197
|
+
'mun:MobilePhone' => request.buyer.mobilePhone,
|
198
|
+
'mun:Name' => request.buyer.name,
|
199
|
+
'mun:PersonTypeEnum' => request.buyer.personTypeEnum,
|
200
|
+
'mun:TaxDocumentNumber' => request.buyer.taxDocumentNumber,
|
201
|
+
'mun:TaxDocumentTypeEnum' => request.buyer.taxDocumentTypeEnum,
|
202
|
+
'mun:TwitterId' => request.buyer.twitterId,
|
203
|
+
'mun:WorkPhone' => request.buyer.workPhone,
|
204
|
+
'mun:BuyerAddressCollection' => nil
|
205
|
+
|
206
|
+
}
|
207
|
+
|
208
|
+
if request.buyer.addressCollection.count > 0
|
209
|
+
|
210
|
+
buyer['mun:BuyerAddressCollection'] = {'mun:BuyerAddress'=>Array.new}
|
211
|
+
|
212
|
+
request.buyer.addressCollection.each do |address|
|
213
|
+
|
214
|
+
buyer['mun:BuyerAddressCollection']['mun:BuyerAddress'] << {
|
215
|
+
'mun:AddressTypeEnum' => address.addressTypeEnum,
|
216
|
+
'mun:City' => address.city,
|
217
|
+
'mun:Complement' => address.complement,
|
218
|
+
'mun:CountryEnum' => address.countryEnum,
|
219
|
+
'mun:District' => address.district,
|
220
|
+
'mun:Number' => address.number,
|
221
|
+
'mun:State' => address.state,
|
222
|
+
'mun:Street' => address.street,
|
223
|
+
'mun:ZipCode' => address.zipCode
|
224
|
+
}
|
225
|
+
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
return buyer
|
230
|
+
end
|
231
|
+
|
232
|
+
def CreateShoppingCart(request)
|
233
|
+
|
234
|
+
shoppingCartColl = {'mun:ShoppingCart' => Array.new}
|
235
|
+
|
236
|
+
shoppingCartItemCollection = {'mun:ShoppingCartItem' => Array.new}
|
237
|
+
|
238
|
+
request.shoppingCartCollection.each do |shoppingCart|
|
239
|
+
|
240
|
+
shoppingCart.shoppingCartItemCollection.each do |shoppingCartItem|
|
241
|
+
shoppingCartItemCollection['mun:ShoppingCartItem'] << {
|
242
|
+
'mun:Description' => shoppingCartItem.description,
|
243
|
+
'mun:ItemReference' => shoppingCartItem.itemReference,
|
244
|
+
'mun:Name' => shoppingCartItem.name,
|
245
|
+
'mun:Quantity' => shoppingCartItem.quantity,
|
246
|
+
'mun:TotalCostInCents' => shoppingCartItem.totalCostInCents,
|
247
|
+
'mun:UnitCostInCents' => shoppingCartItem.unitCostInCents
|
248
|
+
}
|
249
|
+
end
|
250
|
+
|
251
|
+
shoppingCartColl['mun:ShoppingCart'] << {
|
252
|
+
'mun:FreightCostInCents' => shoppingCart.freightCostInCents,
|
253
|
+
'mun:ShoppingCartItemCollection' => shoppingCartItemCollection
|
254
|
+
}
|
255
|
+
|
256
|
+
end
|
257
|
+
|
258
|
+
return shoppingCartColl
|
259
|
+
|
260
|
+
end
|
261
|
+
|
262
|
+
# This method create a hash collection with all boleto transactions information.
|
263
|
+
# The hash collection is a part of the data send to the webservice.
|
264
|
+
#
|
265
|
+
# @param boletoRequest [Array<BoletoTransaction>] CreateOrderRequest instance
|
266
|
+
# @return [Hash<Symbol, Object>] Hash collection with one or more boleto transactions.
|
267
|
+
# @!visibility private
|
268
|
+
def CreateBoletoTransactionRequest(boletoRequest)
|
269
|
+
|
270
|
+
transactionCollection = {'mun:BoletoTransaction' => Array.new}
|
271
|
+
|
272
|
+
boletoRequest.boletoTransactionCollection.each do |boleto|
|
273
|
+
|
274
|
+
transactionCollection['mun:BoletoTransaction'] << {
|
275
|
+
'mun:AmountInCents' => boleto.amountInCents,
|
276
|
+
'mun:BankNumber' => boleto.bankNumber,
|
277
|
+
'mun:DaysToAddInBoletoExpirationDate' => boleto.daysToAddInBoletoExpirationDate,
|
278
|
+
'mun:Instructions' => boleto.instructions,
|
279
|
+
'mun:NossoNumero' => boleto.nossoNumero,
|
280
|
+
'mun:TransactionReference' => boleto.transactionReference,
|
281
|
+
|
282
|
+
}
|
283
|
+
|
284
|
+
end
|
285
|
+
|
286
|
+
return transactionCollection
|
287
|
+
end
|
288
|
+
|
289
|
+
# This method create a hash collection with all credit card transactions information.
|
290
|
+
# The hash collection is a part of the data send to the webservice.
|
291
|
+
#
|
292
|
+
# @param creditCardRequest [Array<CreditCardTransaction>] CreateOrderRequest instance
|
293
|
+
# @return [Hash<Symbol, Object>] Hash collection with one or more credit card transactions.
|
294
|
+
# @!visibility private
|
295
|
+
def CreateCreditCardTransaction(creditCardRequest)
|
296
|
+
|
297
|
+
transactionCollection = {'mun:CreditCardTransaction' => Array.new}
|
298
|
+
|
299
|
+
creditCardRequest.creditCardTransactionCollection.each do |transaction|
|
300
|
+
|
301
|
+
if environment == :test
|
302
|
+
transaction.paymentMethodCode = 1 # Simulator payment code
|
303
|
+
end
|
304
|
+
|
305
|
+
transaction_hash = if transaction.instantBuyKey
|
306
|
+
{
|
307
|
+
'mun:AmountInCents' => transaction.amountInCents,
|
308
|
+
'mun:CreditCardBrandEnum' => transaction.creditCardBrandEnum.to_s,
|
309
|
+
'mun:InstantBuyKey' => transaction.instantBuyKey,
|
310
|
+
'mun:CreditCardOperationEnum' => transaction.creditCardOperationEnum.to_s,
|
311
|
+
'mun:InstallmentCount' => transaction.installmentCount,
|
312
|
+
'mun:PaymentMethodCode' => transaction.paymentMethodCode,
|
313
|
+
'mun:TransactionReference' => transaction.transactionReference
|
314
|
+
}
|
315
|
+
else
|
316
|
+
{
|
317
|
+
'mun:AmountInCents' => transaction.amountInCents,
|
318
|
+
'mun:CreditCardBrandEnum' => transaction.creditCardBrandEnum.to_s,
|
319
|
+
'mun:CreditCardNumber' => transaction.creditCardNumber,
|
320
|
+
'mun:CreditCardOperationEnum' => transaction.creditCardOperationEnum.to_s,
|
321
|
+
'mun:ExpMonth' => transaction.expirationMonth,
|
322
|
+
'mun:ExpYear' => transaction.expirationYear,
|
323
|
+
'mun:HolderName' => transaction.holderName,
|
324
|
+
'mun:InstallmentCount' => transaction.installmentCount,
|
325
|
+
'mun:PaymentMethodCode' => transaction.paymentMethodCode,
|
326
|
+
'mun:SecurityCode' => transaction.securityCode,
|
327
|
+
'mun:TransactionReference' => transaction.transactionReference
|
328
|
+
}
|
329
|
+
end
|
330
|
+
|
331
|
+
if transaction.recurrency.nil? == false
|
332
|
+
|
333
|
+
transaction_hash['mun:Recurrency'] = {
|
334
|
+
'mun:DateToStartBilling' => transaction.recurrency.dateToStartBilling,
|
335
|
+
'mun:FrequencyEnum' => transaction.recurrency.frequencyEnum,
|
336
|
+
'mun:Interval' => transaction.recurrency.interval,
|
337
|
+
'mun:OneDollarAuth' => transaction.recurrency.oneDollarAuth,
|
338
|
+
'mun:Recurrences' => transaction.recurrency.recurrences
|
339
|
+
}
|
340
|
+
end
|
341
|
+
|
342
|
+
transactionCollection['mun:CreditCardTransaction'] << transaction_hash
|
343
|
+
end
|
344
|
+
|
345
|
+
return transactionCollection
|
346
|
+
end
|
347
|
+
|
348
|
+
|
349
|
+
# This method send the hash collectin created in this client and send it to the webservice.
|
350
|
+
#
|
351
|
+
# == Parameters:
|
352
|
+
# @param hash [Hash<Symbol, Object] Hash collection generated by Nori using the base SOAP XML.
|
353
|
+
# @param service_method [Symbol] A Symbol declaring the method that will be called. Can be <i>:create_order</i>, <i>:manage_order<i/> or <i>:query_order</i>.
|
354
|
+
# @return [Hash<Symbol, Object>] A hash collection with the service method response.
|
355
|
+
# @!visibility private
|
356
|
+
def SendToService(hash, service_method)
|
357
|
+
|
358
|
+
url = nil
|
359
|
+
|
360
|
+
if @environment == :production
|
361
|
+
url = @@WEBSERVICE_PRODUCTION_URL
|
362
|
+
else
|
363
|
+
url = @@WEBSERVICE_TEST_URL
|
364
|
+
end
|
365
|
+
savon_levels = { :none => -1, :debug => 0, :info => 1, :warn => 2, :error => 3 }
|
366
|
+
|
367
|
+
if not savon_levels.include? @log_level
|
368
|
+
@log_level = :none
|
369
|
+
end
|
370
|
+
|
371
|
+
level = :debug
|
372
|
+
enable_log = true
|
373
|
+
filters = [:CreditCardNumber,
|
374
|
+
:SecurityCode,
|
375
|
+
:MerchantKey]
|
376
|
+
|
377
|
+
if @log_level == :none
|
378
|
+
level = :error
|
379
|
+
enable_log = false
|
380
|
+
end
|
381
|
+
|
382
|
+
|
383
|
+
client = Savon.client do
|
384
|
+
wsdl url
|
385
|
+
log enable_log
|
386
|
+
log_level level
|
387
|
+
filters filters
|
388
|
+
ssl_verify_mode :none
|
389
|
+
namespaces 'xmlns:mun' => 'http://schemas.datacontract.org/2004/07/MundiPagg.One.Service.DataContracts'
|
390
|
+
end
|
391
|
+
|
392
|
+
response = client.call(service_method) do
|
393
|
+
message hash
|
394
|
+
end
|
395
|
+
|
396
|
+
return response.to_hash
|
397
|
+
end
|
398
|
+
|
399
|
+
private :CreateBoletoTransactionRequest, :CreateCreditCardTransaction, :CreateBuyer, :SendToService, :parser
|
400
|
+
end
|
401
|
+
end
|