Everything works well when installing an extension on a clean Magento, but how about the upgrades? We need to keep up with the security updates, performance improvements and new features, so from time to time updating Magento is necessary and sometimes challenging as the new Magento releases are constantly changing and improving the core.
You can find below one of the common PayPal issues with Magento 2 on checkout.
After upgrading Magento from Magento 2.1.6 to 2.1.11 below issue is experienced with downloadable / virtual products.
PayPal successfully process the payment but returns a blank page or error 500, without redirecting to success page, with below error message in the logs:
Transaction refused because of an invalid argument. See additional error messages for details.
A successful transaction has already been completed for this token.
When enabled additional logs, below errors were discovered:
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
Looks like this is a Magento bug present in Magento 2.1 and was fixed in Magento 2.2. First solution is to upgrade to Magento 2.2.
Solution 2. (recommend to make rewrites in a 'fix extension' and not change the core)
- If you are still on Magento 2.1 and want to address this issue you can apply below fix that was already included in Magento 2.2:
- In addition to that, also below changes are necessary:
convertToBuyRequest - first "if" condition is changed from: