Payment/EventListener/AbstractPaymentListener.php
protected function handleCompletedState(PaymentInterface $payment)
    {
        $changed = false;

        $state = $payment->getState();
        $completedAt = $payment->getCompletedAt();

        if (PaymentStates::isPaidState($state) && null === $completedAt) {
            $payment->setCompletedAt(new \DateTime());
            $changed = true;
        } elseif (!PaymentStates::isPaidState($state) && null !== $completedAt) {
            $payment->setCompletedAt(null);
            $changed = true;
        }

        return $changed;
    }
protected function handleCompletedState(PaymentInterface $payment)
    {
        $changed = false;

        $state = $payment->getState();
        $completedAt = $payment->getCompletedAt();

        if (PaymentStates::isPaidState($state) && null === $completedAt) {
            $payment->setCompletedAt(new \DateTime());
            $changed = true;
        } elseif (!PaymentStates::isPaidState($state) && null !== $completedAt) {
            $payment->setCompletedAt(null);
            $changed = true;
        }

        return $changed;
    }
Handle the 'completed' state.

@param PaymentInterface $payment

@return bool Whether or not the shipment has been changed.