Class: AbtainBilling::Billing::Integrations::Paypal::Helper

Inherits:
Helper
  • Object
show all
Defined in:
lib/abtain_billing/billing/integrations/paypal/helper.rb

Constant Summary collapse

CANADIAN_PROVINCES =
{  'AB' => 'Alberta',
  'BC' => 'British Columbia',
  'MB' => 'Manitoba',
  'NB' => 'New Brunswick',
  'NL' => 'Newfoundland',
  'NS' => 'Nova Scotia',
  'NU' => 'Nunavut',
  'NT' => 'Northwest Territories',
  'ON' => 'Ontario',
  'PE' => 'Prince Edward Island',
  'QC' => 'Quebec',
  'SK' => 'Saskatchewan',
  'YT' => 'Yukon'
}

Instance Attribute Summary

Attributes inherited from Helper

#fields

Instance Method Summary collapse

Methods inherited from Helper

#add_field, #add_fields, #billing_address, #form_fields, mapping

Constructor Details

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

Returns a new instance of Helper.



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/abtain_billing/billing/integrations/paypal/helper.rb', line 23

def initialize(order, , options = {})
  super
  add_field('cmd', '_ext-enter')
  add_field('redirect_cmd', '_xclick')
  add_field('quantity', 1)
  add_field('item_name', 'Store purchase')
  add_field('no_shipping', '1')
  add_field('no_note', '1')
  add_field('charset', 'utf-8')
  add_field('address_override', '0')
  add_field('bn', application_id.to_s.slice(0,32)) unless application_id.blank?
end

Dynamic Method Handling

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

Instance Method Details

#shipping_address(params = {}) ⇒ Object



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
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/abtain_billing/billing/integrations/paypal/helper.rb', line 62

def shipping_address(params = {})

  # Get the country code in the correct format
  # Use what we were given if we can't find anything
  country_code = lookup_country_code(params.delete(:country))
  add_field(mappings[:shipping_address][:country], country_code)
  
  if params.has_key?(:phone)
    phone = params.delete(:phone).to_s

    # Whipe all non digits
    phone.gsub!(/\D+/, '')
    
    if ['US', 'CA'].include?(country_code) && phone =~ /(\d{3})(\d{3})(\d{4})$/
      add_field('night_phone_a', $1) 
      add_field('night_phone_b', $2) 
      add_field('night_phone_c', $3) 
    else
      add_field('night_phone_b', phone)                
    end
  end
    
  province_code = params.delete(:state)
             
  case country_code
  when 'CA'
    add_field(mappings[:shipping_address][:state], CANADIAN_PROVINCES[province_code.upcase]) unless province_code.nil?
  when 'US'
    add_field(mappings[:shipping_address][:state], province_code)
  else
    add_field(mappings[:shipping_address][:state], province_code.blank? ? 'N/A' : province_code)
  end
    
  # Everything else 
  params.each do |k, v|
    field = mappings[:shipping_address][k]
    add_field(field, v) unless field.nil?
  end
end