Reputation:
<?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
Upvotes: 0
Views: 235
Reputation: 1095
The problem is you're trying to access the variable returnValue
which is not defined. Your code throws an exception in the closure (or it could be in the reset()
function), so returnValue
is never defined.
What's happening:
returnValue
is never definedA possible fix it to declare the variable with some value on top like shown below
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; // Or have it equal to some meaningful value
try
{
$this->rollback->reset();
$returnValue = $proceed($order);
$this->rollback->reset();
}
catch (\Exception $e)
{
// handle exception
}
return $returnValue;
}
}
Upvotes: 1