You are here

public function OrderPaymentIntentSubscriber::destruct in Commerce Stripe 8

Performs destruct operations.

Overrides DestructableInterface::destruct

1 method overrides OrderPaymentIntentSubscriber::destruct()
DecoratedOrderPaymentIntentSubscriber::destruct in tests/modules/commerce_stripe_test/src/EventSubscriber/DecoratedOrderPaymentIntentSubscriber.php
Performs destruct operations.

File

src/EventSubscriber/OrderPaymentIntentSubscriber.php, line 63

Class

OrderPaymentIntentSubscriber
Subscribes to order events to syncronize orders with their payment intents.

Namespace

Drupal\commerce_stripe\EventSubscriber

Code

public function destruct() {
  foreach ($this->updateList as $intent_id => $amount) {
    try {
      $intent = PaymentIntent::retrieve($intent_id);

      // You may only update the amount of a PaymentIntent with one of the
      // following statuses: requires_payment_method, requires_confirmation.
      if (in_array($intent->status, [
        PaymentIntent::STATUS_REQUIRES_PAYMENT_METHOD,
        PaymentIntent::STATUS_REQUIRES_CONFIRMATION,
      ], TRUE)) {
        PaymentIntent::update($intent_id, [
          'amount' => $amount,
        ]);
      }
    } catch (StripeError $e) {

      // Allow sync errors to silently fail.
    }
  }
}