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



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/active_merchant/billing/integrations/sage_pay_form/helper.rb', line 61

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"

  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)

  result = {
    'VPSProtocol' => '2.23',
    'TxType' => 'PAYMENT',
    'Vendor' => @fields['Vendor'],
    'Crypt'  => @crypt
  }
  result['ReferrerID'] = referrer_id if referrer_id
  result
end

#map_billing_address_to_shipping_addressObject



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

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



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

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