Class: OffsitePayments::Integrations::Realex::Helper

Inherits:
Helper
  • Object
show all
Includes:
Common
Defined in:
lib/offsite_payments/integrations/realex.rb

Constant Summary

Constants included from Common

Common::CURRENCY_SPECIAL_MINOR_UNITS

Instance Attribute Summary

Attributes inherited from Helper

#fields

Instance Method Summary collapse

Methods included from Common

#create_signature, #extract_avs_code, #extract_digits, #format_amount, #format_amount_as_float

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


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/offsite_payments/integrations/realex.rb', line 103

def initialize(order, , options = {})
  @timestamp   = Time.now.strftime('%Y%m%d%H%M%S')
  @currency    = options[:currency]
  @merchant_id = options[:credential2]
   = options[:credential3]
  @secret      = options[:credential4]
  super
  # Credentials
  add_field 'MERCHANT_ID', @merchant_id
  add_field 'ACCOUNT', 
  # Defaults
  add_field 'AUTO_SETTLE_FLAG', '1'
  add_field 'RETURN_TSS', '1'
  add_field 'TIMESTAMP', @timestamp
  # Realex does not send back CURRENCY param in response
  # however it does echo any other param so we send it twice.
  add_field 'X-CURRENCY', @currency
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class OffsitePayments::Helper

Instance Method Details

#amount=(amount) ⇒ Object


126
127
128
# File 'lib/offsite_payments/integrations/realex.rb', line 126

def amount=(amount)
  add_field 'AMOUNT', format_amount(amount, @currency)
end

#billing_address(params = {}) ⇒ Object


130
131
132
133
# File 'lib/offsite_payments/integrations/realex.rb', line 130

def billing_address(params={})
  add_field(mappings[:billing_address][:zip], extract_avs_code(params))
  add_field(mappings[:billing_address][:country], lookup_country_code(params[:country]))
end

#form_fieldsObject


122
123
124
# File 'lib/offsite_payments/integrations/realex.rb', line 122

def form_fields
  sign_fields
end

#generate_signatureObject


144
145
146
147
148
149
150
151
# File 'lib/offsite_payments/integrations/realex.rb', line 144

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

#shipping_address(params = {}) ⇒ Object


135
136
137
138
# File 'lib/offsite_payments/integrations/realex.rb', line 135

def shipping_address(params={})
  add_field(mappings[:shipping_address][:zip], extract_avs_code(params))
  add_field(mappings[:shipping_address][:country], lookup_country_code(params[:country]))
end

#sign_fieldsObject


140
141
142
# File 'lib/offsite_payments/integrations/realex.rb', line 140

def sign_fields
  @fields.merge!('SHA1HASH' => generate_signature)
end