Class: OffsitePayments::Integrations::Paypal::Helper
- Defined in:
- lib/offsite_payments/integrations/paypal.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
-
#initialize(order, account, options = {}) ⇒ Helper
constructor
A new instance of Helper.
- #shipping_address(params = {}) ⇒ Object
Methods inherited from Helper
#add_field, #add_fields, #add_raw_html_field, #billing_address, #form_fields, #form_method, inherited, mapping, #raw_html_fields, #test?
Methods included from MoneyCompatibility
Constructor Details
#initialize(order, account, options = {}) ⇒ Helper
Returns a new instance of Helper.
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/offsite_payments/integrations/paypal.rb', line 50 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') 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 OffsitePayments::Helper
Instance Method Details
#shipping_address(params = {}) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/offsite_payments/integrations/paypal.rb', line 89 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 # Wipe 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 |