$this->eventDispatcher->
dispatch(new RecurringPaymentOrderCriteriaEvent($orderId,
$criteria,
$context));
/** @var OrderEntity $order */
$order =
$this->orderRepository->
search($criteria,
$context)->
first();
if (!
$order) { throw OrderException::
orderNotFound($orderId);
} $transactions =
$order->
getTransactions();
if ($transactions === null
) { throw OrderException::
missingTransactions($orderId);
} $transactions =
$transactions->
filterByStateId( $this->initialStateIdLoader->
get(OrderTransactionStates::STATE_MACHINE
) );
$transaction =
$transactions->
last();
if ($transaction === null
) { return;
}