You are here

protected function PaymentMethodBase::executePaymentAccessCurrency in Payment 8.2

Checks a payment's currency against this plugin.

Parameters

\Drupal\Core\Session\AccountInterface $account:

Return value

\Drupal\Core\Access\AccessResultInterface

File

src/Plugin/Payment/Method/PaymentMethodBase.php, line 362

Class

PaymentMethodBase
A base payment method plugin.

Namespace

Drupal\payment\Plugin\Payment\Method

Code

protected function executePaymentAccessCurrency(AccountInterface $account) {
  $supported_currencies = $this
    ->getSupportedCurrencies();
  $payment_currency_code = $this
    ->getPayment()
    ->getCurrencyCode();
  $payment_amount = $this
    ->getPayment()
    ->getAmount();

  // If all currencies are allowed, grant access.
  if ($supported_currencies === TRUE) {
    return AccessResult::allowed();
  }

  // If the payment's currency is not specified, access is denied.
  foreach ($supported_currencies as $supported_currency) {
    if ($supported_currency
      ->getCurrencyCode() != $payment_currency_code) {
      continue;
    }
    elseif ($supported_currency
      ->getMinimumAmount() && $payment_amount < $supported_currency
      ->getMinimumAmount()) {
      return AccessResult::forbidden();
    }
    elseif ($supported_currency
      ->getMaximumAmount() && $payment_amount > $supported_currency
      ->getMaximumAmount()) {
      return AccessResult::forbidden();
    }
    else {
      return AccessResult::allowed();
    }
  }
  return AccessResult::forbidden();
}