You are here

public function PaymentGatewayStorage::loadForUser in Commerce Core 8.2

Loads the default payment gateway for the given user.

Used primarily when adding payment methods from the user pages. Thus, only payment gateways which support storing payment methods are considered.

Parameters

\Drupal\user\UserInterface $account: The user account.

Return value

\Drupal\commerce_payment\Entity\PaymentGatewayInterface The payment gateway.

Overrides PaymentGatewayStorageInterface::loadForUser

File

modules/payment/src/PaymentGatewayStorage.php, line 70

Class

PaymentGatewayStorage
Defines the payment gateway storage.

Namespace

Drupal\commerce_payment

Code

public function loadForUser(UserInterface $account) {
  $payment_gateways = $this
    ->loadByProperties([
    'status' => TRUE,
  ]);
  $payment_gateways = array_filter($payment_gateways, function ($payment_gateway) {
    return $payment_gateway
      ->getPlugin() instanceof SupportsStoredPaymentMethodsInterface;
  });

  // @todo Implement resolving logic.
  $payment_gateway = reset($payment_gateways);
  return $payment_gateway;
}