You are here

protected function PaymentGatewayBase::assertRefundAmount in Commerce Core 8.2

Asserts that the refund amount is valid.

Parameters

\Drupal\commerce_payment\Entity\PaymentInterface $payment: The payment.

\Drupal\commerce_price\Price $refund_amount: The refund amount.

Throws

\Drupal\commerce_payment\Exception\InvalidRequestException Thrown when the refund amount is larger than the payment balance.

2 calls to PaymentGatewayBase::assertRefundAmount()
Manual::refundPayment in modules/payment/src/Plugin/Commerce/PaymentGateway/Manual.php
Refunds the given payment.
Onsite::refundPayment in modules/payment_example/src/Plugin/Commerce/PaymentGateway/Onsite.php
Refunds the given payment.

File

modules/payment/src/Plugin/Commerce/PaymentGateway/PaymentGatewayBase.php, line 573

Class

PaymentGatewayBase
Provides the base class for payment gateways.

Namespace

Drupal\commerce_payment\Plugin\Commerce\PaymentGateway

Code

protected function assertRefundAmount(PaymentInterface $payment, Price $refund_amount) {
  $balance = $payment
    ->getBalance();
  if ($refund_amount
    ->greaterThan($balance)) {
    throw new InvalidRequestException(sprintf("Can't refund more than %s.", $balance
      ->__toString()));
  }
}