Browse Source

Merging PKordel's changes.

cleaned up extension requires, common constants and added no_shipping preference

Handling no shipping option in address options

Handling no shipping option in paypay_confirm

Added locale updates for GB and for no_shipping, paypal_site_opts for customizing site appearance

Added MJM fix

Took out no shipping stuff as too specific

Fixes now in extension

Better fix for Payment#payment_profiles_supported?

Added support for no shipping

Added support for no shipping

Fix for passing currency to payment_detail_item

Added param payment_method_id
1-2-stable-sysmocom
Peter Kordel 12 years ago
committed by Brian Quinn
parent
commit
2801d39054
  1. 1
      app/models/billing_integration/paypal_express.rb
  2. 1
      app/models/billing_integration/paypal_express_uk.rb
  3. 5
      app/models/paypal_account.rb
  4. 3
      app/views/shared/_paypal_express_confirm.html.erb
  5. 10
      config/locales/en-GB.yml
  6. 1
      config/locales/en-US.yml
  7. 38
      lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb
  8. 82
      lib/spree/paypal_express.rb
  9. 3
      paypal_express_extension.rb

1
app/models/billing_integration/paypal_express.rb

@ -3,6 +3,7 @@ class BillingIntegration::PaypalExpress < BillingIntegration
preference :password, :password
preference :signature, :string
preference :review, :boolean, :default => false
preference :no_shipping, :boolean, :default => false
def provider_class
ActiveMerchant::Billing::PaypalExpressGateway

1
app/models/billing_integration/paypal_express_uk.rb

@ -3,6 +3,7 @@ class BillingIntegration::PaypalExpressUk < BillingIntegration
preference :password, :password
preference :signature, :string
preference :review, :boolean, :default => false
preference :no_shipping, :boolean, :default => false
def provider_class
ActiveMerchant::Billing::PaypalExpressUkGateway

5
app/models/paypal_account.rb

@ -66,6 +66,11 @@ class PaypalAccount < ActiveRecord::Base
def can_credit?(payment)
!find_capture(payment).nil?
end
# fix for Payment#payment_profiles_supported?
def payment_gateway
false
end
private
def find_authorization(payment)

3
app/views/shared/_paypal_express_confirm.html.erb

@ -5,5 +5,6 @@
<%= render :partial => 'shared/order_details', :locals => {:order => @order} -%>
<div class="form-buttons">
<%= button_to t('place_order'), paypal_finish_order_checkout_url(@checkout.order, {:token => params[:token] , :PayerID => params[:PayerID] } ), :class => "button primary" %>
<%= button_to t('place_order'), paypal_finish_order_checkout_url(@checkout.order, {:token => params[:token] , :PayerID => params[:PayerID], :payment_method_id =>
params[:payment_method_id] } ), :class => "button primary" %>
</div>

10
config/locales/en-GB.yml

@ -10,6 +10,14 @@ en-GB:
paypal_payment_id: PayPal Payment ID
pending_reason: Pending Reason
result: Result
review: Review
no_shipping: No Shipping
paypal_account: PayPal Account
payer_id: Payer ID
payer_country: Country
payer_status: Status
comment: Comment
account_details: Account Details
finalize:
paypalexpress: Capture Payment
activerecord:
@ -19,4 +27,4 @@ en-GB:
models:
paypal_payment:
one: PayPal Payment
other: PayPal Payments
other: PayPal Payments

1
config/locales/en-US.yml

@ -11,6 +11,7 @@ en-US:
pending_reason: Pending Reason
result: Result
review: Review
no_shipping: No Shipping
paypal_account: PayPal Account
payer_id: Payer ID
payer_country: Country

38
lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb

@ -10,40 +10,6 @@ module ActiveMerchant #:nodoc:
silence_warnings do
API_VERSION = '60.0'
URLS = {
:test => { :certificate => 'https://api.sandbox.paypal.com/2.0/',
:signature => 'https://api-3t.sandbox.paypal.com/2.0/' },
:live => { :certificate => 'https://api-aa.paypal.com/2.0/',
:signature => 'https://api-3t.paypal.com/2.0/' }
}
PAYPAL_NAMESPACE = 'urn:ebay:api:PayPalAPI'
EBAY_NAMESPACE = 'urn:ebay:apis:eBLBaseComponents'
ENVELOPE_NAMESPACES = { 'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
'xmlns:env' => 'http://schemas.xmlsoap.org/soap/envelope/',
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance'
}
CREDENTIALS_NAMESPACES = { 'xmlns' => PAYPAL_NAMESPACE,
'xmlns:n1' => EBAY_NAMESPACE,
'env:mustUnderstand' => '0'
}
AUSTRALIAN_STATES = {
'ACT' => 'Australian Capital Territory',
'NSW' => 'New South Wales',
'NT' => 'Northern Territory',
'QLD' => 'Queensland',
'SA' => 'South Australia',
'TAS' => 'Tasmania',
'VIC' => 'Victoria',
'WA' => 'Western Australia'
}
SUCCESS_CODES = [ 'Success', 'SuccessWithWarning' ]
FRAUD_REVIEW_CODE = "11610"
end
# The gateway must be configured with either your PayPal PEM file
@ -291,7 +257,7 @@ module ActiveMerchant #:nodoc:
end
end
def add_payment_detail_item(xml, item)
def add_payment_detail_item(xml, item, options)
currency_code = options[:currency] || currency(item[:amount])
xml.tag! 'n2:PaymentDetailsItem' do
xml.tag! 'n2:Name', item[:name] unless item[:name].blank?
@ -335,7 +301,7 @@ module ActiveMerchant #:nodoc:
xml.tag! 'n2:ButtonSource', application_id.to_s.slice(0,32) unless application_id.blank?
xml.tag! 'n2:NotifyURL', options[:notify_url] unless options[:notify_url].blank?
add_address(xml, 'n2:ShipToAddress', options[:shipping_address] || options[:address])
options[:items].each {|i| add_payment_detail_item xml, i } if options[:items]
options[:items].each {|i| add_payment_detail_item xml, i, options } if options[:items]
end
end

82
lib/spree/paypal_express.rb

@ -54,27 +54,28 @@ module Spree::PaypalExpress
@order.checkout.special_instructions = @ppx_details.params["note"]
#@order.update_attribute(:user, current_user)
ship_address = @ppx_details.address
order_ship_address = Address.new :firstname => @ppx_details.params["first_name"],
:lastname => @ppx_details.params["last_name"],
:address1 => ship_address["address1"],
:address2 => ship_address["address2"],
:city => ship_address["city"],
:country => Country.find_by_iso(ship_address["country"]),
:zipcode => ship_address["zip"],
# phone is currently blanked in AM's PPX response lib
:phone => @ppx_details.params["phone"] || "(not given)"
if (state = State.find_by_abbr(ship_address["state"]))
order_ship_address.state = state
else
order_ship_address.state_name = ship_address["state"]
unless payment_method.preferred_no_shipping
ship_address = @ppx_details.address
order_ship_address = Address.new :firstname => @ppx_details.params["first_name"],
:lastname => @ppx_details.params["last_name"],
:address1 => ship_address["address1"],
:address2 => ship_address["address2"],
:city => ship_address["city"],
:country => Country.find_by_iso(ship_address["country"]),
:zipcode => ship_address["zip"],
# phone is currently blanked in AM's PPX response lib
:phone => @ppx_details.params["phone"] || "(not given)"
if (state = State.find_by_abbr(ship_address["state"]))
order_ship_address.state = state
else
order_ship_address.state_name = ship_address["state"]
end
order_ship_address.save!
@order.checkout.ship_address = order_ship_address
end
order_ship_address.save!
@order.checkout.ship_address = order_ship_address
@order.checkout.save
if payment_method.preferred_review
@ -90,7 +91,7 @@ module Spree::PaypalExpress
def paypal_finish
load_object
opts = { :token => params[:token], :payer_id => params[:PayerID] }.merge all_opts(@order, params[:payment_method_id])
opts = { :token => params[:token], :payer_id => params[:PayerID] }.merge all_opts(@order, params[:payment_method_id], 'checkout' )
gateway = paypal_gateway
if Spree::Config[:auto_capture]
@ -169,6 +170,11 @@ module Spree::PaypalExpress
# see http://www.pdncommunity.com/t5/PayPal-Developer-Blog/Displaying-Order-Details-in-Express-Checkout/bc-p/92902#C851
}
end
# hook to override paypal site options
def paypal_site_opts
{}
end
def order_opts(order, payment_method, stage)
items = order.line_items.map do |item|
@ -201,6 +207,8 @@ module Spree::PaypalExpress
# get the main totals from the items (already *100)
opts[:subtotal] = opts[:items].map {|i| i[:amount] * i[:qty] }.sum
opts[:tax] = opts[:items].map {|i| i[:tax] * i[:qty] }.sum
opts[:handling] = 0 # MJM Added to force elements to be generated
opts[:shipping] = (order.ship_total*100).to_i
# overall total
opts[:money] = opts.slice(:subtotal, :tax, :shipping, :handling).values.sum
@ -234,24 +242,28 @@ module Spree::PaypalExpress
end
def address_options(order)
{
:no_shipping => false,
:address_override => true,
:address => {
:name => "#{order.ship_address.firstname} #{order.ship_address.lastname}",
:address1 => order.ship_address.address1,
:address2 => order.ship_address.address2,
:city => order.ship_address.city,
:state => order.ship_address.state.nil? ? order.ship_address.state_name.to_s : order.ship_address.state.abbr,
:country => order.ship_address.country.iso,
:zip => order.ship_address.zipcode,
:phone => order.ship_address.phone
if payment_method.preferred_no_shipping
{ :no_shipping => true }
else
{
:no_shipping => false,
:address_override => true,
:address => {
:name => "#{order.ship_address.firstname} #{order.ship_address.lastname}",
:address1 => order.ship_address.address1,
:address2 => order.ship_address.address2,
:city => order.ship_address.city,
:state => order.ship_address.state.nil? ? order.ship_address.state_name.to_s : order.ship_address.state.abbr,
:country => order.ship_address.country.iso,
:zip => order.ship_address.zipcode,
:phone => order.ship_address.phone
}
}
}
end
end
def all_opts(order, payment_method, stage=nil)
opts = fixed_opts.merge(order_opts(order, payment_method, stage))
opts = fixed_opts.merge(order_opts(order, payment_method, stage)).merge(paypal_site_opts)
if stage == "payment"
opts.merge! flat_rate_shipping_and_handling_options(order, stage)

3
paypal_express_extension.rb

@ -14,12 +14,11 @@ class PaypalExpressExtension < Spree::Extension
# these will be submitted to ActiveMerchant some time...
require File.join(PaypalExpressExtension.root, "lib", "active_merchant", "billing", "gateways", "paypal", "paypal_common_api.rb")
require File.join(PaypalExpressExtension.root, "lib", "active_merchant", "billing", "gateways", "paypal_express_uk.rb")
require File.join(PaypalExpressExtension.root, "lib", "active_merchant", "billing", "gateways", "paypal_express_uk.rb")
# inject paypal code into orders controller
CheckoutsController.class_eval do
include Spree::PaypalExpress
end
end
end
Loading…
Cancel
Save