mundipagg 1.2.4 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 55265216c6c744da6ed594d1b649938b6b62f43f
4
- data.tar.gz: 91758a2acfaf782b2c760a9c0e7a8ac80b2caae8
3
+ metadata.gz: 6164f0165ed7ffc42595b2e174eea3773e8811c9
4
+ data.tar.gz: d6bf8662ec2df1030bd51af3ffbbaba30ff95935
5
5
  SHA512:
6
- metadata.gz: 051607d759ba7e223df939295f2868431f72d97fda1834c877bea3634a039ec56a1b416a77badc5176012bc3474f2ac86cada8125e1cffc0e74d595b62ac64aa
7
- data.tar.gz: 9d29a62772cb890bee12bcb5a88c237764d3e437b50e24ffc5f96e49b60837a3069ffb3067b5362156f07fb99ebcb13018d80fe7620782ab5f609e4026cb2995
6
+ metadata.gz: 7f77d0b720f5bfecf788737522c610d7e0ad73aafa5c5496719c42bdd4a180ee57f2419fcc8738bb0723d46baf7dbb860104a9ed24538d3fe6c3a4070f79da04
7
+ data.tar.gz: 37b5fb0c7ae9bc365b0a437314e50ef12cceab8a3c6499dac591afc9aa5d951f248e952201e91a195f0f29c63b80d20f03c44a409253c6b94492cf095ca7c158
data/README.md CHANGED
@@ -16,6 +16,14 @@ Unit tests made with [Cucumber](https://github.com/cucumber/cucumber) and [RSpec
16
16
  * [RubyDoc](http://rubydoc.info/github/mundipagg/mundipagg-ruby-api/)
17
17
 
18
18
 
19
+ ## Tests
20
+ After get your _MerchantKey_ you can run the unit tests in our simulator environment, all you need to do is put your _MerchantKey_ in the [TestConfiguration.rb file](https://github.com/mundipagg/mundipagg-ruby-api/blob/master/tests/test_configuration.rb) and execute cucumber tests with the command below:
21
+
22
+ ```sh
23
+ $ bundle exec rake integration
24
+ ```
25
+
26
+
19
27
  ## Usage
20
28
  Below a simple exemple of an order with one credit card transaction.
21
29
 
@@ -1,335 +1,344 @@
1
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 }
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 => :error
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://transaction.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:CreditCardTransactionCollection>
129
- </mun:CreditCardTransactionCollection>
130
- <mun:BoletoTransactionCollection>
131
- </mun:BoletoTransactionCollection>
132
- </tns:createOrderRequest>')
133
-
134
- xml_hash = hash['tns:createOrderRequest'];
135
-
136
- xml_hash['mun:AmountInCents'] = request.amountInCents
137
- xml_hash['mun:AmountInCentsToConsiderPaid'] = request.amountInCentsToConsiderPaid
138
- xml_hash['mun:CurrencyIsoEnum'] = request.currencyIsoEnum
139
- xml_hash['mun:MerchantKey'] = request.merchantKey
140
- xml_hash['mun:OrderReference'] = request.orderReference
141
- xml_hash['mun:RequestKey'] = request.requestKey
142
-
143
- if request.buyer.nil? == false
144
- xml_hash['mun:Buyer'] = CreateBuyer(request)
145
- end
146
-
147
- if not request.creditCardTransactionCollection.nil? and request.creditCardTransactionCollection.count > 0
148
- #Create credit card transaction array and assing to the contract hash
149
- creditCardTransactionCollection = CreateCreditCardTransaction(request)
150
- xml_hash['mun:CreditCardTransactionCollection'] = creditCardTransactionCollection
151
- else
152
- xml_hash['mun:CreditCardTransactionCollection'] = nil
153
- end
154
-
155
- if request.boletoTransactionCollection.nil? == false and request.boletoTransactionCollection.count > 0
156
- #Create boleto transaction array and assing to the contract hash
157
- boletoTransactionCollection = CreateBoletoTransactionRequest(request);
158
- xml_hash['mun:BoletoTransactionCollection'] = boletoTransactionCollection
159
- end
160
-
161
- response = SendToService(hash, :create_order)
162
-
163
-
164
- return response
165
-
166
- end
167
-
168
-
169
- # This method create a hash collection with all buyer information.
170
- # The hash collection is a part of the data send to the webservice.
171
- #
172
- # @param request [CreateOrderRequest]
173
- # @return [Hash<Symbol, Object>] Hash collection with buyer information.
174
- # @!visibility private
175
- def CreateBuyer(request)
176
-
177
- buyer = {
178
- 'mun:BuyerKey' => request.buyer.buyerKey,
179
- 'mun:BuyerReference' => request.buyer.buyerReference,
180
- 'mun:Email' => request.buyer.email,
181
- 'mun:GenderEnum' => request.buyer.genderEnum,
182
- 'mun:FacebookId' => request.buyer.facebookId,
183
- 'mun:GenderEnum' => request.buyer.genderEnum,
184
- 'mun:HomePhone' => request.buyer.homePhone,
185
- 'mun:IpAddress' => request.buyer.ipAddress,
186
- 'mun:MobilePhone' => request.buyer.mobilePhone,
187
- 'mun:Name' => request.buyer.name,
188
- 'mun:PersonTypeEnum' => request.buyer.personTypeEnum,
189
- 'mun:TaxDocumentNumber' => request.buyer.taxDocumentNumber,
190
- 'mun:TaxDocumentNumberTypeEnum' => request.buyer.taxDocumentTypeEnum,
191
- 'mun:TwitterId' => request.buyer.twitterId,
192
- 'mun:WorkPhone' => request.buyer.workPhone,
193
- 'mun:BuyerAddressCollection' => nil
194
-
195
- }
196
-
197
- if request.buyer.addressCollection.count > 0
198
-
199
- buyer['mun:BuyerAddressCollection'] = {'mun:BuyerAddress'=>Array.new}
200
-
201
- request.buyer.addressCollection.each do |address|
202
-
203
- buyer['mun:BuyerAddressCollection']['mun:BuyerAddress'] << {
204
- 'mun:AddressTypeEnum' => address.addressTypeEnum,
205
- 'mun:City' => address.city,
206
- 'mun:Complement' => address.complement,
207
- 'mun:CountryEnum' => address.countryEnum,
208
- 'mun:District' => address.district,
209
- 'mun:Number' => address.number,
210
- 'mun:State' => address.state,
211
- 'mun:Street' => address.street,
212
- 'mun:ZipCode' => address.zipCode
213
- }
214
-
215
- end
216
- end
217
-
218
- return buyer
219
- end
220
-
221
- # This method create a hash collection with all boleto transactions information.
222
- # The hash collection is a part of the data send to the webservice.
223
- #
224
- # @param boletoRequest [Array<BoletoTransaction>] CreateOrderRequest instance
225
- # @return [Hash<Symbol, Object>] Hash collection with one or more boleto transactions.
226
- # @!visibility private
227
- def CreateBoletoTransactionRequest(boletoRequest)
228
-
229
- transactionCollection = {'mun:BoletoTransaction' => Array.new}
230
-
231
- boletoRequest.boletoTransactionCollection.each do |boleto|
232
-
233
- transactionCollection['mun:BoletoTransaction'] << {
234
- 'mun:AmountInCents' => boleto.amountInCents,
235
- 'mun:BankNumber' => boleto.bankNumber,
236
- 'mun:DaysToAddInBoletoExpirationDate' => boleto.daysToAddInBoletoExpirationDate,
237
- 'mun:Instructions' => boleto.instructions,
238
- 'mun:NossoNumero' => boleto.nossoNumero,
239
- 'mun:TransactionReference' => boleto.transactionReference,
240
-
241
- }
242
-
243
- end
244
-
245
- return transactionCollection
246
- end
247
-
248
- # This method create a hash collection with all credit card transactions information.
249
- # The hash collection is a part of the data send to the webservice.
250
- #
251
- # @param creditCardRequest [Array<CreditCardTransaction>] CreateOrderRequest instance
252
- # @return [Hash<Symbol, Object>] Hash collection with one or more credit card transactions.
253
- # @!visibility private
254
- def CreateCreditCardTransaction(creditCardRequest)
255
-
256
- transactionCollection = {'mun:CreditCardTransaction' => Array.new}
257
-
258
- creditCardRequest.creditCardTransactionCollection.each do |transaction|
259
-
260
- if environment == :test
261
- transaction.paymentMethodCode = 1 # Simulator payment code
262
- end
263
-
264
- transaction_hash = {
265
- 'mun:AmountInCents' => transaction.amountInCents,
266
- 'mun:CreditCardBrandEnum' => transaction.creditCardBrandEnum.to_s,
267
- 'mun:CreditCardNumber' => transaction.creditCardNumber,
268
- 'mun:CreditCardOperationEnum' => transaction.creditCardOperationEnum.to_s,
269
- 'mun:ExpMonth' => transaction.expirationMonth,
270
- 'mun:ExpYear' => transaction.expirationYear,
271
- 'mun:HolderName' => transaction.holderName,
272
- 'mun:InstallmentCount' => transaction.installmentCount,
273
- 'mun:PaymentMethodCode' => transaction.paymentMethodCode,
274
- 'mun:SecurityCode' => transaction.securityCode,
275
- 'mun:TransactionReference' => transaction.transactionReference
276
- }
277
-
278
- if transaction.recurrency.nil? == false
279
-
280
- transaction_hash['mun:Recurrency'] = {
281
- 'mun:DateToStartBilling' => transaction.recurrency.dateToStartBilling,
282
- 'mun:FrequencyEnum' => transaction.recurrency.frequencyEnum,
283
- 'mun:Interval' => transaction.recurrency.interval,
284
- 'mun:OneDollarAuth' => transaction.recurrency.oneDollarAuth,
285
- 'mun:Recurrences' => transaction.recurrency.recurrences
286
- }
287
- end
288
-
289
- transactionCollection['mun:CreditCardTransaction'] << transaction_hash
290
- end
291
-
292
- return transactionCollection
293
- end
294
-
295
-
296
- # This method send the hash collectin created in this client and send it to the webservice.
297
- #
298
- # == Parameters:
299
- # @param hash [Hash<Symbol, Object] Hash collection generated by Nori using the base SOAP XML.
300
- # @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>.
301
- # @return [Hash<Symbol, Object>] A hash collection with the service method response.
302
- # @!visibility private
303
- def SendToService(hash, service_method)
304
-
305
- url = nil
306
-
307
- if @environment == :production
308
- url = @@WEBSERVICE_PRODUCTION_URL
309
- else
310
- url = @@WEBSERVICE_TEST_URL
311
- end
312
- savon_levels = { :debug => 0, :info => 1, :warn => 2, :error => 3 }
313
-
314
- if not savon_levels.include? @log_level
315
- @log_level = :error
316
- end
317
-
318
- level = :debug
319
-
320
- client = Savon.client do
321
- wsdl url
322
- log_level level
323
- namespaces 'xmlns:mun' => 'http://schemas.datacontract.org/2004/07/MundiPagg.One.Service.DataContracts'
324
- end
325
-
326
- response = client.call(service_method) do
327
- message hash
328
- end
329
-
330
- return response.to_hash
331
- end
332
-
333
- private :CreateBoletoTransactionRequest, :CreateCreditCardTransaction, :CreateBuyer, :SendToService, :parser
334
- end
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://transaction.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:CreditCardTransactionCollection>
129
+ </mun:CreditCardTransactionCollection>
130
+ <mun:BoletoTransactionCollection>
131
+ </mun:BoletoTransactionCollection>
132
+ </tns:createOrderRequest>')
133
+
134
+ xml_hash = hash['tns:createOrderRequest'];
135
+
136
+ xml_hash['mun:AmountInCents'] = request.amountInCents
137
+ xml_hash['mun:AmountInCentsToConsiderPaid'] = request.amountInCentsToConsiderPaid
138
+ xml_hash['mun:CurrencyIsoEnum'] = request.currencyIsoEnum
139
+ xml_hash['mun:MerchantKey'] = request.merchantKey
140
+ xml_hash['mun:OrderReference'] = request.orderReference
141
+ xml_hash['mun:RequestKey'] = request.requestKey
142
+
143
+ if request.buyer.nil? == false
144
+ xml_hash['mun:Buyer'] = CreateBuyer(request)
145
+ end
146
+
147
+ if not request.creditCardTransactionCollection.nil? and request.creditCardTransactionCollection.count > 0
148
+ #Create credit card transaction array and assing to the contract hash
149
+ creditCardTransactionCollection = CreateCreditCardTransaction(request)
150
+ xml_hash['mun:CreditCardTransactionCollection'] = creditCardTransactionCollection
151
+ else
152
+ xml_hash['mun:CreditCardTransactionCollection'] = nil
153
+ end
154
+
155
+ if request.boletoTransactionCollection.nil? == false and request.boletoTransactionCollection.count > 0
156
+ #Create boleto transaction array and assing to the contract hash
157
+ boletoTransactionCollection = CreateBoletoTransactionRequest(request);
158
+ xml_hash['mun:BoletoTransactionCollection'] = boletoTransactionCollection
159
+ end
160
+
161
+ response = SendToService(hash, :create_order)
162
+
163
+
164
+ return response
165
+
166
+ end
167
+
168
+
169
+ # This method create a hash collection with all buyer information.
170
+ # The hash collection is a part of the data send to the webservice.
171
+ #
172
+ # @param request [CreateOrderRequest]
173
+ # @return [Hash<Symbol, Object>] Hash collection with buyer information.
174
+ # @!visibility private
175
+ def CreateBuyer(request)
176
+
177
+ buyer = {
178
+ 'mun:BuyerKey' => request.buyer.buyerKey,
179
+ 'mun:BuyerReference' => request.buyer.buyerReference,
180
+ 'mun:Email' => request.buyer.email,
181
+ 'mun:GenderEnum' => request.buyer.genderEnum,
182
+ 'mun:FacebookId' => request.buyer.facebookId,
183
+ 'mun:GenderEnum' => request.buyer.genderEnum,
184
+ 'mun:HomePhone' => request.buyer.homePhone,
185
+ 'mun:IpAddress' => request.buyer.ipAddress,
186
+ 'mun:MobilePhone' => request.buyer.mobilePhone,
187
+ 'mun:Name' => request.buyer.name,
188
+ 'mun:PersonTypeEnum' => request.buyer.personTypeEnum,
189
+ 'mun:TaxDocumentNumber' => request.buyer.taxDocumentNumber,
190
+ 'mun:TaxDocumentNumberTypeEnum' => request.buyer.taxDocumentTypeEnum,
191
+ 'mun:TwitterId' => request.buyer.twitterId,
192
+ 'mun:WorkPhone' => request.buyer.workPhone,
193
+ 'mun:BuyerAddressCollection' => nil
194
+
195
+ }
196
+
197
+ if request.buyer.addressCollection.count > 0
198
+
199
+ buyer['mun:BuyerAddressCollection'] = {'mun:BuyerAddress'=>Array.new}
200
+
201
+ request.buyer.addressCollection.each do |address|
202
+
203
+ buyer['mun:BuyerAddressCollection']['mun:BuyerAddress'] << {
204
+ 'mun:AddressTypeEnum' => address.addressTypeEnum,
205
+ 'mun:City' => address.city,
206
+ 'mun:Complement' => address.complement,
207
+ 'mun:CountryEnum' => address.countryEnum,
208
+ 'mun:District' => address.district,
209
+ 'mun:Number' => address.number,
210
+ 'mun:State' => address.state,
211
+ 'mun:Street' => address.street,
212
+ 'mun:ZipCode' => address.zipCode
213
+ }
214
+
215
+ end
216
+ end
217
+
218
+ return buyer
219
+ end
220
+
221
+ # This method create a hash collection with all boleto transactions information.
222
+ # The hash collection is a part of the data send to the webservice.
223
+ #
224
+ # @param boletoRequest [Array<BoletoTransaction>] CreateOrderRequest instance
225
+ # @return [Hash<Symbol, Object>] Hash collection with one or more boleto transactions.
226
+ # @!visibility private
227
+ def CreateBoletoTransactionRequest(boletoRequest)
228
+
229
+ transactionCollection = {'mun:BoletoTransaction' => Array.new}
230
+
231
+ boletoRequest.boletoTransactionCollection.each do |boleto|
232
+
233
+ transactionCollection['mun:BoletoTransaction'] << {
234
+ 'mun:AmountInCents' => boleto.amountInCents,
235
+ 'mun:BankNumber' => boleto.bankNumber,
236
+ 'mun:DaysToAddInBoletoExpirationDate' => boleto.daysToAddInBoletoExpirationDate,
237
+ 'mun:Instructions' => boleto.instructions,
238
+ 'mun:NossoNumero' => boleto.nossoNumero,
239
+ 'mun:TransactionReference' => boleto.transactionReference,
240
+
241
+ }
242
+
243
+ end
244
+
245
+ return transactionCollection
246
+ end
247
+
248
+ # This method create a hash collection with all credit card transactions information.
249
+ # The hash collection is a part of the data send to the webservice.
250
+ #
251
+ # @param creditCardRequest [Array<CreditCardTransaction>] CreateOrderRequest instance
252
+ # @return [Hash<Symbol, Object>] Hash collection with one or more credit card transactions.
253
+ # @!visibility private
254
+ def CreateCreditCardTransaction(creditCardRequest)
255
+
256
+ transactionCollection = {'mun:CreditCardTransaction' => Array.new}
257
+
258
+ creditCardRequest.creditCardTransactionCollection.each do |transaction|
259
+
260
+ if environment == :test
261
+ transaction.paymentMethodCode = 1 # Simulator payment code
262
+ end
263
+
264
+ transaction_hash = {
265
+ 'mun:AmountInCents' => transaction.amountInCents,
266
+ 'mun:CreditCardBrandEnum' => transaction.creditCardBrandEnum.to_s,
267
+ 'mun:CreditCardNumber' => transaction.creditCardNumber,
268
+ 'mun:CreditCardOperationEnum' => transaction.creditCardOperationEnum.to_s,
269
+ 'mun:ExpMonth' => transaction.expirationMonth,
270
+ 'mun:ExpYear' => transaction.expirationYear,
271
+ 'mun:HolderName' => transaction.holderName,
272
+ 'mun:InstallmentCount' => transaction.installmentCount,
273
+ 'mun:PaymentMethodCode' => transaction.paymentMethodCode,
274
+ 'mun:SecurityCode' => transaction.securityCode,
275
+ 'mun:TransactionReference' => transaction.transactionReference
276
+ }
277
+
278
+ if transaction.recurrency.nil? == false
279
+
280
+ transaction_hash['mun:Recurrency'] = {
281
+ 'mun:DateToStartBilling' => transaction.recurrency.dateToStartBilling,
282
+ 'mun:FrequencyEnum' => transaction.recurrency.frequencyEnum,
283
+ 'mun:Interval' => transaction.recurrency.interval,
284
+ 'mun:OneDollarAuth' => transaction.recurrency.oneDollarAuth,
285
+ 'mun:Recurrences' => transaction.recurrency.recurrences
286
+ }
287
+ end
288
+
289
+ transactionCollection['mun:CreditCardTransaction'] << transaction_hash
290
+ end
291
+
292
+ return transactionCollection
293
+ end
294
+
295
+
296
+ # This method send the hash collectin created in this client and send it to the webservice.
297
+ #
298
+ # == Parameters:
299
+ # @param hash [Hash<Symbol, Object] Hash collection generated by Nori using the base SOAP XML.
300
+ # @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>.
301
+ # @return [Hash<Symbol, Object>] A hash collection with the service method response.
302
+ # @!visibility private
303
+ def SendToService(hash, service_method)
304
+
305
+ url = nil
306
+
307
+ if @environment == :production
308
+ url = @@WEBSERVICE_PRODUCTION_URL
309
+ else
310
+ url = @@WEBSERVICE_TEST_URL
311
+ end
312
+ savon_levels = { :none => -1, :debug => 0, :info => 1, :warn => 2, :error => 3 }
313
+
314
+ if not savon_levels.include? @log_level
315
+ @log_level = :none
316
+ end
317
+
318
+ level = :debug
319
+ enable_log = true
320
+
321
+
322
+ if @log_level == :none
323
+ enable_log = false
324
+ level = :error
325
+ end
326
+
327
+
328
+ client = Savon.client do
329
+ wsdl url
330
+ log enable_log
331
+ log_level level
332
+ namespaces 'xmlns:mun' => 'http://schemas.datacontract.org/2004/07/MundiPagg.One.Service.DataContracts'
333
+ end
334
+
335
+ response = client.call(service_method) do
336
+ message hash
337
+ end
338
+
339
+ return response.to_hash
340
+ end
341
+
342
+ private :CreateBoletoTransactionRequest, :CreateCreditCardTransaction, :CreateBuyer, :SendToService, :parser
343
+ end
335
344
  end
@@ -2,7 +2,7 @@ module Mundipagg
2
2
  module Version
3
3
  Major = 1
4
4
  Minor = 2
5
- Revision = 4
5
+ Revision = 5
6
6
 
7
7
  String = "#{Major}.#{Minor}.#{Revision}"
8
8
  end
@@ -2,11 +2,12 @@
2
2
 
3
3
  Before do
4
4
  @client = Mundipagg::Gateway.new :test
5
+ @client.log_level = :none
5
6
  @order = Mundipagg::CreateOrderRequest.new
6
7
  @boleto = Mundipagg::BoletoTransaction.new
7
8
  @response = Hash.new
8
9
  @order.merchantKey = TestConfiguration::Merchant::MerchantKey
9
-
10
+ $world = self
10
11
  end
11
12
 
12
13
 
@@ -3,6 +3,7 @@
3
3
  Before do
4
4
 
5
5
  @client = Mundipagg::Gateway.new :test
6
+ @client.log_level = :none
6
7
  @order = Mundipagg::CreateOrderRequest.new
7
8
  @order.merchantKey = TestConfiguration::Merchant::MerchantKey
8
9
  @transaction = Mundipagg::CreditCardTransaction.new
@@ -1,9 +1,8 @@
1
1
  # encoding: UTF-8
2
-
3
2
  Before do
4
3
 
5
4
  @client = Mundipagg::Gateway.new :test
6
- @client.log_level = :error
5
+ @client.log_level = :none
7
6
 
8
7
  @order = Mundipagg::CreateOrderRequest.new
9
8
  @manage_order = Mundipagg::ManageOrderRequest.new
@@ -79,6 +78,7 @@ Then(/^I will receive a POST notification telling my transaction has been (\w+)$
79
78
  xml = TestHelper.CreateFakePostNotification(@response, @response_manage)
80
79
 
81
80
  @notification_hash = Mundipagg::PostNotification.ParseNotification(xml)
81
+ pp @notification_hash, :indent => true
82
82
 
83
83
  @notification_hash.should_not == nil
84
84
  @notification_hash.count.should > 0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mundipagg
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - MundiPagg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-25 00:00:00.000000000 Z
11
+ date: 2013-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: savon
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  version: '0'
75
75
  requirements: []
76
76
  rubyforge_project:
77
- rubygems_version: 2.0.6
77
+ rubygems_version: 2.1.10
78
78
  signing_key:
79
79
  specification_version: 4
80
80
  summary: MundiPagg Ruby Client Library