Class: OffsitePayments::Integrations::SagePayForm::Helper

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

Instance Attribute Summary

Attributes inherited from Helper

#fields

Instance Method Summary collapse

Methods included from Encryption

#sage_decrypt, #sage_encrypt, #sage_encrypt_salt

Methods inherited from Helper

#add_field, #add_fields, #add_raw_html_field, #billing_address, #form_method, inherited, #initialize, mapping, #raw_html_fields, #test?

Constructor Details

This class inherits a constructor from OffsitePayments::Helper

Dynamic Method Handling

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

Instance Method Details

#form_fieldsObject


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
# File 'lib/offsite_payments/integrations/sage_pay_form.rb', line 123

def form_fields
  map_billing_address_to_shipping_address unless @shipping_address_set

  fields['DeliveryFirstnames'] ||= fields['BillingFirstnames']
  fields['DeliverySurname']    ||= fields['BillingSurname']

  fields['FailureURL'] ||= fields['SuccessURL']

  fields['BillingPostCode'] ||= "0000"
  fields['DeliveryPostCode'] ||= "0000"

  fields['ReferrerID'] = referrer_id if referrer_id

  crypt_skip = ['Vendor', 'EncryptKey', 'SendEmail']
  crypt_skip << 'BillingState'  unless fields['BillingCountry']  == 'US'
  crypt_skip << 'DeliveryState' unless fields['DeliveryCountry'] == 'US'
  crypt_skip << 'CustomerEMail' unless fields['SendEmail']
  key = fields['EncryptKey']
  @crypt ||= create_crypt_field(fields.except(*crypt_skip), key)

  {
    'VPSProtocol' => '3.00',
    'TxType' => 'PAYMENT',
    'Vendor' => @fields['Vendor'],
    'Crypt'  => @crypt
  }
end

#map_billing_address_to_shipping_addressObject


117
118
119
120
121
# File 'lib/offsite_payments/integrations/sage_pay_form.rb', line 117

def map_billing_address_to_shipping_address
  %w(City Address1 Address2 State PostCode Country).each do |field|
    fields["Delivery#{field}"] = fields["Billing#{field}"]
  end
end

#shipping_address(params = {}) ⇒ Object


108
109
110
111
112
113
114
115
# File 'lib/offsite_payments/integrations/sage_pay_form.rb', line 108

def shipping_address(params = {})
  @shipping_address_set = true unless params.empty?

  params.each do |k, v|
    field = mappings[:shipping_address][k]
    add_field(field, v) unless field.nil?
  end
end