code: 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;
      }
docs: Handle the 'completed' state.
  
  @param PaymentInterface $payment
  
  @return bool Whether or not the shipment has been changed.