/** @var OrderTransactionEntity $lastTransaction */
$lastTransaction =
$transactions->
last();
foreach ($transactions as $transaction) { if ($transaction->
getPaymentMethodId() ===
$paymentMethodId &&
$lastTransaction->
getId() ===
$transaction->
getId()) { $initialState =
$this->initialStateIdLoader->
get(OrderTransactionStates::STATE_MACHINE
);
if ($transaction->
getStateId() ===
$initialState) { return true;
} try { $this->orderService->
orderTransactionStateTransition( $transaction->
getId(),
StateMachineTransitionActions::ACTION_REOPEN,
new ParameterBag(),
$context );
return true;
} catch (IllegalTransitionException
) { // if we can't reopen the last transaction with a matching payment method
// we have to create a new transaction and cancel the previous one
} }