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
This commit is contained in:
Peter Kordel 2010-03-05 12:59:20 +01:00 committed by Brian Quinn
parent 18597fa8a9
commit 2801d39054
9 changed files with 67 additions and 73 deletions

View File

@ -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

View File

@ -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

View File

@ -67,6 +67,11 @@ class PaypalAccount < ActiveRecord::Base
!find_capture(payment).nil?
end
# fix for Payment#payment_profiles_supported?
def payment_gateway
false
end
private
def find_authorization(payment)
#find the transaction associated with the original authorization/capture

View File

@ -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>

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -54,7 +54,7 @@ module Spree::PaypalExpress
@order.checkout.special_instructions = @ppx_details.params["note"]
#@order.update_attribute(:user, current_user)
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"],
@ -75,6 +75,7 @@ module Spree::PaypalExpress
order_ship_address.save!
@order.checkout.ship_address = order_ship_address
end
@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]
@ -170,6 +171,11 @@ module Spree::PaypalExpress
}
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|
tax = paypal_variant_tax(item.price, item.variant)
@ -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,6 +242,9 @@ module Spree::PaypalExpress
end
def address_options(order)
if payment_method.preferred_no_shipping
{ :no_shipping => true }
else
{
:no_shipping => false,
:address_override => true,
@ -249,9 +260,10 @@ module Spree::PaypalExpress
}
}
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)

View File

@ -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