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 collapse

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, mapping, #raw_html_fields, #test?

Methods included from MoneyCompatibility

#to_cents

Constructor Details

#initialize(order, account, options = {}) ⇒ Helper

Returns a new instance of Helper.



74
75
76
77
78
79
# File 'lib/offsite_payments/integrations/sage_pay_form.rb', line 74

def initialize(order, , options={})
  @shipping_address_set = nil
  super
  @identifier = rand(0..99999).to_s.rjust(5, '0')
  add_field 'VendorTxCode', "#{order}-#{@identifier}"
end

Dynamic Method Handling

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

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier.



72
73
74
# File 'lib/offsite_payments/integrations/sage_pay_form.rb', line 72

def identifier
  @identifier
end

Instance Method Details

#form_fieldsObject



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

def form_fields
  fields.delete('locale')

  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



124
125
126
127
128
# File 'lib/offsite_payments/integrations/sage_pay_form.rb', line 124

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



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

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