You are here

function stripe_payment_payment_method_update in Stripe 7

Implements hook_ENTITY_TYPE_ACTION().

1 call to stripe_payment_payment_method_update()
stripe_payment_payment_method_insert in stripe_payment/stripe_payment.module
Implements hook_ENTITY_TYPE_ACTION().

File

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

Code

function stripe_payment_payment_method_update(PaymentMethod $payment_method) {
  if ($payment_method->controller->name === 'StripePaymentMethodController') {
    $payment_method->controller_data += $payment_method->controller->controller_data_defaults;
    if ($payment_method->controller_data['keys']['mode']) {

      // Insert/Update stored Payment Method's keys.
      db_merge('stripe_payment_keys')
        ->key(array(
        'pmid' => $payment_method->pmid,
      ))
        ->fields(array(
        'secret' => $payment_method->controller_data['keys']['secret'],
        'publishable' => $payment_method->controller_data['keys']['publishable'],
      ))
        ->execute();
    }
    else {

      // Delete stored keys (if any).
      db_delete('stripe_payment_keys')
        ->condition('pmid', $payment_method->pmid)
        ->execute();
    }

    // Clear cached data related to this Payment Method.
    drupal_static_reset('StripePaymentMethodController::retrieveAccount');
    cache_clear_all("stripe_payment_method:{$payment_method->pmid}:", 'cache', TRUE);
  }
}