code: protected function calculateTotalByState(PaymentSubjectInterface $subject, $state)
      {
          PaymentStates::isValidState($state, true);
  
          $currency = $subject->getCurrency()->getCode();
  
          $total = 0;
  
          foreach ($subject->getPayments() as $payment) {
              if ($payment->getState() === $state) {
                  $total += $this->convertPaymentAmount($payment, $currency);
              }
          }
  
          return $total;
      }
docs: Calculates the payments total by state.
  
  @param PaymentSubjectInterface $subject
  @param string                  $state
  
  @return float