Class: Mundipagg::Gateway

Inherits:
Object
  • Object
show all
Defined in:
lib/mundipagg/gateway.rb

Overview

Class that handles all webservice calls

Constant Summary collapse

@@WEBSERVICE_TEST_URL =

Returns URL that points to the simulator WSDL

Returns:

  • (String)

    URL that points to the simulator WSDL

'https://transaction.mundipaggone.com/MundiPaggService.svc?wsdl'
@@WEBSERVICE_PRODUCTION_URL =

Returns URL that points to the production WSDL

Returns:

  • (String)

    URL that points to the production WSDL

'https://transaction.mundipaggone.com/MundiPaggService.svc?wsdl'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment = :test) ⇒ Gateway

Initialize a class with an environment

Parameters:

  • environment (Symbol) (defaults to: :test)

    Sets the MundiPagg environment will be used by the client.


30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/mundipagg/gateway.rb', line 30

def initialize(environment=:test)
	@parser = Nori.new(:convert_tags_to => lambda { |tag| tag })
	@environment = environment

	if environment == :test
		@log_level = :debug
	else
		@log_level = :error
	end


end

Instance Attribute Details

#environmentSymbol

:test = Simulator enviroment, fake transaction approval; :production = Real transaction, needs real credit card.

Returns:

  • (Symbol)

    Webservice environment.


19
20
21
# File 'lib/mundipagg/gateway.rb', line 19

def environment
  @environment
end

#log_levelObject

Sets the soap request log level. Can be: { :debug, :info, :warn, :error or :none } Use :debug only to inspect the Xml sent and received to the service. Default in test environment => :debug Default in production environment => :none


10
11
12
# File 'lib/mundipagg/gateway.rb', line 10

def log_level
  @log_level
end

Instance Method Details

#CreateOrder(request) ⇒ Hash<Symbol, Object>

This method makes requests to the webservice method CreateOrder.

Parameters:

  • request (CreateOrderRequest)

    A CreateOrderRequest instance containing information to create a order.

Returns:

  • (Hash<Symbol, Object>)

    A hash collection containing the response data


116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/mundipagg/gateway.rb', line 116

def CreateOrder(request)

	hash = @parser.parse('
					 <tns:createOrderRequest>
							<mun:AmountInCents>?</mun:AmountInCents>
							<mun:AmountInCentsToConsiderPaid>?</mun:AmountInCentsToConsiderPaid>
							<mun:CurrencyIsoEnum>?</mun:CurrencyIsoEnum>
							<mun:MerchantKey>?</mun:MerchantKey>
							<mun:OrderReference>?</mun:OrderReference>
							<mun:RequestKey>?</mun:RequestKey>
							<mun:Buyer>
							</mun:Buyer>
							<mun:ShoppingCartCollection>
							</mun:ShoppingCartCollection>
							<mun:CreditCardTransactionCollection>
							</mun:CreditCardTransactionCollection>
							<mun:BoletoTransactionCollection>
							</mun:BoletoTransactionCollection>
					 </tns:createOrderRequest>')

	xml_hash = hash['tns:createOrderRequest'];

	xml_hash['mun:AmountInCents'] = request.amountInCents

	if request.amountInCentsToConsiderPaid == nil
		xml_hash['mun:AmountInCentsToConsiderPaid'] = request.amountInCents
	else
		xml_hash['mun:AmountInCentsToConsiderPaid'] = request.amountInCentsToConsiderPaid
	end

	xml_hash['mun:CurrencyIsoEnum'] = request.currencyIsoEnum
	xml_hash['mun:MerchantKey'] = request.merchantKey
	xml_hash['mun:OrderReference'] = request.orderReference
	xml_hash['mun:RequestKey'] = request.requestKey

	if request.buyer.nil? == false
		xml_hash['mun:Buyer'] = CreateBuyer(request)
	end

	if not request.shoppingCartCollection.nil? and request.shoppingCartCollection.count > 0
		xml_hash['mun:ShoppingCartCollection'] = CreateShoppingCart(request)
	end

	if not request.creditCardTransactionCollection.nil? and request.creditCardTransactionCollection.count > 0
		#Create credit card transaction array and assing to the contract hash
		creditCardTransactionCollection = CreateCreditCardTransaction(request)
		xml_hash['mun:CreditCardTransactionCollection'] = creditCardTransactionCollection
	else
		xml_hash['mun:CreditCardTransactionCollection'] = nil
	end

	if request.boletoTransactionCollection.nil? == false and request.boletoTransactionCollection.count > 0
		#Create boleto transaction array and assing to the contract hash
		boletoTransactionCollection = CreateBoletoTransactionRequest(request);
		xml_hash['mun:BoletoTransactionCollection'] = boletoTransactionCollection
	end

	response = SendToService(hash, :create_order)


	return response

end

#CreateShoppingCart(request) ⇒ Object


232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/mundipagg/gateway.rb', line 232

def CreateShoppingCart(request)

	shoppingCartColl = {'mun:ShoppingCart' => Array.new}

	shoppingCartItemCollection = {'mun:ShoppingCartItem' => Array.new}

	request.shoppingCartCollection.each do |shoppingCart|

		shoppingCart.shoppingCartItemCollection.each do |shoppingCartItem|
			shoppingCartItemCollection['mun:ShoppingCartItem'] << {
				'mun:Description' => shoppingCartItem.description,
				'mun:ItemReference' => shoppingCartItem.itemReference,
				'mun:Name' => shoppingCartItem.name,
				'mun:Quantity' => shoppingCartItem.quantity,
				'mun:TotalCostInCents' => shoppingCartItem.totalCostInCents,
				'mun:UnitCostInCents' => shoppingCartItem.unitCostInCents
			}
		end

		shoppingCartColl['mun:ShoppingCart'] << {
			'mun:FreightCostInCents' => shoppingCart.freightCostInCents,
			'mun:ShoppingCartItemCollection' => shoppingCartItemCollection
		}

	end

	return shoppingCartColl

end

#ManageOrder(request) ⇒ Hash<Symbol, Object>

This method makes requests to the webservice method ManageOrder.

Parameters:

  • request (CreateOrderRequest)

    A ManagerOrderRequest instance containing information to capture or void a transaction or order.

Returns:

  • (Hash<Symbol, Object>)

    A hash collection containing the response data


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/mundipagg/gateway.rb', line 47

def ManageOrder(request)

hash = @parser.parse('<tns:manageOrderRequest>
						<mun:ManageCreditCardTransactionCollection>
						</mun:ManageCreditCardTransactionCollection>
						<mun:ManageOrderOperationEnum>?</mun:ManageOrderOperationEnum>
						<mun:MerchantKey>?</mun:MerchantKey>
						<mun:OrderKey>?</mun:OrderKey>
						<mun:OrderReference>?</mun:OrderReference>
						<mun:RequestKey>?</mun:RequestKey>
					</tns:manageOrderRequest>')

xml_hash = hash['tns:manageOrderRequest'];

xml_hash['mun:ManageCreditCardTransactionCollection'] = {'mun:ManageCreditCardTransactionRequest'=>Array.new}

if request.transactionCollection.nil? == false and request.transactionCollection.count > 0

	request.transactionCollection.each do |transaction|

		xml_hash['mun:ManageCreditCardTransactionCollection']['mun:ManageCreditCardTransactionRequest'] << {
			'mun:AmountInCents' => transaction.amountInCents,
			'mun:TransactionKey' => transaction.transactionKey,
			'mun:TransactionReference' => transaction.transactionReference
		}
	end
end

xml_hash['mun:ManageOrderOperationEnum'] = request.manageOrderOperationEnum
xml_hash['mun:MerchantKey'] = request.merchantKey
xml_hash['mun:OrderKey'] = request.orderKey
xml_hash['mun:OrderReference'] = request.orderReference
xml_hash['mun:RequestKey'] = request.requestKey

response = SendToService(hash, :manage_order)

return response

end

#QueryOrder(request) ⇒ Hash<Symbol, Object>

This method makes requests to the webservice method QueryOrder.

Parameters:

  • request (QueryOrderRequest)

    A QueryOrderRequest instance containing information to request more information about an order or transaction.

Returns:

  • (Hash<Symbol, Object>)

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/mundipagg/gateway.rb', line 91

def QueryOrder(request)

	hash = @parser.parse('<tns:queryOrderRequest>
			<mun:MerchantKey>?</mun:MerchantKey>
			<mun:OrderKey>?</mun:OrderKey>
			<mun:OrderReference>?</mun:OrderReference>
			<mun:RequestKey>?</mun:RequestKey>
		</tns:queryOrderRequest>')

	xml_hash = hash['tns:queryOrderRequest'];

	xml_hash['mun:MerchantKey'] = request.merchantKey
	xml_hash['mun:OrderKey'] = request.orderKey
	xml_hash['mun:OrderReference'] = request.orderReference
	xml_hash['mun:RequestKey'] = request.requestKey

	response = SendToService(hash, :query_order)

	return response
end