0

I have this error when I'm trying to pay an order:

Fatal error: Uncaught TypeError: 
Argument 1 passed to Magento\Paypal\Model\Adminhtml\Express::isOrderAuthorizationAllowed() must be an instance of Magento\Sales\Model\Order\Payment, null given, 
called in /var/www/axiane-portailclient/vendor/magento/module-paypal/Plugin/OrderCanInvoice.php on line 41 and 
defined in /var/www/axiane-portailclient/vendor/magento/module-paypal/Model/Adminhtml/Express.php:169 
Stack trace: 
#0 /var/www/axiane-portailclient/vendor/magento/module-paypal/Plugin/OrderCanInvoice.php(41): Magento\Paypal\Model\Adminhtml\Express->isOrderAuthorizationAllowed(NULL) 
#1 /var/www/axiane-portailclient/vendor/magento/framework/Interception/Interceptor.php(146): Magento\Paypal\Plugin\OrderCanInvoice->afterCanInvoice(Object(Magento\Sales\Model\Order\Interceptor), false) 
#2 /var/www/axiane-portailclient/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Sales\Model\Order\Interceptor->Magento\Framework\Interception\{closure}() 
#3 /var/www/axiane-portailclient/generated/code/Magento/Sales/Model/Orde in /var/www/axiane-portailclient/vendor/magento/module-paypal/Model/Adminhtml/Express.php on line 169

I don't know why, because it's not a paypal step.

I'm on magento 2.2.5

Error is showing after save($order)

public function updateOrderStatus(){
    $increment_id = $this->loadOrderIncrementId();
    $order = $this->_order->loadByIncrementId($increment_id);
    $order->setState(Order::STATE_COMPLETE);
    $order->setStatus(Order::STATE_COMPLETE);
    $this->_orderRepository->save($order);
}
1

The called method from the paypal module is in a plugin called after the method canInvoice() of the order model and is therefore called for each order independent of the payment of the order.

So the question in your case is: Why doesn't have the order you are trying to save a payment? Because $order->getPayment() is null, that's what the error message says.

It might be that you don't find an order to the given $increment_id. I would suggest to check if the order exists and change the code to something like this:

if ($order->getId()){
   $order->setState(Order::STATE_COMPLETE);
   $order->setStatus(Order::STATE_COMPLETE);
   $this->_orderRepository->save($order);
}

If your order exists, but has no payment than you might have some inconsistent data for that order.

  • Yes that was just that... $order was null because is ID was null... Thanks. But it doesn't explained why this trigger a Paypal error ^^ – Morgan Tartreau Mar 20 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.