You are here

public function EcheckTransactionVerifier::getPayments in Commerce Authorize.Net 8

Gets payments to process.

Return value

\Drupal\commerce_payment\Entity\PaymentInterface[] An array of payments keyed by the entity id.

Overrides PaymentProcessorInterface::getPayments

File

src/EcheckTransactionVerifier.php, line 56

Class

EcheckTransactionVerifier
Verify echeck transaction states.

Namespace

Drupal\commerce_authnet

Code

public function getPayments() {
  $payment_gateway_storage = $this->entityTypeManager
    ->getStorage('commerce_payment_gateway');
  $payment_gateway_ids = $payment_gateway_storage
    ->getQuery()
    ->condition('plugin', 'authorizenet_echeck')
    ->execute();
  if (empty($payment_gateway_ids)) {
    return [];
  }

  /** @var \Drupal\commerce_payment\Entity\PaymentGatewayInterface[] $payment_gateways */
  $payment_gateways = $payment_gateway_storage
    ->loadMultiple($payment_gateway_ids);
  $payment_gateway_plugins = [];
  foreach ($payment_gateways as $payment_gateway) {
    $payment_gateway_plugins[$payment_gateway
      ->getPluginId()] = $payment_gateway
      ->getPlugin();
  }

  // Get settled transactions.
  $payments = [];
  $now = date('Y-m-d\\TH:i:s', $this->time
    ->getCurrentTime());
  $two_days_ago = date('Y-m-d\\TH:i:s', $this->time
    ->getCurrentTime() - 480 * 3600);

  /** @var \Drupal\commerce_authnet\Plugin\Commerce\PaymentGateway\EcheckInterface $plugin */
  foreach ($payment_gateway_plugins as $plugin) {
    $payments += $plugin
      ->getSettledTransactions($two_days_ago, $now);
  }
  return $payments;
}