better_spree_paypal_express icon indicating copy to clipboard operation
better_spree_paypal_express copied to clipboard

PayPal failed. The totals of the cart item amounts do not match order amounts.

Open peterfealey opened this issue 10 years ago • 27 comments

screenshot 2014-10-30 16 19 43 Having a problem integrating this. Gemfile attached, if that helps.

At checkout the above message prevents even getting to the PayPal form.


source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.4'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', group: :development
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# Use jquery as the JavaScript library
gem 'jquery-rails', '~> 3.1.0'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0',          group: :doc

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring',        group: :development

gem 'spree', '2.3.2'
gem 'spree_gateway', :git => 'https://github.com/spree/spree_gateway.git', :branch => '2-3-stable'
gem 'spree_auth_devise', :git => 'https://github.com/spree/spree_auth_devise.git', :branch => '2-3-stable'
gem 'spree_bootstrap_frontend', github: '200Creative/spree_bootstrap_frontend', branch: '2-3-stable'
gem 'spree_digital', :git => 'git://github.com/halo/spree_digital.git', :branch => '2-3-stable'
gem 'spree_product_assembly', github: 'spree/spree-product-assembly', branch: '2-3-stable'
gem 'spree_static_content', github: 'spree/spree_static_content', branch: '2-3-stable'

gem 'spree_paypal_express', github: 'spree-contrib/better_spree_paypal_express', branch: '2-3-stable'
gem 'spree_blogging_spree', github: 'stefansenk/spree-blogging-spree', branch: '2-3-stable'

gem 'spreadsheet', '0.9.7'
gem 'datashift', :git => 'git://github.com/autotelik/datashift'
gem 'datashift_spree', :git => 'git://github.com/autotelik/datashift_spree'

gem 'rails_12factor', group: :production

gem 'mysql2', group: :production

gem 'better_errors', group: :development
gem 'binding_of_caller', group: :development

gem 'sprockets-rails', '2.1.3'

gem 'paperclip'
gem 'aws-sdk'

peterfealey avatar Oct 30 '14 16:10 peterfealey

Ok, on further inspection, choosing not to 'include Tax In Prices' means I can get through the process, but I'd really not like to be displaying ex VAT pricing and adding it on at checkout.

peterfealey avatar Oct 30 '14 16:10 peterfealey

I am experiencing this exact issue, where unchecking 'INCLUDED IN PRICE' in /admin/tax_rates/1/edit resolved the problem, but is undesired.

Very grateful for any help on this :)

paulgroves avatar Nov 03 '14 22:11 paulgroves

same here ...

I'm using the 2-3 stable branch and for a quick fix I have juste commented this section in paypal_controller :

  # TMP fix for tax included in product price

  # order.all_adjustments.eligible.each do |adjustment|
  #   next if (tax_adjustments + shipping_adjustments).include?(adjustment)
  #   items << {
  #     :Name => adjustment.label,
  #     :Quantity => 1,
  #     :Amount => {
  #       :currencyID => order.currency,
  #       :value => adjustment.amount
  #     }
  #   }
  # end

It's working because I don't have other taxes and they are included in product price but it's not a good solution.

ouechtasvu avatar Nov 05 '14 12:11 ouechtasvu

These are the changes I made to have inclusive VAT work on 2-2-stable. Ignore my reference to paypal_price as that's an internal thing we use for calculating gift wrapping.

https://github.com/Hates/better_spree_paypal_express/commit/b00e970bc2147b8f7fb60a9f638ea92adb127edd

Hates avatar Nov 06 '14 18:11 Hates

@Hates - Ah wow. Thank you.

This is my first Spree project, so please excuse the stupidity that's about to come from my keyboard.

Could I theoretically take a copy of paypal_controller.rb and drop it into /app/spree/controllers/ and it will override the gem's copy? I expect it's not best practice but deadlines are looming and better launched than not!

peterfealey avatar Nov 06 '14 18:11 peterfealey

...But I should really fork the Gem based on the branch I'm using and bundle from my fork...

peterfealey avatar Nov 06 '14 18:11 peterfealey

@peterfealey Putting something like this in app/controllers/spree/paypal_controller_decorator.rb should work: https://gist.github.com/Hates/fb67e791c5d239efdbff

Hates avatar Nov 06 '14 18:11 Hates

Thank you so much @Hates

peterfealey avatar Nov 06 '14 18:11 peterfealey

anyone figured out what actually happened here and the proper way to fix this? i have a 2.2 store with tax included in price that works as expected, and a brand new 2.3 one with this error.

alepore avatar Nov 14 '14 17:11 alepore

maybe this commit? https://github.com/spree-contrib/better_spree_paypal_express/commit/057973b9a8520736290c75b4466ff0ee25d9f743 /c @gmacdougall

alepore avatar Nov 14 '14 17:11 alepore

AFAIK this gem has never worked when tax is included in the price.

Hates avatar Nov 14 '14 18:11 Hates

uhm, looks like this was fixed month ago on https://github.com/spree-contrib/better_spree_paypal_express/commit/d446645c0ba09fa61b902982a5f57d2713fd9868 but this never reached 2-3-stable and master.

alepore avatar Nov 16 '14 16:11 alepore

I'm running the 2-2-stable branch with that change and was still running into problems with inclusive tax rates. It's possible that the problem I'm having is un-related. My issue occurs when shipping to a tax zone where the inclusive rate should not be applied.

Hates avatar Nov 16 '14 21:11 Hates

So I'm not sure if this has been fixed and explained somewhere else but the following worked for me.

For those of you needing to fix it yourself you can modify the paypal controller and make sure that the tax adjustments include the line item taxes. The issue seemed to be that the line item tax adjustments were being added as order items (this is for 2.3-stable). So for line 6 I changed it to:

tax_adjustments = order.adjustments.tax.additional + order.line_item_adjustments.tax.additional

The reason there is this issue is because there are two places where the cart item totals are added up: line 137 and line 148. Line 137 uses current_order.total - shipment_sum - current_order.additional_tax_total to calculate the total, and line 148 sums up the items in the item array, and the tax for the line items is included as an item.

I hope this helps!

brianmcmahon avatar Feb 20 '15 00:02 brianmcmahon

I just ran into this, curious, why was it closed by tests?

geermc4 avatar Jul 21 '15 22:07 geermc4

+1 Also experiencing this bug. @alepore can this be re-opened?

I'm getting this message when a line item has a promotion adjustment, shipping to a location without taxes.

mleglise avatar Jul 31 '15 20:07 mleglise

@mleglise on which version? are you up2date?

alepore avatar Aug 01 '15 08:08 alepore

@alepore I was on 69fd18c48b98 although I later figured out my issue was caused by tax adjustments from https://github.com/railsdog/spree_avatax_certified

geermc4 avatar Aug 03 '15 16:08 geermc4

@alepore I'm running latest 3-0-stable for this gem and Spree itself. Working on a test case to show the breakage.

mleglise avatar Aug 03 '15 18:08 mleglise

Thanks, the problem here is always the same : PayPal checks if the sum of all items and adjustments matches the total amount.

So we must be very careful to include (or exclude) all kinds of spree adjustments and taxes

alepore avatar Aug 03 '15 18:08 alepore

hi mleglise, I am on 3-0-stable too. in paypal_controller.rb line 8, I changed additional_adjustments = order.all_adjustments.additional to additional_adjustments = order.all_adjustments

After line 22, I also added (you may don't need it) order.update!

Now it works. good luck. Albert

albertliu-nwb avatar Aug 11 '15 23:08 albertliu-nwb

@albertliu-nwb found the right place. I dug deeper and discovered that this is because of a change in Spree::Core 3.0. PR submitted: https://github.com/spree/spree/pull/6695

Theoretically, that PR should solve this issue, with no changes needed in the PayPal gem.

mleglise avatar Aug 26 '15 00:08 mleglise

I have applied the PR to spree branch 3-0-stable and I still experience the issue. Changing line 8 of paypal_controller.rb as @albertliu-nwb suggested solved it.

In my case the error was caused beacuse an order adjustment was not included and not beacuse of a tax adjustment.

GerardGarcia avatar Aug 29 '15 16:08 GerardGarcia

uhm, this spree included: nil is pretty bad. changing that line on paypal controller will probably break again in other situations...

alepore avatar Sep 25 '15 12:09 alepore

Hi there,

i was getting the same error and fixed it with this gist mentioned above (https://gist.github.com/Hates/fb67e791c5d239efdbff).

Now this works for most of my orders but we have a special discounting system. if someone places an order in our store he must enter a unique ID, some of them are linked to a discount. so for every order including a discount I am still getting this error. I guess that happens because the discount is applied to the whole order and not to the single items. as I am not the developer of that discounting system and my rails knowledge is very limited: do you know a quick way to disable this "security mechanism" in this paypal plugin here? Which line of code is responsible for that?

Hope you understand my problem!

mmintel avatar May 10 '16 08:05 mmintel

@mmintel It should be added as an adjustment, which AFAIK can be a negative value. You can see where it builds them up on line 11 of the gist you linked to. Apart from that I don't think it can be disabled as all the values need to add up otherwise Paypal reject the order.

Hates avatar May 10 '16 10:05 Hates

@Hates as an adjustments works but the promotions won't be collected in the aditional therefore the issue will persist if the order has any discount. My fix for future readers:

    additional_adjustments = order.all_adjustments.additional
    tax_adjustments = additional_adjustments.tax
    shipping_adjustments = additional_adjustments.shipping
    promotion_adjustments = order.all_adjustments.promotion

    (additional_adjustments.eligible + promotion_adjustments.eligible).each do |adjustment|
      next if (shipping_adjustments + tax_adjustments).include?(adjustment)
      items << {
        :Name => adjustment.label,
        :Quantity => 1,
        :Amount => {
          :currencyID => order.currency,
          :value => adjustment.amount
        }
      }
    end

Hope this helps

Note: I had to add the tax adjustments since paypal was capturing the taxonomies apart from the items So far: Tested at 11/07/2018 20:57 UTC

cjgarciaj avatar Jul 10 '18 15:07 cjgarciaj