Class: ActiveMerchant::Billing::Integrations::SagePayForm::Helper

Inherits:
Helper
  • Object
show all
Includes:
Encryption
Defined in:
lib/active_merchant/billing/integrations/sage_pay_form/helper.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, #initialize, mapping, #raw_html_fields, #test?

Constructor Details

This class inherits a constructor from ActiveMerchant::Billing::Integrations::Helper

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActiveMerchant::Billing::Integrations::Helper

Instance Method Details

#form_fieldsObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/active_merchant/billing/integrations/sage_pay_form/helper.rb', line 59

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']

  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' => '2.23',
    'TxType' => 'PAYMENT',
    'Vendor' => @fields['Vendor'],
    'Crypt'  => @crypt
  }
end

#map_billing_address_to_shipping_addressObject



53
54
55
56
57
# File 'lib/active_merchant/billing/integrations/sage_pay_form/helper.rb', line 53

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



44
45
46
47
48
49
50
51
# File 'lib/active_merchant/billing/integrations/sage_pay_form/helper.rb', line 44

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