You are here

function stripe_payment_payment_load in Stripe 7

Implements hook_ENTITY_TYPE_ACTION().

File

stripe_payment/stripe_payment.module, line 292
Stripe Payment module.

Code

function stripe_payment_payment_load($payments) {

  // Discard non-Stripe payments.
  $payments = array_filter($payments, function (Payment $payment) {
    return $payment->method->controller->name === 'StripePaymentMethodController';
  });
  if ($payments) {

    // Collect pids.
    $pids = array_map(function (Payment $payment) {
      return $payment->pid;
    }, $payments);

    // Load stored data (all payments at once).
    $method_data = db_select('stripe_payment_data', 'spd')
      ->fields('spd', array(
      'pid',
      'type',
      'id',
    ))
      ->condition('pid', $pids)
      ->execute()
      ->fetchAllAssoc('pid', PDO::FETCH_ASSOC);
    foreach ($payments as $payment) {
      if (isset($method_data[$payment->pid])) {
        $payment->method_data[$method_data[$payment->pid]['type']] = $method_data[$payment->pid]['id'];
      }
    }
  }
}