mundipagg 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,81 +1,81 @@
1
- module Mundipagg
2
- class CreditCardTransaction
3
-
4
- # @return [Long] Transaction amount in cents
5
- attr_accessor :amountInCents
6
-
7
- # @return [String] Instant buy key
8
- attr_accessor :instantBuyKey
9
-
10
- # @return [String] Card brand. Use the static property <i>BrandEnum</i>.
11
- # @see BrandEnum
12
- attr_accessor :creditCardBrandEnum
13
-
14
- # @return [String] Credit Card Number.
15
- attr_accessor :creditCardNumber
16
-
17
- # @return [String] Type of operation. Use the static property <i>OperationEnum</i>.
18
- # @see OperationEnum
19
- attr_accessor :creditCardOperationEnum
20
-
21
- # @return [Integer] Credit card expiration month
22
- attr_accessor :expirationMonth
23
-
24
- # @return [Integer] Credit card expiration year
25
- attr_accessor :expirationYear
26
-
27
- # @return [Integer] Name in the credit card
28
- attr_accessor :holderName
29
-
30
- # @return [Integer] Transaction installments count.
31
- attr_accessor :installmentCount
32
-
33
- # @return [Integer] Card security code.
34
- attr_accessor :securityCode
35
-
36
- # @return [Integer] Code to select the payment method. Can be <i>Cielo<i>, <i>Redecard<i> and others.
37
- attr_accessor :paymentMethodCode
38
-
39
- # @return [String] Custom transaction identifier.
40
- attr_accessor :transactionReference
41
-
42
- # Fill this property when creating a recurrency transaction.
43
- # @return [Recurrency] Transaction recurrency information.
44
- attr_accessor :recurrency
45
-
46
- # Allowed card brands
47
- # @returns [Hash<Symbol, String>]
48
- @@CARD_BRAND = {
49
- :Visa => 'Visa',
50
- :Mastercard => 'Mastercard',
51
- :AmericanExpress => 'Amex',
52
- :Hipercard => 'Hipercard',
53
- :Diners => 'Diners',
54
- :Elo => 'Elo',
55
- :Aura => 'Aura',
56
- :Discover => 'Discover'
57
- }
58
-
59
- # Types of operation.
60
- # @returns [Hash<Symbol, String>]
61
- @@OPERATION = {
62
- :AuthOnly => 'AuthOnly',
63
- :AuthAndCapture => 'AuthAndCapture',
64
- :AuthAndCaptureWithDelay => 'AuthAndCaptureWithDelay'
65
- }
66
-
67
- # Allowed card brands
68
- # @returns [Hash<Symbol, String>]
69
- # @see @@CARD_BRAND
70
- def self.BrandEnum
71
- @@CARD_BRAND
72
- end
73
-
74
- # Allowed operations.
75
- # @returns [Hash<Symbol, String>]
76
- # @see @@OPERATION
77
- def self.OperationEnum
78
- @@OPERATION
79
- end
80
- end
81
- end
1
+ module Mundipagg
2
+ class CreditCardTransaction
3
+
4
+ # @return [Long] Transaction amount in cents
5
+ attr_accessor :amountInCents
6
+
7
+ # @return [String] Instant buy key
8
+ attr_accessor :instantBuyKey
9
+
10
+ # @return [String] Card brand. Use the static property <i>BrandEnum</i>.
11
+ # @see BrandEnum
12
+ attr_accessor :creditCardBrandEnum
13
+
14
+ # @return [String] Credit Card Number.
15
+ attr_accessor :creditCardNumber
16
+
17
+ # @return [String] Type of operation. Use the static property <i>OperationEnum</i>.
18
+ # @see OperationEnum
19
+ attr_accessor :creditCardOperationEnum
20
+
21
+ # @return [Integer] Credit card expiration month
22
+ attr_accessor :expirationMonth
23
+
24
+ # @return [Integer] Credit card expiration year
25
+ attr_accessor :expirationYear
26
+
27
+ # @return [Integer] Name in the credit card
28
+ attr_accessor :holderName
29
+
30
+ # @return [Integer] Transaction installments count.
31
+ attr_accessor :installmentCount
32
+
33
+ # @return [Integer] Card security code.
34
+ attr_accessor :securityCode
35
+
36
+ # @return [Integer] Code to select the payment method. Can be <i>Cielo<i>, <i>Redecard<i> and others.
37
+ attr_accessor :paymentMethodCode
38
+
39
+ # @return [String] Custom transaction identifier.
40
+ attr_accessor :transactionReference
41
+
42
+ # Fill this property when creating a recurrency transaction.
43
+ # @return [Recurrency] Transaction recurrency information.
44
+ attr_accessor :recurrency
45
+
46
+ # Allowed card brands
47
+ # @returns [Hash<Symbol, String>]
48
+ @@CARD_BRAND = {
49
+ :Visa => 'Visa',
50
+ :Mastercard => 'Mastercard',
51
+ :AmericanExpress => 'Amex',
52
+ :Hipercard => 'Hipercard',
53
+ :Diners => 'Diners',
54
+ :Elo => 'Elo',
55
+ :Aura => 'Aura',
56
+ :Discover => 'Discover'
57
+ }
58
+
59
+ # Types of operation.
60
+ # @returns [Hash<Symbol, String>]
61
+ @@OPERATION = {
62
+ :AuthOnly => 'AuthOnly',
63
+ :AuthAndCapture => 'AuthAndCapture',
64
+ :AuthAndCaptureWithDelay => 'AuthAndCaptureWithDelay'
65
+ }
66
+
67
+ # Allowed card brands
68
+ # @returns [Hash<Symbol, String>]
69
+ # @see @@CARD_BRAND
70
+ def self.BrandEnum
71
+ @@CARD_BRAND
72
+ end
73
+
74
+ # Allowed operations.
75
+ # @returns [Hash<Symbol, String>]
76
+ # @see @@OPERATION
77
+ def self.OperationEnum
78
+ @@OPERATION
79
+ end
80
+ end
81
+ end
@@ -1,52 +1,52 @@
1
- module Mundipagg
2
- class ManageOrderRequest
3
-
4
- # @return [Array] Credit card transaction collection
5
- attr_accessor :transactionCollection
6
-
7
- # @return [String] Operation enum
8
- attr_accessor :manageOrderOperationEnum
9
-
10
- # @return [Guid] MundiPagg merchant identification
11
- attr_accessor :merchantKey
12
-
13
- # @return [Guid] Unique order identification. Generated by MundiPagg.
14
- attr_accessor :orderKey
15
-
16
- # @return [String] Order identification.
17
- attr_accessor :orderReference
18
-
19
- # If not send, it will be generate automatically in the webservice and returned in response.
20
- # Web service request identification, it is used for investigate problems with webservice requests.
21
- # @return [Guid] Globally Unique Identifier.
22
- # @param Optional
23
- # @param Default: 00000000-0000-0000-0000-000000000000
24
- attr_accessor :requestKey
25
-
26
- # Initialize class and properties
27
- def initialize
28
- @transactionCollection = Array.new
29
- @requestKey = '00000000-0000-0000-0000-000000000000'
30
- end
31
-
32
- # Operations allowed
33
- @@Operation = {
34
- :Capture => 'Capture',
35
- :Void => 'Void'
36
- }
37
-
38
- # Hash collection with operations allowed
39
- def self.OperationEnum
40
- @@Operation
41
- end
42
- end
43
-
44
- class ManageTransactionRequest
45
- # @return [Long] Order amount in cents.
46
- attr_accessor :amountInCents
47
- # @return [Guid] Unique transacion identifier generated by MundiPagg.
48
- attr_accessor :transactionKey
49
- # @return [String] Custom transaction identifier.
50
- attr_accessor :transactionReference
51
- end
1
+ module Mundipagg
2
+ class ManageOrderRequest
3
+
4
+ # @return [Array] Credit card transaction collection
5
+ attr_accessor :transactionCollection
6
+
7
+ # @return [String] Operation enum
8
+ attr_accessor :manageOrderOperationEnum
9
+
10
+ # @return [Guid] MundiPagg merchant identification
11
+ attr_accessor :merchantKey
12
+
13
+ # @return [Guid] Unique order identification. Generated by MundiPagg.
14
+ attr_accessor :orderKey
15
+
16
+ # @return [String] Order identification.
17
+ attr_accessor :orderReference
18
+
19
+ # If not send, it will be generate automatically in the webservice and returned in response.
20
+ # Web service request identification, it is used for investigate problems with webservice requests.
21
+ # @return [Guid] Globally Unique Identifier.
22
+ # @param Optional
23
+ # @param Default: 00000000-0000-0000-0000-000000000000
24
+ attr_accessor :requestKey
25
+
26
+ # Initialize class and properties
27
+ def initialize
28
+ @transactionCollection = Array.new
29
+ @requestKey = '00000000-0000-0000-0000-000000000000'
30
+ end
31
+
32
+ # Operations allowed
33
+ @@Operation = {
34
+ :Capture => 'Capture',
35
+ :Void => 'Void'
36
+ }
37
+
38
+ # Hash collection with operations allowed
39
+ def self.OperationEnum
40
+ @@Operation
41
+ end
42
+ end
43
+
44
+ class ManageTransactionRequest
45
+ # @return [Long] Order amount in cents.
46
+ attr_accessor :amountInCents
47
+ # @return [Guid] Unique transacion identifier generated by MundiPagg.
48
+ attr_accessor :transactionKey
49
+ # @return [String] Custom transaction identifier.
50
+ attr_accessor :transactionReference
51
+ end
52
52
  end
@@ -1,27 +1,27 @@
1
- module Mundipagg
2
- class QueryOrderRequest
3
-
4
- # @return [Guid] MundiPagg merchant identification
5
- attr_accessor :merchantKey
6
-
7
- # @return [Guid] Unique order identification. Generated by MundiPagg.
8
- attr_accessor :orderKey
9
-
10
- # @return [String] Custom order identification.
11
- attr_accessor :orderReference
12
-
13
- # If not send, it will be generate automatically in the webservice and returned in response.
14
- # Web service request identification, it is used for investigate problems with webservice requests.
15
- # @return [Guid] Globally Unique Identifier.
16
- # @param Optional
17
- # @param Default: 00000000-0000-0000-0000-000000000000
18
- attr_accessor :requestKey
19
-
20
- # Initialize class and properties
21
- def initialize()
22
- @requestKey = '00000000-0000-0000-0000-000000000000'
23
- end
24
-
25
-
26
- end
1
+ module Mundipagg
2
+ class QueryOrderRequest
3
+
4
+ # @return [Guid] MundiPagg merchant identification
5
+ attr_accessor :merchantKey
6
+
7
+ # @return [Guid] Unique order identification. Generated by MundiPagg.
8
+ attr_accessor :orderKey
9
+
10
+ # @return [String] Custom order identification.
11
+ attr_accessor :orderReference
12
+
13
+ # If not send, it will be generate automatically in the webservice and returned in response.
14
+ # Web service request identification, it is used for investigate problems with webservice requests.
15
+ # @return [Guid] Globally Unique Identifier.
16
+ # @param Optional
17
+ # @param Default: 00000000-0000-0000-0000-000000000000
18
+ attr_accessor :requestKey
19
+
20
+ # Initialize class and properties
21
+ def initialize()
22
+ @requestKey = '00000000-0000-0000-0000-000000000000'
23
+ end
24
+
25
+
26
+ end
27
27
  end
@@ -1,38 +1,38 @@
1
- module Mundipagg
2
- # Class that hold recurrency transaction information
3
- class Recurrency
4
-
5
- # @return [Date] Date the first recurrency will be charged.
6
- attr_accessor :dateToStartBilling
7
-
8
- # @return [String] Indicating the recurrency frequency.
9
- # @see FrequencyEnum
10
- attr_accessor :frequencyEnum
11
-
12
- # @return [Integer] Recurrency interval.
13
- attr_accessor :interval
14
-
15
- # @return [Boolean] Indicates whether the One webservice will run an OneDollarAuth
16
- # to validate the credit card.
17
- attr_accessor :oneDollarAuth
18
-
19
- # @return [Integer] Number of recurrencies.
20
- attr_accessor :recurrences
21
-
22
- # Allowed recurrency frequency
23
- @@FREQUENCY = {
24
- :Monthly => 'Monthly',
25
- :Yearly => 'Yearly',
26
- :Daily => 'Daily'
27
- }
28
-
29
- # Initialize class and properties
30
- def initialize
31
- end
32
-
33
- # Allowed recurrency frequency
34
- def self.FrequencyEnum
35
- @@FREQUENCY
36
- end
37
- end
38
- end
1
+ module Mundipagg
2
+ # Class that hold recurrency transaction information
3
+ class Recurrency
4
+
5
+ # @return [Date] Date the first recurrency will be charged.
6
+ attr_accessor :dateToStartBilling
7
+
8
+ # @return [String] Indicating the recurrency frequency.
9
+ # @see FrequencyEnum
10
+ attr_accessor :frequencyEnum
11
+
12
+ # @return [Integer] Recurrency interval.
13
+ attr_accessor :interval
14
+
15
+ # @return [Boolean] Indicates whether the One webservice will run an OneDollarAuth
16
+ # to validate the credit card.
17
+ attr_accessor :oneDollarAuth
18
+
19
+ # @return [Integer] Number of recurrencies.
20
+ attr_accessor :recurrences
21
+
22
+ # Allowed recurrency frequency
23
+ @@FREQUENCY = {
24
+ :Monthly => 'Monthly',
25
+ :Yearly => 'Yearly',
26
+ :Daily => 'Daily'
27
+ }
28
+
29
+ # Initialize class and properties
30
+ def initialize
31
+ end
32
+
33
+ # Allowed recurrency frequency
34
+ def self.FrequencyEnum
35
+ @@FREQUENCY
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,15 @@
1
+ module Mundipagg
2
+ class ShoppingCart
3
+
4
+ # @return [Integer] Freight value in cents
5
+ attr_accessor :freightCostInCents
6
+
7
+ # @return [Array] Array of ShopCartItens
8
+ attr_accessor :shoppingCartItemCollection
9
+
10
+ def initialize
11
+ @shoppingCartItemCollection = Array.new
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ module Mundipagg
2
+ class ShoppingCartItem
3
+
4
+ # @return [string] Item identifier
5
+ attr_accessor :itemReference
6
+
7
+ # @return [string] Item description
8
+ attr_accessor :description
9
+
10
+ # @return [string] Item name
11
+ attr_accessor :name
12
+
13
+ # @return [Integer] Quantity of itens
14
+ attr_accessor :quantity
15
+
16
+ # @return [long] Total in cents of all itens
17
+ attr_accessor :totalCostInCents
18
+
19
+ # @return [long] Item cost in cents
20
+ attr_accessor :unitCostInCents
21
+
22
+ end
23
+ end
@@ -1,365 +1,400 @@
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://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
-
138
- if request.amountInCentsToConsiderPaid == nil
139
- xml_hash['mun:AmountInCentsToConsiderPaid'] = request.amountInCents
140
- else
141
- xml_hash['mun:AmountInCentsToConsiderPaid'] = request.amountInCentsToConsiderPaid
142
- end
143
-
144
- xml_hash['mun:CurrencyIsoEnum'] = request.currencyIsoEnum
145
- xml_hash['mun:MerchantKey'] = request.merchantKey
146
- xml_hash['mun:OrderReference'] = request.orderReference
147
- xml_hash['mun:RequestKey'] = request.requestKey
148
-
149
- if request.buyer.nil? == false
150
- xml_hash['mun:Buyer'] = CreateBuyer(request)
151
- end
152
-
153
- if not request.creditCardTransactionCollection.nil? and request.creditCardTransactionCollection.count > 0
154
- #Create credit card transaction array and assing to the contract hash
155
- creditCardTransactionCollection = CreateCreditCardTransaction(request)
156
- xml_hash['mun:CreditCardTransactionCollection'] = creditCardTransactionCollection
157
- else
158
- xml_hash['mun:CreditCardTransactionCollection'] = nil
159
- end
160
-
161
- if request.boletoTransactionCollection.nil? == false and request.boletoTransactionCollection.count > 0
162
- #Create boleto transaction array and assing to the contract hash
163
- boletoTransactionCollection = CreateBoletoTransactionRequest(request);
164
- xml_hash['mun:BoletoTransactionCollection'] = boletoTransactionCollection
165
- end
166
-
167
- response = SendToService(hash, :create_order)
168
-
169
-
170
- return response
171
-
172
- end
173
-
174
-
175
- # This method create a hash collection with all buyer information.
176
- # The hash collection is a part of the data send to the webservice.
177
- #
178
- # @param request [CreateOrderRequest]
179
- # @return [Hash<Symbol, Object>] Hash collection with buyer information.
180
- # @!visibility private
181
- def CreateBuyer(request)
182
-
183
- buyer = {
184
- 'mun:BuyerKey' => request.buyer.buyerKey,
185
- 'mun:BuyerReference' => request.buyer.buyerReference,
186
- 'mun:Email' => request.buyer.email,
187
- 'mun:GenderEnum' => request.buyer.genderEnum,
188
- 'mun:FacebookId' => request.buyer.facebookId,
189
- 'mun:GenderEnum' => request.buyer.genderEnum,
190
- 'mun:HomePhone' => request.buyer.homePhone,
191
- 'mun:IpAddress' => request.buyer.ipAddress,
192
- 'mun:MobilePhone' => request.buyer.mobilePhone,
193
- 'mun:Name' => request.buyer.name,
194
- 'mun:PersonTypeEnum' => request.buyer.personTypeEnum,
195
- 'mun:TaxDocumentNumber' => request.buyer.taxDocumentNumber,
196
- 'mun:TaxDocumentNumberTypeEnum' => request.buyer.taxDocumentTypeEnum,
197
- 'mun:TwitterId' => request.buyer.twitterId,
198
- 'mun:WorkPhone' => request.buyer.workPhone,
199
- 'mun:BuyerAddressCollection' => nil
200
-
201
- }
202
-
203
- if request.buyer.addressCollection.count > 0
204
-
205
- buyer['mun:BuyerAddressCollection'] = {'mun:BuyerAddress'=>Array.new}
206
-
207
- request.buyer.addressCollection.each do |address|
208
-
209
- buyer['mun:BuyerAddressCollection']['mun:BuyerAddress'] << {
210
- 'mun:AddressTypeEnum' => address.addressTypeEnum,
211
- 'mun:City' => address.city,
212
- 'mun:Complement' => address.complement,
213
- 'mun:CountryEnum' => address.countryEnum,
214
- 'mun:District' => address.district,
215
- 'mun:Number' => address.number,
216
- 'mun:State' => address.state,
217
- 'mun:Street' => address.street,
218
- 'mun:ZipCode' => address.zipCode
219
- }
220
-
221
- end
222
- end
223
-
224
- return buyer
225
- end
226
-
227
- # This method create a hash collection with all boleto transactions information.
228
- # The hash collection is a part of the data send to the webservice.
229
- #
230
- # @param boletoRequest [Array<BoletoTransaction>] CreateOrderRequest instance
231
- # @return [Hash<Symbol, Object>] Hash collection with one or more boleto transactions.
232
- # @!visibility private
233
- def CreateBoletoTransactionRequest(boletoRequest)
234
-
235
- transactionCollection = {'mun:BoletoTransaction' => Array.new}
236
-
237
- boletoRequest.boletoTransactionCollection.each do |boleto|
238
-
239
- transactionCollection['mun:BoletoTransaction'] << {
240
- 'mun:AmountInCents' => boleto.amountInCents,
241
- 'mun:BankNumber' => boleto.bankNumber,
242
- 'mun:DaysToAddInBoletoExpirationDate' => boleto.daysToAddInBoletoExpirationDate,
243
- 'mun:Instructions' => boleto.instructions,
244
- 'mun:NossoNumero' => boleto.nossoNumero,
245
- 'mun:TransactionReference' => boleto.transactionReference,
246
-
247
- }
248
-
249
- end
250
-
251
- return transactionCollection
252
- end
253
-
254
- # This method create a hash collection with all credit card transactions information.
255
- # The hash collection is a part of the data send to the webservice.
256
- #
257
- # @param creditCardRequest [Array<CreditCardTransaction>] CreateOrderRequest instance
258
- # @return [Hash<Symbol, Object>] Hash collection with one or more credit card transactions.
259
- # @!visibility private
260
- def CreateCreditCardTransaction(creditCardRequest)
261
-
262
- transactionCollection = {'mun:CreditCardTransaction' => Array.new}
263
-
264
- creditCardRequest.creditCardTransactionCollection.each do |transaction|
265
-
266
- if environment == :test
267
- transaction.paymentMethodCode = 1 # Simulator payment code
268
- end
269
-
270
- transaction_hash = if transaction.instantBuyKey
271
- {
272
- 'mun:AmountInCents' => transaction.amountInCents,
273
- 'mun:CreditCardBrandEnum' => transaction.creditCardBrandEnum.to_s,
274
- 'mun:InstantBuyKey' => transaction.instantBuyKey,
275
- 'mun:CreditCardOperationEnum' => transaction.creditCardOperationEnum.to_s,
276
- 'mun:InstallmentCount' => transaction.installmentCount,
277
- 'mun:PaymentMethodCode' => transaction.paymentMethodCode,
278
- 'mun:TransactionReference' => transaction.transactionReference
279
- }
280
- else
281
- {
282
- 'mun:AmountInCents' => transaction.amountInCents,
283
- 'mun:CreditCardBrandEnum' => transaction.creditCardBrandEnum.to_s,
284
- 'mun:CreditCardNumber' => transaction.creditCardNumber,
285
- 'mun:CreditCardOperationEnum' => transaction.creditCardOperationEnum.to_s,
286
- 'mun:ExpMonth' => transaction.expirationMonth,
287
- 'mun:ExpYear' => transaction.expirationYear,
288
- 'mun:HolderName' => transaction.holderName,
289
- 'mun:InstallmentCount' => transaction.installmentCount,
290
- 'mun:PaymentMethodCode' => transaction.paymentMethodCode,
291
- 'mun:SecurityCode' => transaction.securityCode,
292
- 'mun:TransactionReference' => transaction.transactionReference
293
- }
294
- end
295
-
296
- if transaction.recurrency.nil? == false
297
-
298
- transaction_hash['mun:Recurrency'] = {
299
- 'mun:DateToStartBilling' => transaction.recurrency.dateToStartBilling,
300
- 'mun:FrequencyEnum' => transaction.recurrency.frequencyEnum,
301
- 'mun:Interval' => transaction.recurrency.interval,
302
- 'mun:OneDollarAuth' => transaction.recurrency.oneDollarAuth,
303
- 'mun:Recurrences' => transaction.recurrency.recurrences
304
- }
305
- end
306
-
307
- transactionCollection['mun:CreditCardTransaction'] << transaction_hash
308
- end
309
-
310
- return transactionCollection
311
- end
312
-
313
-
314
- # This method send the hash collectin created in this client and send it to the webservice.
315
- #
316
- # == Parameters:
317
- # @param hash [Hash<Symbol, Object] Hash collection generated by Nori using the base SOAP XML.
318
- # @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>.
319
- # @return [Hash<Symbol, Object>] A hash collection with the service method response.
320
- # @!visibility private
321
- def SendToService(hash, service_method)
322
-
323
- url = nil
324
-
325
- if @environment == :production
326
- url = @@WEBSERVICE_PRODUCTION_URL
327
- else
328
- url = @@WEBSERVICE_TEST_URL
329
- end
330
- savon_levels = { :none => -1, :debug => 0, :info => 1, :warn => 2, :error => 3 }
331
-
332
- if not savon_levels.include? @log_level
333
- @log_level = :none
334
- end
335
-
336
- level = :debug
337
- enable_log = true
338
- filters = [:CreditCardNumber,
339
- :SecurityCode,
340
- :MerchantKey]
341
-
342
- if @log_level == :none
343
- level = :error
344
- enable_log = false
345
- end
346
-
347
-
348
- client = Savon.client do
349
- wsdl url
350
- log enable_log
351
- log_level level
352
- filters filters
353
- namespaces 'xmlns:mun' => 'http://schemas.datacontract.org/2004/07/MundiPagg.One.Service.DataContracts'
354
- end
355
-
356
- response = client.call(service_method) do
357
- message hash
358
- end
359
-
360
- return response.to_hash
361
- end
362
-
363
- private :CreateBoletoTransactionRequest, :CreateCreditCardTransaction, :CreateBuyer, :SendToService, :parser
364
- end
365
- 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://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: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:TaxDocumentNumberTypeEnum' => 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
+ namespaces 'xmlns:mun' => 'http://schemas.datacontract.org/2004/07/MundiPagg.One.Service.DataContracts'
389
+ end
390
+
391
+ response = client.call(service_method) do
392
+ message hash
393
+ end
394
+
395
+ return response.to_hash
396
+ end
397
+
398
+ private :CreateBoletoTransactionRequest, :CreateCreditCardTransaction, :CreateBuyer, :SendToService, :parser
399
+ end
400
+ end