Articles on: Magento 2 User Guide

How to fix PayPal Magento 2 checkout issues - transaction refused invalid argument token error

Overview


Upgrading Magento is essential for security and performance, but it can surface payment flow issues. One common PayPal problem appears after upgrading from Magento 2.1.6 → 2.1.11, especially with downloadable/virtual products: PayPal completes the charge, but the customer hits a blank page or HTTP 500 instead of the success page. The logs show:


Transaction refused because of an invalid argument. See additional error messages for details.
A successful transaction has already been completed for this token.


With verbose logging enabled, you may also see a fatal error similar to:


Fatal error: Uncaught Error: Call to a member function getDownloadableOption() on null
in /vendor/magento/module-downloadable/Model/Quote/Item/CartItemProcessor.php:66
Stack trace:
#0 /vendor/magento/module-quote/Model/Quote/Item/CartItemOptionsProcessor.php(33):
Magento\Downloadable\Model\Quote\Item\CartItemProcessor->convertToBuyRequest(
Object(Magento\Quote\Model\Quote\Item))
#1 /vendor/magento/module-quote/Model/Quote/Item/CartItemPersister.php(69):
Magento\Quote\Model\Quote\Item\CartItemOptionsProcessor->getBuyRequest(
'downloadable', Object(Magento\Quote\Model\Quote\Item))
#2 /vendor/magento/module-quote/Model/QuoteRepository/SaveHandler.php(86):
Magento\Quote\Model\Quote\Item\CartItemPersister->save(
Object(Magento\Quote\Model\Quote\Interceptor),
Object(Magento\Quote\Model\Quote\Item))
#3 /vendor/magento/module-downloadable/Model/Quote/Item/CartItemProcessor.php on line 66



Root Cause


This is a Magento 2.1 bug in the Downloadable module’s cart item processing logic. The code assumes the presence of extension attributes for downloadable options and calls getDownloadableOption() without a null check, which can fatally error and interrupt the post-payment flow. This was fixed in Magento 2.2.



Solutions



The issue is fixed upstream starting with Magento 2.2. If possible, plan an upgrade to eliminate this and related edge cases. Follow your normal upgrade path, recompile, deploy static content, and re-test checkout for downloadable/virtual products.



Solution 2 (Backport the Fix on Magento 2.1)


If you must remain on Magento 2.1, backport the official fix from Magento:


Reference commit:

https://github.com/magento/magento2/commit/f954a9150aef87d58ccc4f400815f6337234f09a


Important: Do not modify core files directly. Create a small “fix” module or use a preference/plugin to override the behavior in a safe, upgrade-friendly way.


File involved (for reference):

vendor/magento/module-downloadable/Model/Quote/Item/CartItemProcessor.php


In convertToBuyRequest, the original first if condition in Magento 2.1 is:


if ($cartItem->getProductOption()
&& $cartItem->getProductOption()->getExtensionAttributes()->getDownloadableOption()
)


Update it to safely guard against missing extension attributes:


if ($cartItem->getProductOption()
&& $cartItem->getProductOption()->getExtensionAttributes()
&& $cartItem->getProductOption()->getExtensionAttributes()->getDownloadableOption()
)


This null-check prevents the fatal error when the extension attributes are not present.



Post-Fix Checklist


  1. Flush & Recompile
  • Clear caches and generated code, then recompile/deploy:
   php bin/magento cache:flush
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
  1. Re-test Checkout
  • Test with downloadable/virtual items via PayPal.
  • Confirm users are redirected to the success page after payment.
  1. Monitor Logs
  • Check var/log/ and your web server logs to ensure the fatal error no longer appears.
  1. Plan Upgrade
  • Even with the backport, schedule an upgrade to Magento 2.2+ to benefit from the official fix and other security/performance improvements.



Notes


  • The PayPal messages:
  • “Transaction refused because of an invalid argument…”
  • “A successful transaction has already been completed for this token.”

often reflect that PayPal completed the charge, but Magento’s post-payment handling crashed before redirect, causing token reuse or an inconsistent state. Fixing the null check resolves this flow.


  • Always test on a staging environment before deploying to production.

Updated on: 18/09/2025

Was this article helpful?

Share your feedback

Cancel

Thank you!