Skip to content

Commit fe23313

Browse files
d-g-codappixclaude
andcommitted
[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 <noreply@anthropic.com>
1 parent e2c1d66 commit fe23313

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

‎Classes/Controller/Order/PaymentController.php‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,14 @@ private function updatePaymentAndTransaction($notify, Item $orderItem, string $s
154154

155155
$payment = $orderItem->getPayment();
156156

157-
foreach ($payment->getTransactions() as $transaction) {
158-
if ($transaction->getTxnId() === ($notify->getResponseParam('gcReference'))) {
157+
$transaction = null;
158+
foreach ($payment->getTransactions() as $paymentTransaction) {
159+
if ($paymentTransaction->getTxnId() === $notify->getResponseParam('gcReference')) {
160+
$transaction = $paymentTransaction;
159161
break;
160162
}
161163
}
162-
if (!isset($transaction)) {
164+
if ($transaction === null) {
163165
throw new Exception('No transaction found!', 1731616906);
164166
}
165167

‎Tests/Functional/Controller/Order/PaymentControllerNotifyActionTest.php‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,25 @@ public function notificationForPaymentWithoutTransactionIsRejected(): void
191191
self::assertSame([], EventRecorder::getEvents());
192192
}
193193

194+
#[Test]
195+
public function notificationForUnknownTransactionIsRejected(): void
196+
{
197+
$this->get(ConnectionPool::class)
198+
->getConnectionForTable('tx_cart_domain_model_order_transaction')
199+
->update('tx_cart_domain_model_order_transaction', ['txn_id' => 'gc-reference-0002'], ['uid' => 1]);
200+
201+
try {
202+
$this->sendNotification(self::RESULT_PAYMENT_SUCCESSFUL, self::TYPOSCRIPT_SECRET);
203+
self::fail('The notification for an unknown transaction has been accepted.');
204+
} catch (\Exception $exception) {
205+
self::assertSame(1731616906, $exception->getCode());
206+
}
207+
208+
self::assertSame('open', $this->getPayment()['status']);
209+
self::assertSame('created', $this->getTransaction()['status']);
210+
self::assertSame([], EventRecorder::getEvents());
211+
}
212+
194213
#[Test]
195214
public function notifyActionRespondsWithEmptyBody(): void
196215
{

0 commit comments

Comments
 (0)