Class: OffsitePayments::Integrations::RealexOffsite::Helper
- Inherits:
-
Helper
- Object
- Helper
- OffsitePayments::Integrations::RealexOffsite::Helper
show all
- Includes:
- Common
- Defined in:
- lib/offsite_payments/integrations/realex_offsite.rb
Constant Summary
Constants included
from Common
Common::CANADIAN_STATES, Common::CURRENCY_SPECIAL_MINOR_UNITS, Common::US_STATES
Instance Attribute Summary
Attributes inherited from Helper
#fields
Instance Method Summary
collapse
Methods included from Common
#copy_billing_address, #create_signature, #extract_address_match_indicator, #extract_avs_code, #extract_digits, #format_amount, #format_amount_as_float, #format_phone_number, #lookup_state_code
Methods inherited from Helper
#add_field, #add_fields, #add_raw_html_field, #form_method, inherited, mapping, #raw_html_fields, #test?
Constructor Details
#initialize(order, account, options = {}) ⇒ Helper
Returns a new instance of Helper.
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
# File 'lib/offsite_payments/integrations/realex_offsite.rb', line 223
def initialize(order, account, options = {})
@timestamp = Time.now.strftime('%Y%m%d%H%M%S')
@currency = options[:currency]
@merchant_id = account
@sub_account = options[:credential2]
@secret = options[:credential3]
super
add_field 'MERCHANT_ID', @merchant_id
add_field 'ACCOUNT', @sub_account
add_field 'AUTO_SETTLE_FLAG', '1'
add_field 'RETURN_TSS', '1'
add_field 'TIMESTAMP', @timestamp
add_field 'HPP_VERSION', '2'
add_field 'X-CURRENCY', @currency
add_field 'X-TEST', @test.to_s
add_field 'ORDER_ID', "#{order}#{@timestamp.to_i}"
add_field 'COMMENT1', application_id
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class OffsitePayments::Helper
Instance Method Details
#addresses_match(address_match = nil) ⇒ Object
285
286
287
288
289
290
291
292
293
294
|
# File 'lib/offsite_payments/integrations/realex_offsite.rb', line 285
def addresses_match(address_match = nil)
return if address_match.nil?
add_field(
mappings[:addresses_match],
(address_match)
)
copy_billing_address if address_match
end
|
#amount=(amount) ⇒ Object
250
251
252
|
# File 'lib/offsite_payments/integrations/realex_offsite.rb', line 250
def amount=(amount)
add_field 'AMOUNT', format_amount(amount, @currency)
end
|
#billing_address(params = {}) ⇒ Object
254
255
256
257
258
259
260
261
262
263
264
265
|
# File 'lib/offsite_payments/integrations/realex_offsite.rb', line 254
def billing_address(params={})
country = params[:country]
country_code = lookup_country_code(country, :alpha2)
super
add_field(mappings[:billing_address][:zip], (params))
add_field(mappings[:billing_address][:country], lookup_country_code(country))
if ['US', 'CA'].include?(country_code) && params[:state].length > 2
add_field(mappings[:billing_address][:state], lookup_state_code(country_code, params[:state]))
end
end
|
296
297
298
|
# File 'lib/offsite_payments/integrations/realex_offsite.rb', line 296
def ( = nil)
add_field(mappings[:comment], )
end
|
#customer(params = {}) ⇒ Object
280
281
282
283
|
# File 'lib/offsite_payments/integrations/realex_offsite.rb', line 280
def customer(params={})
super
add_field(mappings[:customer][:phone], format_phone_number(params[:phone]))
end
|
246
247
248
|
# File 'lib/offsite_payments/integrations/realex_offsite.rb', line 246
def form_fields
sign_fields
end
|
#generate_signature ⇒ Object
314
315
316
317
318
319
320
321
|
# File 'lib/offsite_payments/integrations/realex_offsite.rb', line 314
def generate_signature
fields_to_sign = []
['TIMESTAMP', 'MERCHANT_ID', 'ORDER_ID', 'AMOUNT', 'CURRENCY'].each do |field|
fields_to_sign << @fields[field]
end
create_signature(fields_to_sign, @secret)
end
|
#require_shipping(require_shipping = nil) ⇒ Object
HPP does not want shipping address and HPP_ADDRESS_MATCH_INDICATOR to be sent if the product does not require shipping
302
303
304
305
306
307
308
|
# File 'lib/offsite_payments/integrations/realex_offsite.rb', line 302
def require_shipping(require_shipping = nil)
return unless require_shipping == false
@fields.delete_if do |k, _|
k.start_with?('HPP_SHIPPING_') || k == 'HPP_ADDRESS_MATCH_INDICATOR'
end
end
|
#shipping_address(params = {}) ⇒ Object
267
268
269
270
271
272
273
274
275
276
277
278
|
# File 'lib/offsite_payments/integrations/realex_offsite.rb', line 267
def shipping_address(params={})
country = params[:country]
country_code = lookup_country_code(country, :alpha2)
super
add_field(mappings[:shipping_address][:zip], (params))
add_field(mappings[:shipping_address][:country], lookup_country_code(params[:country]))
if ['US', 'CA'].include?(country_code) && params[:state].length > 2
add_field(mappings[:shipping_address][:state], lookup_state_code(country_code, params[:state]))
end
end
|
#sign_fields ⇒ Object
310
311
312
|
# File 'lib/offsite_payments/integrations/realex_offsite.rb', line 310
def sign_fields
@fields.merge!('SHA1HASH' => generate_signature)
end
|