Added support for coupons / credits and actual tax amounts
This commit is contained in:
parent
2cb3ba61e2
commit
86a977d174
|
@ -264,7 +264,11 @@ module ActiveMerchant #:nodoc:
|
||||||
xml.tag! 'n2:Description', item[:description] unless item[:description].blank?
|
xml.tag! 'n2:Description', item[:description] unless item[:description].blank?
|
||||||
xml.tag! 'n2:Number', item[:sku] unless item[:sku].blank?
|
xml.tag! 'n2:Number', item[:sku] unless item[:sku].blank?
|
||||||
xml.tag! 'n2:Quantity', item[:qty] unless item[:qty].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?
|
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:Tax', amount(item[:tax]), 'currencyID' => currency_code unless item[:tax].blank?
|
||||||
xml.tag! 'n2:ItemWeight', item[:weight] unless item[:weight].blank?
|
xml.tag! 'n2:ItemWeight', item[:weight] unless item[:weight].blank?
|
||||||
xml.tag! 'n2:ItemHeight', item[:height] unless item[:height].blank?
|
xml.tag! 'n2:ItemHeight', item[:height] unless item[:height].blank?
|
||||||
|
|
|
@ -15,7 +15,6 @@ module ActiveMerchant #:nodoc:
|
||||||
|
|
||||||
def setup_authorization(money, options = {})
|
def setup_authorization(money, options = {})
|
||||||
requires!(options, :return_url, :cancel_return_url)
|
requires!(options, :return_url, :cancel_return_url)
|
||||||
|
|
||||||
commit 'SetExpressCheckout', build_setup_request('Authorization', money, options)
|
commit 'SetExpressCheckout', build_setup_request('Authorization', money, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -193,6 +193,15 @@ module Spree::PaypalExpress
|
||||||
:depth => item.variant.weight }
|
:depth => item.variant.weight }
|
||||||
end
|
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}",
|
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",
|
: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)
|
# get the main totals from the items (already *100)
|
||||||
opts[:subtotal] = opts[:items].map {|i| i[:amount] * i[:qty] }.sum
|
opts[:subtotal] = opts[:items].map {|i| i[:amount] * i[:qty] }.sum
|
||||||
opts[:tax] = opts[:items].map {|i| i[:tax] * 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
|
opts[:shipping] = (order.ship_total*100).to_i
|
||||||
|
|
||||||
# overall total
|
# overall total
|
||||||
opts[:money] = opts.slice(:subtotal, :tax, :shipping, :handling).values.sum
|
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_url] = "http://" + request.host_with_port + "/paypal_express_callbacks/#{order.number}"
|
||||||
opts[:callback_timeout] = 3
|
opts[:callback_timeout] = 3
|
||||||
|
|
||||||
elsif stage == "payment"
|
elsif stage == "payment"
|
||||||
#use real totals are we are paying via paypal (spree checkout almost complete)
|
#use real totals are we are paying via paypal (spree checkout almost complete)
|
||||||
opts[:subtotal] = (order.item_total*100).to_i
|
opts[:subtotal] = ((order.item_total + order.credits.total)*100).to_i
|
||||||
opts[:tax] = 0 # BQ : not sure what to do here
|
opts[:tax] = (order.tax_total*100).to_i
|
||||||
opts[:shipping] = (order.ship_total*100).to_i
|
opts[:shipping] = (order.ship_total*100).to_i
|
||||||
opts[:handling] = 0 # BQ : not sure what to do here
|
opts[:handling] = 0
|
||||||
|
|
||||||
# overall total
|
|
||||||
opts[:money] = opts.slice(:subtotal, :tax, :shipping, :handling).values.sum
|
|
||||||
|
|
||||||
opts[:money] = (order.total*100).to_i
|
opts[:money] = (order.total*100).to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue