Magento2 – Resolve PaymentTokenInterfaceFactory Error in Cart and Checkout

checkoutfatal errorhttp-error-500magento-2.1

Recently, I upload my Magento 2 site to production server, and everything looks fine, except by Cart and Checkout. When I enter to these, the server throw me a HTTP ERROR 500, and the page keep blank.

In Php Error Log, is displayed this error:

PHP Fatal error:  Uncaught Error: Cannot instantiate interface Magento\Vault\Api\Data\PaymentTokenInterfaceFactory in vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:93
Stack trace:
#0 vendor/magento/framework/ObjectManager/Factory/Compiled.php(88): Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject('Magento\\Vault\\A...', Array)
#1 vendor/magento/framework/ObjectManager/Factory/Compiled.php(130): Magento\Framework\ObjectManager\Factory\Compiled->create('Magento\\Vault\\A...')
#2 vendor/magento/framework/ObjectManager/Factory/Compiled.php(67): Magento\Framework\ObjectManager\Factory\Compiled->get('Magento\\Vault\\A...')
#3 vendor/magento/framework/ObjectManager/ObjectManager.php(57): Magento\Framework\ObjectManager\Factory\Compiled->create('Magento\\Paypal\\...', Array)
in vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 93

The other sections display well, only cart and checkout have this problem. Additional, this occurs only in Production. In my developer server, all is fine.

Best Answer

At first, please, provide Magento version of your application.

Starting Magento >= 2.1.3 version the Magento\Vault\Api\Data\PaymentTokenInterfaceFactory is no more autogenerated factory (the autogenerated code is "private" and can be changed in any patch release).

Instead of using PaymentTokenInterfaceFactory you should specify concrete factory for payment token. Magento provides two factories out of the box:

  • \Magento\Vault\Model\AccountPaymentTokenFactory - for payment methods which work with payment profiles like PayPal, Authorize.net, CyberSource

  • \Magento\Vault\Model\CreditCardTokenFactory - for payment methods, which tokenize credit card details, like Braintree.

More details about both factories and their purposes you can find in Magento payments documentation.

Magento Vault does not provide default preference for PaymentTokenInterfaceFactory interface because only payment integration knows about the type of token.

UPD: Starting from 2.2.0 release the \Magento\Vault\Api\Data\PaymentTokenInterfaceFactory has been deprecated and \Magento\Vault\Api\Data\PaymentTokenFactoryInterface should be used instead. The documentation has been updated as well.

Related Topic