Payment/EventListener/PaymentDoneEventSubscriber.php
public function onStatus(PaymentEvent $event)
    {
        $payment = $event->getPayment();

        $sale = $payment->getSale();

        if ($sale instanceof OrderInterface) {
            return;
        }

        if ($sale instanceof CartInterface && $sale->getState() !== CartStates::STATE_ACCEPTED) {
            return;
        }

        if ($sale instanceof QuoteInterface && $sale->getState() !== QuoteStates::STATE_ACCEPTED) {
            return;
        }

        // Store payment tokens
        $tokens = $this->findPaymentTokens($payment);

        // Transform sale to order
        if (null === $order = $this->transform($sale)) {
            return;
        }

        // Find order's transformed payment
        $newPayment = null;
        foreach ($order->getPayments() as $p) {
            if ($p->getNumber() === $payment->getNumber()) {
                $newPayment = $p;
                break;
            }
        }
        if (null === $newPayment) {
            throw new RuntimeException("Failed to find the transformed payment.");
        }

        // Convert tokens
        $this->convertTokens($this->getPaymentIdentity($newPayment), $tokens);

        // Set event new payment
        $event->setPayment($newPayment);
    }
public function onStatus(PaymentEvent $event)
    {
        $payment = $event->getPayment();

        $sale = $payment->getSale();

        if ($sale instanceof OrderInterface) {
            return;
        }

        if ($sale instanceof CartInterface && $sale->getState() !== CartStates::STATE_ACCEPTED) {
            return;
        }

        if ($sale instanceof QuoteInterface && $sale->getState() !== QuoteStates::STATE_ACCEPTED) {
            return;
        }

        // Store payment tokens
        $tokens = $this->findPaymentTokens($payment);

        // Transform sale to order
        if (null === $order = $this->transform($sale)) {
            return;
        }

        // Find order's transformed payment
        $newPayment = null;
        foreach ($order->getPayments() as $p) {
            if ($p->getNumber() === $payment->getNumber()) {
                $newPayment = $p;
                break;
            }
        }
        if (null === $newPayment) {
            throw new RuntimeException("Failed to find the transformed payment.");
        }

        // Convert tokens
        $this->convertTokens($this->getPaymentIdentity($newPayment), $tokens);

        // Set event new payment
        $event->setPayment($newPayment);
    }
Payment status event handler.

Transforms an accepted cart/quote to an order.

@param PaymentEvent $event