You are here

public function PaymentGateway::applies in Commerce Core 8.2

Checks whether the payment gateway applies to the given order.

Ensures that the conditions pass.

Parameters

\Drupal\commerce_order\Entity\OrderInterface $order: The order.

Return value

bool TRUE if payment gateway applies, FALSE otherwise.

Overrides PaymentGatewayInterface::applies

File

modules/payment/src/Entity/PaymentGateway.php, line 224

Class

PaymentGateway
Defines the payment gateway entity class.

Namespace

Drupal\commerce_payment\Entity

Code

public function applies(OrderInterface $order) {
  $conditions = $this
    ->getConditions();
  if (!$conditions) {

    // Payment gateways without conditions always apply.
    return TRUE;
  }
  $order_conditions = array_filter($conditions, function ($condition) {

    /** @var \Drupal\commerce\Plugin\Commerce\Condition\ConditionInterface $condition */
    return $condition
      ->getEntityTypeId() == 'commerce_order';
  });
  $order_conditions = new ConditionGroup($order_conditions, $this
    ->getConditionOperator());
  return $order_conditions
    ->evaluate($order);
}