Sonata\Component\Payment\PaymentHandler::getValidOrder PHP Method

getValidOrder() protected method

Retrieves the order matching $transaction and adds it to $transaction.
protected getValidOrder ( Sonata\Component\Payment\TransactionInterface $transaction ) : Sonata\Component\Order\OrderInterface
$transaction Sonata\Component\Payment\TransactionInterface The request's transaction (will be linked to the order in the process)
return Sonata\Component\Order\OrderInterface
    protected function getValidOrder(TransactionInterface $transaction)
    {
        $payment = $this->getPayment($transaction->getPaymentCode());
        // retrieve the related order
        $reference = $payment->getOrderReference($transaction);
        if (!$reference) {
            throw new InvalidTransactionException();
        }
        $order = $this->orderManager->findOneby(array('reference' => $reference));
        if (!$order) {
            throw new EntityNotFoundException(sprintf('Order %s', $reference));
        }
        $transaction->setOrder($order);
        // control the handshake value
        if (!$payment->isRequestValid($transaction)) {
            throw new InvalidTransactionException($order->getReference());
        }
        return $order;
    }