Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
peterfealey opened this issue Oct 30, 2014 · 27 comments

Comments

@peterfealey
Copy link

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
Copy link
Author

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.

@paulgroves
Copy link

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

@ouechtasvu
Copy link

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.

@Hates
Copy link
Contributor

Hates commented Nov 6, 2014

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.

Hates@b00e970

@peterfealey
Copy link
Author

@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
Copy link
Author

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

@Hates
Copy link
Contributor

Hates commented Nov 6, 2014

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

@peterfealey
Copy link
Author

Thank you so much @Hates

@alepore
Copy link
Member

alepore commented Nov 14, 2014

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
Copy link
Member

alepore commented Nov 14, 2014

maybe this commit? 057973b /c @gmacdougall

@Hates
Copy link
Contributor

Hates commented Nov 14, 2014

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

@alepore
Copy link
Member

alepore commented Nov 16, 2014

uhm, looks like this was fixed month ago on d446645 but this never reached 2-3-stable and master.

@Hates
Copy link
Contributor

Hates commented Nov 16, 2014

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.

@brianmcmahon
Copy link

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!

@geermc4
Copy link
Contributor

geermc4 commented Jul 21, 2015

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

@mleglise
Copy link

+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.

@alepore
Copy link
Member

alepore commented Aug 1, 2015

@mleglise on which version? are you up2date?

@geermc4
Copy link
Contributor

geermc4 commented Aug 3, 2015

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

@mleglise
Copy link

mleglise commented Aug 3, 2015

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

@alepore alepore reopened this Aug 3, 2015
@alepore
Copy link
Member

alepore commented Aug 3, 2015

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

@albertliu-nwb
Copy link

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

@mleglise
Copy link

@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: spree/spree#6695

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

@GerardGarcia
Copy link

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.

yushine added a commit to FlexMessenger/better_spree_paypal_express that referenced this issue Sep 14, 2015
@alepore
Copy link
Member

alepore commented Sep 25, 2015

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

@mmintel
Copy link

mmintel commented May 10, 2016

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!

@Hates
Copy link
Contributor

Hates commented May 10, 2016

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

@cjgarciaj
Copy link

cjgarciaj commented Jul 10, 2018

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests