code: protected function updatePaymentTotal(SaleInterface $sale)
      {
          $changed = false;
  
          $currency = $sale->getCurrency()->getCode();
  
          // Update paid total if needed
          $paid = $this->paymentCalculator->calculatePaidTotal($sale);
          if (0 != Money::compare($paid, $sale->getPaidTotal(), $currency)) {
              $sale->setPaidTotal($paid);
              $changed = true;
          }
          // Update pending total total if needed
          $pending = $this->paymentCalculator->calculateOfflinePendingTotal($sale);
          if (0 != Money::compare($pending, $sale->getPendingTotal(), $currency)) {
              $sale->setPendingTotal($pending);
              $changed = true;
          }
          // Update accepted outstanding total if needed
          $acceptedOutstanding = $this->paymentCalculator->calculateOutstandingAcceptedTotal($sale);
          if (0 != Money::compare($acceptedOutstanding, $sale->getOutstandingAccepted(), $currency)) {
              $sale->setOutstandingAccepted($acceptedOutstanding);
              $changed = true;
          }
          // Update expired outstanding total if needed
          $expiredOutstanding = $this->paymentCalculator->calculateOutstandingExpiredTotal($sale);
          if (0 != Money::compare($expiredOutstanding, $sale->getOutstandingExpired(), $currency)) {
              $sale->setOutstandingExpired($expiredOutstanding);
              $changed = true;
          }
  
          // If payment totals has changed and fund has been released
          if ($changed && $this->outstandingReleaser->releaseFund($sale)) {
              // Re-update the outstanding totals
              //$sale->setPaidTotal($this->paymentCalculator->calculatePaidTotal($sale));
              //$sale->setPendingTotal($this->paymentCalculator->calculateOfflinePendingTotal($sale));
              $sale->setOutstandingAccepted($this->paymentCalculator->calculateOutstandingAcceptedTotal($sale));
              $sale->setOutstandingExpired($this->paymentCalculator->calculateOutstandingExpiredTotal($sale));
          }
  
          return $changed;
      }
docs: Updates the payment totals total.
  
  @param SaleInterface $sale
  
  @return bool Whether the sale has been changed or not.