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 {