Class ActiveMerchant::Billing::Integrations::Paypal::Helper
In: lib/active_merchant/billing/integrations/paypal/helper.rb
Parent: ActiveMerchant::Billing::Integrations::Helper

Methods

Constants

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'

Public Class methods

[Source]

    # File lib/active_merchant/billing/integrations/paypal/helper.rb, line 23
23:           def initialize(order, account, options = {})
24:             super
25:             add_field('cmd', '_ext-enter')
26:             add_field('redirect_cmd', '_xclick')
27:             add_field('quantity', 1)
28:             add_field('item_name', 'Store purchase')
29:             add_field('no_shipping', '1')
30:             add_field('no_note', '1')
31:             add_field('charset', 'utf-8')
32:             add_field('address_override', '0')
33:             add_field('bn', application_id.to_s.slice(0,32)) unless application_id.blank?
34:           end

Public Instance methods

[Source]

    # File lib/active_merchant/billing/integrations/paypal/helper.rb, line 62
62:           def shipping_address(params = {})
63:             
64:             if params.has_key?(:phone)
65:               phone = params.delete(:phone).to_s
66:           
67:               # Whipe all non digits
68:               phone.gsub!(/\D+/, '')
69:           
70:               # Parse in the us style (555 555 5555) which seems to be the only format paypal supports. Ignore anything before this. 
71:               if phone =~ /(\d{3})(\d{3})(\d{4})$/
72:                 add_field('night_phone_a', $1) 
73:                 add_field('night_phone_b', $2) 
74:                 add_field('night_phone_c', $3) 
75:               end
76:             end
77:             
78:             # Get the country code in the correct format
79:             # Use what we were given if we can't find anything
80:             country_code = lookup_country_code(params.delete(:country))
81:             add_field(mappings[:shipping_address][:country], country_code)
82:               
83:             province_code = params.delete(:state)
84:                        
85:             case country_code
86:             when 'CA'
87:               add_field(mappings[:shipping_address][:state], CANADIAN_PROVINCES[province_code.upcase]) unless province_code.nil?
88:             when 'US'
89:               add_field(mappings[:shipping_address][:state], province_code)
90:             else
91:               add_field(mappings[:shipping_address][:state], province_code.blank? ? 'N/A' : province_code)
92:             end
93:               
94:             # Everything else 
95:             params.each do |k, v|
96:               field = mappings[:shipping_address][k]
97:               add_field(field, v) unless field.nil?
98:             end
99:           end

[Validate]