lib/active_merchant/billing/integrations/paypal/helper.rb in activemerchant-1.1.0 vs lib/active_merchant/billing/integrations/paypal/helper.rb in activemerchant-1.2.0
- old
+ new
@@ -27,11 +27,12 @@
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', '1')
+ add_field('address_override', '0')
+ add_field('bn', application_id.to_s.slice(0,32)) unless application_id.blank?
end
mapping :amount, 'amount'
mapping :account, 'business'
mapping :currency, 'currency_code'
@@ -43,60 +44,72 @@
mapping :quantity, 'quantity'
mapping :no_shipping, 'no_shipping'
mapping :no_note, 'no_note'
mapping :address_override, 'address_override'
+ mapping :application_id, 'bn'
+
mapping :customer, :first_name => 'first_name',
:last_name => 'last_name',
- :email => 'email',
- :phone => 'night_phone_a'
+ :email => 'email'
- mapping :billing_address, :city => 'city',
- :address1 => 'address1',
- :address2 => 'address2',
- :state => 'state',
- :zip => 'zip',
- :country => 'country',
- :phone_a => "night_phone_a",
- :phone_b => "night_phone_b",
- :phone_c => "night_phone_c"
+ mapping :shipping_address, :city => 'city',
+ :address1 => 'address1',
+ :address2 => 'address2',
+ :state => 'state',
+ :zip => 'zip',
+ :country => 'country'
- 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
-
-
+ def shipping_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('night_phone_a', $1)
+ add_field('night_phone_b', $2)
+ add_field('night_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[:shipping_address][:country], country_code)
+
+ 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
+
mapping :tax, 'tax'
mapping :shipping, 'shipping'
+ mapping :cmd, 'cmd'
+ mapping :custom, 'custom'
+ mapping :src, 'src'
+ mapping :sra, 'sra'
+ %w(a p t).each do |l|
+ (1..3).each do |i|
+ mapping "#{l}#{i}".to_sym, "#{l}#{i}"
+ end
+ end
end
end
end
end
end