MultiSafepay / magento2

MultiSafepay plugin for Magento 2
Open Software License 3.0
19 stars 8 forks source link

Cron job sales_clean_orders fails when order contains no payment method #54

Closed ainigma32 closed 11 months ago

ainigma32 commented 1 year ago

The cron job sales_clean_orders fails if the order does not contain a valid payment.

The error occurs in MultiSafepay\ConnectCore\Util\PaymentMethodUtil::isMultisafepayOrder(OrderInterface $order): bool When executing the code:

return $this->checkIsMultisafepayMethodByPayment($order->getPayment()->getMethodInstance());

the assumption is made that $order->getPayment() will always return a \Magento\Sales\Api\Data\OrderPaymentInterface

However in the docblock of Magento\Sales\Api\Data\OrderInterface ::getPayment() it says that the return value can also be null.

This occours on Magento 2.4.5-p1 using version 3.1.0 of the MSP plugin

As a workaround we changed the code to:

    /**
     * @param OrderInterface $order
     * @return bool
     */
    public function isMultisafepayOrder(OrderInterface $order): bool
    {
        if($order->getPayment() === null) {
           return false;
        }
        return $this->checkIsMultisafepayMethodByPayment($order->getPayment()->getMethodInstance());
    }
vinodsowdagar commented 1 year ago

Hi @ainigma32 ,

Thank you for reporting this. We will look into it and come back to you later.

vinodsowdagar commented 1 year ago

Hi @ainigma32 ,

We will add the proposed change in the new version. We'll let you know when it has been released.

vinodsowdagar commented 11 months ago

Hi @ainigma32 ,

We've introduced a new release where this issue has been fixed: https://github.com/MultiSafepay/magento2/releases/tag/3.1.2

I'm closing this issue for now. Please add a new comment if there are any related comments and we will reopen this if needed.