0
<?php

namespace StripeIntegration\Payments\Plugin\Sales\Model\Service;

class OrderService
{
    public function __construct(
        \StripeIntegration\Payments\Helper\Rollback $rollback,
        \StripeIntegration\Payments\Helper\GenericFactory $helperFactory
    ) {
        $this->rollback = $rollback;
        $this->helperFactory = $helperFactory;
    }

    public function aroundPlace($subject, \Closure $proceed, $order)
    {
        try
        {
            $this->rollback->reset();
            $returnValue = $proceed($order);
            $this->rollback->reset();
        }
        catch (\Exception $e)
        {
            $helper = $this->helperFactory->create();
            \StripeIntegration\Payments\Helper\Logger::log($e->getMessage());
            if ($order->getId())
            {
                // The order has already been saved, so we don't want to run the rollback. The exception likely occurred in an order_save_after observer.
                $this->rollback->reset();
                $helper->dieWithError($e->getMessage(), $e);
            }
            else
            {
                $msg = $e->getMessage();
                if (!$this->isAuthenticationRequiredMessage($msg))
                    $this->rollback->run($e);
                else
                    $this->rollback->reset(); // In case some customization is trying to place multiple split-orders

                $helper->dieWithError($e->getMessage(), $e);
            }
        }
        return $returnValue;
    }

}
1
  • Any thoughts on this how i can resolve this error ?
    – devhs
    Apr 17, 2021 at 8:07

1 Answer 1

1

Add following code outside of try...catch block

$returnValue = null;

Your code looks like:


<?php

namespace StripeIntegration\Payments\Plugin\Sales\Model\Service;

class OrderService
{
    public function __construct(
        \StripeIntegration\Payments\Helper\Rollback $rollback,
        \StripeIntegration\Payments\Helper\GenericFactory $helperFactory
    ) {
        $this->rollback = $rollback;
        $this->helperFactory = $helperFactory;
    }

    public function aroundPlace($subject, \Closure $proceed, $order)
    {
        $returnValue = null;
        try {
            $this->rollback->reset();
            $returnValue = $proceed($order);
            $this->rollback->reset();
        } catch (\Exception $e) {
            $helper = $this->helperFactory->create();
            \StripeIntegration\Payments\Helper\Logger::log($e->getMessage());
            if ($order->getId()) {
                // The order has already been saved, so we don't want to run the rollback. The exception likely occurred in an order_save_after observer.
                $this->rollback->reset();
                $helper->dieWithError($e->getMessage(), $e);
            } else {
                $msg = $e->getMessage();
                if (!$this->isAuthenticationRequiredMessage($msg))
                    $this->rollback->run($e);
                else
                    $this->rollback->reset(); // In case some customization is trying to place multiple split-orders

                $helper->dieWithError($e->getMessage(), $e);
            }
        }
        return $returnValue;
    }

}
1
  • Hello, thanks for the answer, i have tried that but it shows another error Error: Call to a member function getAllItems() on null in Magento2/vendor/magento/module-downloadable/Observer/SetHasDownloadableProductsObserver.php:36
    – devhs
    Apr 17, 2021 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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