Class: OffsitePayments::Integrations::WorldPay::Helper

Inherits:
Helper
  • Object
show all
Defined in:
lib/offsite_payments/integrations/world_pay.rb

Instance Attribute Summary

Attributes inherited from Helper

#fields

Instance Method Summary collapse

Methods inherited from Helper

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

Methods included from MoneyCompatibility

#to_cents

Constructor Details

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

WorldPay supports two different test modes - :always_succeed and :always_fail



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/offsite_payments/integrations/world_pay.rb', line 50

def initialize(order, , options = {})
  super

  if OffsitePayments.mode == :test || options[:test]
    test_mode = case options[:test]
    when :always_fail
      101
    when false
      0
    else
      100
    end
    add_field('testMode', test_mode.to_s)
  elsif OffsitePayments.mode == :always_succeed
    add_field('testMode', '100')
  elsif OffsitePayments.mode == :always_fail
    add_field('testMode', '101')
  end
end

Dynamic Method Handling

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

Instance Method Details

#callback_params(params = {}) ⇒ Object



107
108
109
# File 'lib/offsite_payments/integrations/world_pay.rb', line 107

def callback_params(params={})
  params.each{|k,v| add_field("M_#{k}",v)}
end

#combined_params(params = {}) ⇒ Object



111
112
113
# File 'lib/offsite_payments/integrations/world_pay.rb', line 111

def combined_params(params={})
  params.each{|k,v| add_field("MC_#{k}",v)}
end

#customer(params = {}) ⇒ Object

WorldPay only supports a single name field so we have to concat



71
72
73
74
75
# File 'lib/offsite_payments/integrations/world_pay.rb', line 71

def customer(params={})
  add_field(mappings[:customer][:email], params[:email])
  add_field(mappings[:customer][:phone], params[:phone])
  add_field('name', "#{params[:first_name]} #{params[:last_name]}")
end

#encrypt(secret, fields = [:amount, :currency, :account, :order]) ⇒ Object

Support for a MD5 hash of selected fields to prevent tampering For further information read the tech note at the address below: support.worldpay.com/kb/integration_guides/junior/integration/help/tech_notes/sjig_tn_009.html



80
81
82
83
84
85
86
87
# File 'lib/offsite_payments/integrations/world_pay.rb', line 80

def encrypt(secret, fields = [:amount, :currency, :account, :order])
  signature_fields = fields.collect{ |field| mappings[field] }
  add_field('signatureFields', signature_fields.join(':'))

  field_values = fields.collect{ |field| form_fields[mappings[field]] }
  signature    = "#{secret}:#{field_values.join(':')}"
  add_field('signature', Digest::MD5.hexdigest(signature))
end

#response_params(params = {}) ⇒ Object

WorldPay supports the passing of custom parameters prefixed with the following: C_ : These parameters can be used in the response pages hosted on WorldPay’s site M_ : These parameters are passed through to the callback script (if enabled) MC_ or CM_ : These parameters are availble both in the response and callback contexts



103
104
105
# File 'lib/offsite_payments/integrations/world_pay.rb', line 103

def response_params(params={})
  params.each{|k,v| add_field("C_#{k}",v)}
end

#valid_from(from_time) ⇒ Object

Add a time window for which the payment can be completed. Read the link below for how they work support.worldpay.com/kb/integration_guides/junior/integration/help/appendicies/sjig_10100.html



91
92
93
# File 'lib/offsite_payments/integrations/world_pay.rb', line 91

def valid_from(from_time)
  add_field('authValidFrom', from_time.to_i.to_s + '000')
end

#valid_to(to_time) ⇒ Object



95
96
97
# File 'lib/offsite_payments/integrations/world_pay.rb', line 95

def valid_to(to_time)
  add_field('authValidTo', to_time.to_i.to_s + '000')
end