Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

try:

  • Make sure the PHP module intl is installed;
  • rm var/generation/*
  • rm var/di/*
  • rm var/cache/*

    bin/magento setup:upgrade

    bin/magento setup:di:compile

I feel a little embarrassing right know. Thanks to joni jones comment about Magento 2.1.3 and PaymentTokenInterfaceFactory , I could see that, in fact, that was the source of my problem. But, the strange is that I have the 2.1.1 version when I develop the site in my developer server, instead of 2.1.3.

So, I put an investigate, and Apparently the hosting guys installed a newer version of Magento on the production server. I do not know if it was 2.1.3, but it was definitely not 2.1.1. So, when I upload my site to production, I had code of 2.1.1 and 2.1.3 scrambled, and that obviously caused conflicts.

I deleted everything, and re-upload all my 2.1.1 site again, and the site is now visible. What a silly mistake. In normal situations, if someone is presented with this error, I think the joni's solution would be correct.

Thanks for everything.

Try This to clear cache and generation files

sudo rm -rf var/cache/* var/di/* var/generation/*
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top