You are here

public function OrderPaymentGateway::evaluate in Commerce Core 8.2

Evaluates the condition.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity.

Return value

bool TRUE if the condition has been met, FALSE otherwise.

Overrides ConditionInterface::evaluate

File

modules/payment/src/Plugin/Commerce/Condition/OrderPaymentGateway.php, line 63

Class

OrderPaymentGateway
Provides the payment gateway condition for orders.

Namespace

Drupal\commerce_payment\Plugin\Commerce\Condition

Code

public function evaluate(EntityInterface $entity) {
  $this
    ->assertEntity($entity);

  /** @var \Drupal\commerce_order\Entity\OrderInterface $order */
  $order = $entity;
  if ($order
    ->get('payment_gateway')
    ->isEmpty()) {

    // The payment gateway is not known yet, the condition cannot pass.
    return FALSE;
  }

  // Avoiding ->target_id to allow the condition to be unit tested,
  // because Prophecy doesn't support magic properties.
  $payment_gateway_item = $order
    ->get('payment_gateway')
    ->first()
    ->getValue();
  $payment_gateway_id = $payment_gateway_item['target_id'];
  return in_array($payment_gateway_id, $this->configuration['payment_gateways']);
}