You are here

public function OrderPaymentIntentSubscriber::onOrderUpdate in Commerce Stripe 8

Ensures the Stripe payment intent is up to date.

Parameters

\Drupal\commerce_order\Event\OrderEvent $event: The event.

File

src/EventSubscriber/OrderPaymentIntentSubscriber.php, line 88

Class

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

Namespace

Drupal\commerce_stripe\EventSubscriber

Code

public function onOrderUpdate(OrderEvent $event) {
  $order = $event
    ->getOrder();
  $gateway = $order
    ->get('payment_gateway');
  if ($gateway
    ->isEmpty() || !$gateway->entity instanceof PaymentGatewayInterface) {
    return;
  }
  $plugin = $gateway->entity
    ->getPlugin();
  if (!$plugin instanceof StripeInterface) {
    return;
  }
  $intent_id = $order
    ->getData('stripe_intent');
  if ($intent_id === NULL) {
    return;
  }
  $total_price = $order
    ->getTotalPrice();
  if ($total_price !== NULL) {
    $amount = $this
      ->toMinorUnits($order
      ->getTotalPrice());
    $this->updateList[$intent_id] = $amount;
  }
}