You are here

protected function RecurringOrderManager::selectPaymentMethod in Commerce Recurring Framework 8

Selects the payment method for the given subscriptions.

It is assumed that even if the billing schedule allows multiple subscriptions per recurring order, there will still be a single enforced payment method per customer. In case multiple payment methods are found, the more recent one will be used.

Parameters

\Drupal\commerce_recurring\Entity\SubscriptionInterface[] $subscriptions: The subscriptions.

Return value

\Drupal\commerce_payment\Entity\PaymentMethodInterface|null The payment method, or NULL if none were found.

2 calls to RecurringOrderManager::selectPaymentMethod()
RecurringOrderManager::closeOrder in src/RecurringOrderManager.php
Closes the given recurring order.
RecurringOrderManager::refreshOrder in src/RecurringOrderManager.php
Refreshes the given recurring order.

File

src/RecurringOrderManager.php, line 342

Class

RecurringOrderManager
Provides the default recurring order manager.

Namespace

Drupal\commerce_recurring

Code

protected function selectPaymentMethod(array $subscriptions) {
  $payment_methods = [];
  foreach ($subscriptions as $subscription) {
    if ($payment_method = $subscription
      ->getPaymentMethod()) {
      $payment_methods[$payment_method
        ->id()] = $payment_method;
    }
  }
  krsort($payment_methods, SORT_NUMERIC);
  $payment_method = reset($payment_methods);
  return $payment_method ?: NULL;
}