Parent

Class/Module Index [+]

Quicksearch

ActiveMerchant::Billing::Integrations::Paypal::Helper

Constants

CANADIAN_PROVINCES

Public Class Methods

new(order, account, options = {}) click to toggle source
# File lib/active_merchant/billing/integrations/paypal/helper.rb, line 23
def initialize(order, account, 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

Public Instance Methods

shipping_address(params = {}) click to toggle source
# File lib/active_merchant/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

[Validate]

Generated with the Darkfish Rdoc Generator 2.