Class: OffsitePayments::Integrations::TwoCheckout::Helper

Inherits:
Helper
  • Object
show all
Defined in:
lib/offsite_payments/integrations/two_checkout.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, #test?

Constructor Details

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

Returns a new instance of Helper.



37
38
39
40
41
42
# File 'lib/offsite_payments/integrations/two_checkout.rb', line 37

def initialize(order, , options = {})
  super
  if OffsitePayments.mode == :test || options[:test]
    add_field('demo', 'Y')
  end
end

Dynamic Method Handling

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

Instance Method Details

#customer(params = {}) ⇒ Object



92
93
94
95
96
# File 'lib/offsite_payments/integrations/two_checkout.rb', line 92

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

#shipping_address(params = {}) ⇒ Object



98
99
100
101
# File 'lib/offsite_payments/integrations/two_checkout.rb', line 98

def shipping_address(params = {})
  super
  add_field(mappings[:shipping_address][:name], "#{params[:first_name]} #{params[:last_name]}")
end

#third_party_cart(params = {}) ⇒ Object

Uses Third Party Cart parameter set to pass in lineitem details. You must also specify ‘service.invoice` when using this method.



105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/offsite_payments/integrations/two_checkout.rb', line 105

def third_party_cart(params = {})
  add_field('id_type', '1')
  (max_existing_line_item_id = form_fields.keys.map do |key|
    i = key.to_s[/^c_prod_(\d+)/, 1]
    (i && i.to_i)
  end.compact.max || 0)

  line_item_id = max_existing_line_item_id + 1
  params.each do |key, value|
    add_field("c_#{key}_#{line_item_id}", value)
  end
end