<?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;
}
}
Any thoughts how to solve this error ? I am using magento version 2.4 we the call run through this file the error appears It seems like the variable is not getting any data in code. I need some fix to prevent this error
$returnValueis crated in atry - catchblock, but returned after. The only explanation is that the only line before it ($this->rollback->reset();) threw an exception so the execution of thetryblock stopped and the variable was never created.$returnValueis defined in the try block. But if the first instruction fails,$returnValueis never set. So you should declare it first after function header like$returnValue = null;