You are here

public function Payment::getBalance in Commerce Core 8.2

Gets the payment balance.

The balance represents the payment amount minus the refunded amount.

Return value

\Drupal\commerce_price\Price|null The payment balance, or NULL if the payment does not have an amount yet.

Overrides PaymentInterface::getBalance

File

modules/payment/src/Entity/Payment.php, line 198

Class

Payment
Defines the payment entity class.

Namespace

Drupal\commerce_payment\Entity

Code

public function getBalance() {
  if ($amount = $this
    ->getAmount()) {
    $balance = $amount;
    if ($refunded_amount = $this
      ->getRefundedAmount()) {
      $balance = $balance
        ->subtract($refunded_amount);
    }
    return $balance;
  }
}