From e78eb3a4a202516aab1b6b5f9acc05cd0fdff9b2 Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Sun, 22 Nov 2026 17:03:42 +0100 Subject: [PATCH] [BUGFIX] Reject notifications for unknown transactions If no transaction of the payment matched the gcReference of the notification, the last transaction of the payment was updated and the payment was marked as paid or canceled anyway. The notification is now rejected like a notification for a payment without any transaction. Co-Authored-By: Claude Opus 5.5 --- .../Controller/Order/PaymentController.php | 8 +++++--- .../PaymentControllerNotifyActionTest.php | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Classes/Controller/Order/PaymentController.php b/Classes/Controller/Order/PaymentController.php index 70bc9fd..933fe67 100644 --- a/Classes/Controller/Order/PaymentController.php +++ b/Classes/Controller/Order/PaymentController.php @@ -154,12 +154,14 @@ private function updatePaymentAndTransaction($notify, Item $orderItem, string $s $payment = $orderItem->getPayment(); - foreach ($payment->getTransactions() as $transaction) { - if ($transaction->getTxnId() === ($notify->getResponseParam('gcReference'))) { + $transaction = null; + foreach ($payment->getTransactions() as $paymentTransaction) { + if ($paymentTransaction->getTxnId() === $notify->getResponseParam('gcReference')) { + $transaction = $paymentTransaction; break; } } - if (!isset($transaction)) { + if ($transaction === null) { throw new Exception('No transaction found!', 1731616906); } diff --git a/Tests/Functional/Controller/Order/PaymentControllerNotifyActionTest.php b/Tests/Functional/Controller/Order/PaymentControllerNotifyActionTest.php index fcc7ee9..895ffe0 100644 --- a/Tests/Functional/Controller/Order/PaymentControllerNotifyActionTest.php +++ b/Tests/Functional/Controller/Order/PaymentControllerNotifyActionTest.php @@ -191,6 +191,25 @@ public function notificationForPaymentWithoutTransactionIsRejected(): void self::assertSame([], EventRecorder::getEvents()); } + #[Test] + public function notificationForUnknownTransactionIsRejected(): void + { + $this->get(ConnectionPool::class) + ->getConnectionForTable('tx_cart_domain_model_order_transaction') + ->update('tx_cart_domain_model_order_transaction', ['txn_id' => 'gc-reference-0002'], ['uid' => 1]); + + try { + $this->sendNotification(self::RESULT_PAYMENT_SUCCESSFUL, self::TYPOSCRIPT_SECRET); + self::fail('The notification for an unknown transaction has been accepted.'); + } catch (\Exception $exception) { + self::assertSame(1731616906, $exception->getCode()); + } + + self::assertSame('open', $this->getPayment()['status']); + self::assertSame('created', $this->getTransaction()['status']); + self::assertSame([], EventRecorder::getEvents()); + } + #[Test] public function notifyActionRespondsWithEmptyBody(): void {