Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ECP-9534] Fix success page displayed if payment is canceled #2796

Merged
merged 3 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions Controller/Return/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,6 @@ protected function validateRedirectResponse(array $redirectResponse): bool
// Make paymentsDetails call to validate the payment
$request["details"] = $redirectResponse;
$paymentsDetailsResponse = $this->paymentsDetailsHelper->initiatePaymentDetails($order, $request);

if ($this->isResponseAlreadyProcessed($order, $paymentsDetailsResponse)) {
$this->adyenLogger->addAdyenResult('Duplicate response detected. Skipping processing.');
return true;
}
} catch (Exception $e) {
$paymentsDetailsResponse['error'] = $e->getMessage();
}
Expand Down Expand Up @@ -195,27 +190,6 @@ private function getOrder(string $incrementId = null): Order
return $order;
}

private function isResponseAlreadyProcessed(Order $order, array $paymentsDetailsResponse): bool
{
$pspReference = $paymentsDetailsResponse['pspReference'] ?? null;
$merchantReference = $paymentsDetailsResponse['merchantReference'] ?? null;

if (!$pspReference || !$merchantReference) {
return false;
}

$history = $order->getStatusHistories();

foreach ($history as $status) {
$comment = $status->getComment();
if (str_contains($comment, $pspReference) !== false) {
return true;
}
}

return false;
}

/**
* @return void
* @throws Exception
Expand Down
32 changes: 9 additions & 23 deletions Test/Unit/Controller/Return/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ private static function testDataProvider(): array
'orderId' => PHP_INT_MAX,
'expectedException' => null,
'multishipping' => false,
'orderStatusHistory' => ['Payment received'],
'isDuplicate' => false
'orderStatusHistory' => ['Payment received']
],
[
'redirectResponse' => [
Expand All @@ -154,8 +153,7 @@ private static function testDataProvider(): array
'orderId' => 'ORDER123',
'expectedException' => null,
'multishipping' => false,
'orderStatusHistory' => ['PSP reference: PSP123456789'],
'isDuplicate' => true
'orderStatusHistory' => ['PSP reference: PSP123456789']
],
];
}
Expand All @@ -171,8 +169,7 @@ public function testExecute(
$orderId,
$expectedException,
$multishipping,
$orderStatusHistory,
$isDuplicate
$orderStatusHistory
) {
// Set up order status history
$orderStatusHistoryCollectionMock = $this->createMock(OrderStatusHistoryCollection::class);
Expand Down Expand Up @@ -209,24 +206,13 @@ public function testExecute(
$this->orderEntityMock->method('getIncrementId')->willReturn($orderId);
$this->paymentsDetailsHelperMock->method('initiatePaymentDetails')
->willReturn($paymentsDetailsResponse);
$this->adyenLoggerMock->expects($this->once())
->method('addAdyenResult')
->with('Processing redirect response');
$this->paymentResponseHandlerMock->expects($this->once())
->method('handlePaymentsDetailsResponse')
->willReturn($responseHandlerResult);

if ($isDuplicate) {
$this->adyenLoggerMock->expects($this->exactly(2))
->method('addAdyenResult')
->withConsecutive(
['Processing redirect response'],
['Duplicate response detected. Skipping processing.']
);
$this->paymentResponseHandlerMock->expects($this->never())
->method('handlePaymentsDetailsResponse');
} else {
$this->adyenLoggerMock->expects($this->once())
->method('addAdyenResult')
->with('Processing redirect response');
$this->paymentResponseHandlerMock->expects($this->once())
->method('handlePaymentsDetailsResponse')
->willReturn($responseHandlerResult);
}

$this->indexControllerMock->execute();
}
Expand Down
Loading