Add temporary work around for orders / payments that get rejected by PayPal due to the totals not suming up correctly.

This commit is contained in:
Brian Quinn 2010-11-17 16:26:19 +00:00
parent 08ee800f06
commit 1d4caea500
1 changed files with 14 additions and 18 deletions

View File

@ -194,21 +194,19 @@ module Spree::PaypalExpress
def order_opts(order, payment_method, stage) def order_opts(order, payment_method, stage)
items = order.line_items.map do |item| items = order.line_items.map do |item|
tax = paypal_variant_tax(item.price, item.variant)
price = (item.price * 100).to_i # convert for gateway price = (item.price * 100).to_i # convert for gateway
tax = (tax * 100).to_i # truncate the tax slice
{ :name => item.variant.product.name, { :name => item.variant.product.name,
:description => item.variant.product.description[0..120], :description => item.variant.product.description[0..120],
:sku => item.variant.sku, :sku => item.variant.sku,
:qty => item.quantity, :qty => item.quantity,
:amount => price - tax, :amount => price,
:tax => tax,
:weight => item.variant.weight, :weight => item.variant.weight,
:height => item.variant.height, :height => item.variant.height,
:width => item.variant.width, :width => item.variant.width,
:depth => item.variant.weight } :depth => item.variant.weight }
end end
#add each credit a line item to ensure totals sum up correctly
credits = order.credits.map do |credit| credits = order.credits.map do |credit|
{ :name => credit.description, { :name => credit.description,
:description => credit.description, :description => credit.description,
@ -245,20 +243,18 @@ module Spree::PaypalExpress
opts[:subtotal] = ((order.item_total + order.credits.total)*100).to_i opts[:subtotal] = ((order.item_total + order.credits.total)*100).to_i
opts[:tax] = (order.tax_total*100).to_i 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
#hack to add float rounding difference in as handling fee - prevents PayPal from rejecting orders
#becuase the integer totals are different from the float based total. This is temporary and will be
#removed once Spree's currency values are persisted as integers (normally only 1c)
opts[:handling] = (order.total*100).to_i - opts.slice(:subtotal, :tax, :shipping).values.sum
opts[:money] = (order.total*100).to_i opts[:money] = (order.total*100).to_i
end end
opts opts
end end
# hook for supplying tax amount for a single unit of a variant
# expects the sale price from the line_item and the variant itself, since
# line_item price and variant price can diverge in time
def paypal_variant_tax(sale_price, variant)
0.0
end
def address_options(order) def address_options(order)
if payment_method.preferred_no_shipping if payment_method.preferred_no_shipping
{ :no_shipping => true } { :no_shipping => true }