Added support for coupons / credits and actual tax amounts

This commit is contained in:
Brian Quinn 2010-04-30 10:12:54 +01:00
parent 2cb3ba61e2
commit 86a977d174
3 changed files with 34 additions and 29 deletions

View File

@ -264,7 +264,11 @@ module ActiveMerchant #:nodoc:
xml.tag! 'n2:Description', item[:description] unless item[:description].blank?
xml.tag! 'n2:Number', item[:sku] unless item[:sku].blank?
xml.tag! 'n2:Quantity', item[:qty] unless item[:qty].blank?
if item[:amount].to_i > 0
xml.tag! 'n2:Amount', amount(item[:amount]), 'currencyID' => currency_code unless item[:amount].blank?
else
xml.tag! 'n2:Amount', "-#{amount(item[:amount].to_i*-1)}", 'currencyID' => currency_code unless item[:amount].blank?
end
xml.tag! 'n2:Tax', amount(item[:tax]), 'currencyID' => currency_code unless item[:tax].blank?
xml.tag! 'n2:ItemWeight', item[:weight] unless item[:weight].blank?
xml.tag! 'n2:ItemHeight', item[:height] unless item[:height].blank?

View File

@ -15,7 +15,6 @@ module ActiveMerchant #:nodoc:
def setup_authorization(money, options = {})
requires!(options, :return_url, :cancel_return_url)
commit 'SetExpressCheckout', build_setup_request('Authorization', money, options)
end

View File

@ -193,6 +193,15 @@ module Spree::PaypalExpress
:depth => item.variant.weight }
end
credits = order.credits.map do |credit|
{ :name => credit.description,
:description => credit.description,
:sku => credit.id,
:qty => 1,
:amount => (credit.amount*100).to_i }
end
items.concat credits
opts = { :return_url => request.protocol + request.host_with_port + "/orders/#{order.number}/checkout/paypal_confirm?payment_method_id=#{payment_method}",
:cancel_return_url => "http://" + request.host_with_port + "/orders/#{order.number}/edit",
@ -207,27 +216,20 @@ 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[:handling] = 0
opts[:shipping] = (order.ship_total*100).to_i
# overall total
opts[:money] = opts.slice(:subtotal, :tax, :shipping, :handling).values.sum
opts[:money] = (order.total*100).to_i
opts[:callback_url] = "http://" + request.host_with_port + "/paypal_express_callbacks/#{order.number}"
opts[:callback_timeout] = 3
elsif stage == "payment"
#use real totals are we are paying via paypal (spree checkout almost complete)
opts[:subtotal] = (order.item_total*100).to_i
opts[:tax] = 0 # BQ : not sure what to do here
opts[:subtotal] = ((order.item_total + order.credits.total)*100).to_i
opts[:tax] = (order.tax_total*100).to_i
opts[:shipping] = (order.ship_total*100).to_i
opts[:handling] = 0 # BQ : not sure what to do here
# overall total
opts[:money] = opts.slice(:subtotal, :tax, :shipping, :handling).values.sum
opts[:handling] = 0
opts[:money] = (order.total*100).to_i
end