Class: ActiveMerchant::Billing::Integrations::Paypal::Helper
- Defined in:
- lib/active_merchant/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
Instance Method Summary collapse
- #billing_address(params = {}) ⇒ Object
-
#initialize(order, account, options = {}) ⇒ Helper
constructor
A new instance of Helper.
Methods inherited from Helper
#add_field, #add_fields, #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 |
# File 'lib/active_merchant/billing/integrations/paypal/helper.rb', line 23 def initialize(order, account, = {}) 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') end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class ActiveMerchant::Billing::Integrations::Helper
Instance Method Details
#billing_address(params = {}) ⇒ Object
61 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 |
# File 'lib/active_merchant/billing/integrations/paypal/helper.rb', line 61 def billing_address(params = {}) if params.has_key?(:phone) phone = params.delete(:phone).to_s # Whipe all non digits phone.gsub!(/\D+/, '') # Parse in the us style (555 555 5555) which seems to be the only format paypal supports. Ignore anything before this. if phone =~ /(\d{3})(\d{3})(\d{4})$/ add_field(mappings[:billing_address][:phone_a], $1) add_field(mappings[:billing_address][:phone_b], $2) add_field(mappings[:billing_address][:phone_c], $3) end end # 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[:billing_address][:country], country_code) # Fix Canadian province if required if country_code == 'CA' province_code = params.delete(:state) add_field(mappings[:billing_address][:state], CANADIAN_PROVINCES[province_code.upcase]) unless province_code.nil? end # Everything else params.each do |k, v| field = mappings[:billing_address][k] add_field(field, v) unless field.nil? end end |