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;
    }