Skip to content
Snippets Groups Projects
Commit ef7b6f0f authored by Matt Glaman's avatar Matt Glaman Committed by Bojan Živanović
Browse files

Issue #3079162 by mglaman, carstenG: OrderPaymentIntentSubscriber cannot run...

Issue #3079162 by mglaman, carstenG: OrderPaymentIntentSubscriber cannot run against completed payment intents
parent 5fb79fdb
No related branches found
Tags 7.x-3.2
No related merge requests found
......@@ -63,7 +63,15 @@ class OrderPaymentIntentSubscriber implements EventSubscriberInterface, Destruct
public function destruct() {
foreach ($this->updateList as $intent_id => $amount) {
try {
PaymentIntent::update($intent_id, ['amount' => $amount]);
$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.
......
......@@ -236,6 +236,9 @@ class Stripe extends OnsitePaymentGatewayBase implements StripeInterface {
\Stripe\PaymentIntent::update($intent->id, [
'metadata' => $metadata,
]);
$order->unsetData('stripe_intent');
$order->save();
}
catch (\Stripe\Error\Base $e) {
ErrorHelper::handleException($e);
......
......@@ -3,3 +3,7 @@ services:
class: Drupal\commerce_stripe_test\EventSubscriber\TransactionDataSubscriber
tags:
- { name: event_subscriber }
commerce_stripe_test.decorated_order_payment_intent_subscriber:
class: Drupal\commerce_stripe_test\EventSubscriber\DecoratedOrderPaymentIntentSubscriber
parent: commerce_stripe.order_events_subscriber
decorates: commerce_stripe.order_events_subscriber
<?php
namespace Drupal\commerce_stripe_test\EventSubscriber;
use Drupal\commerce_order\Event\OrderEvent;
use Drupal\commerce_stripe\EventSubscriber\OrderPaymentIntentSubscriber;
use Stripe\Error\Base as StripeError;
use Stripe\PaymentIntent;
class DecoratedOrderPaymentIntentSubscriber extends OrderPaymentIntentSubscriber {
/**
* {@inheritdoc}
*/
public function destruct() {
foreach ($this->updateList as $intent_id => $amount) {
try {
PaymentIntent::update($intent_id, ['amount' => $amount]);
}
catch (StripeError $e) {
// Ensure all API exceptions throw during testing.
throw $e;
}
}
}
}
......@@ -77,6 +77,7 @@ class CreatePaymentTest extends StripeIntegrationTestBase {
$order->set('payment_method', $payment_method);
$order->set('payment_gateway', $gateway);
$order->save();
$this->container->get('commerce_stripe.order_events_subscriber')->destruct();
$payment = Payment::create([
'state' => 'new',
......@@ -103,6 +104,10 @@ class CreatePaymentTest extends StripeIntegrationTestBase {
// Tests metadata set by commerce_stripe_test.
$this->assertEquals($intent->metadata['payment_uuid'], $payment->uuid());
$order = $this->reloadEntity($order);
$this->assertNull($order->getData('stripe_intent'));
$order->getState()->applyTransitionById('place');
$order->save();
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment