From a2ae80b7496db9f1da9b858b1a6738a7a6b0c325 Mon Sep 17 00:00:00 2001 From: Can Demiralp Date: Wed, 21 Feb 2024 15:28:01 +0100 Subject: [PATCH 1/4] [ECP-8715] Fix PaymentsDetails class after merge conflict --- Helper/PaymentsDetails.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Helper/PaymentsDetails.php b/Helper/PaymentsDetails.php index 2e1dbff0c..632d3062b 100644 --- a/Helper/PaymentsDetails.php +++ b/Helper/PaymentsDetails.php @@ -62,9 +62,10 @@ public function initiatePaymentDetails(OrderInterface $order, array $payload): a try { $client = $this->adyenHelper->initializeAdyenClient($order->getStoreId()); - $service = $this->adyenHelper->initialize - - ($client); + $service = $this->adyenHelper->initializePaymentsApi($client); + + $requestOptions['idempotencyKey'] = $this->idempotencyHelper->generateIdempotencyKey($request); + $requestOptions['headers'] = $this->adyenHelper->buildRequestHeaders(); $requestOptions['idempotencyKey'] = $this->idempotencyHelper->generateIdempotencyKey($request); $requestOptions['headers'] = $this->adyenHelper->buildRequestHeaders(); From 09e1089b248ae56a3f79376dd15f56ce434f6a67 Mon Sep 17 00:00:00 2001 From: Can Demiralp Date: Wed, 21 Feb 2024 15:28:25 +0100 Subject: [PATCH 2/4] [ECP-8715] Fix unit tests after merge conflict --- Test/Unit/Helper/PaymentDetailsTest.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Test/Unit/Helper/PaymentDetailsTest.php b/Test/Unit/Helper/PaymentDetailsTest.php index 47f1373e6..cb4933870 100644 --- a/Test/Unit/Helper/PaymentDetailsTest.php +++ b/Test/Unit/Helper/PaymentDetailsTest.php @@ -15,6 +15,7 @@ use Adyen\AdyenException; use Adyen\Payment\Helper\PaymentsDetails; use Adyen\Payment\Test\Unit\AbstractAdyenTestCase; +use Adyen\Service\Checkout; use Magento\Framework\Exception\ValidatorException; use Magento\Sales\Api\Data\OrderInterface; use Magento\Sales\Model\Order\Payment; @@ -67,24 +68,23 @@ protected function setUp(): void public function testInitiatePaymentDetailsSuccessfully() { - $orderMock = $this->createMock(OrderInterface::class); - $paymentMock = $this->createMock(Payment::class); $serviceMock = $this->createMock(PaymentsApi::class); $adyenClientMock = $this->createMock(Client::class); - $storeId = 1; - $payload = json_encode([ - 'details' => 'some_details', - 'merchantReference' => '00000000001' + $payload = [ + 'details' => [ + 'some_value' => 'some_details', + 'merchantReference' => '00000000001' + ], 'paymentData' => 'some_payment_data', 'threeDSAuthenticationOnly' => true, - ]); + ]; $requestOptions = [ 'idempotencyKey' => 'some_idempotency_key', 'headers' => ['headerKey' => 'headerValue'] ]; - $paymentDetailsResult = ['resultCode' => 'Authorised', 'action' => null, 'additionalData' => null]; + $paymentDetailsResult = ['resultCode' => 'Authorised']; $this->adyenHelperMock->method('initializeAdyenClient')->willReturn($adyenClientMock); $this->adyenHelperMock->method('initializePaymentsApi')->willReturn($serviceMock); $this->adyenHelperMock->method('buildRequestHeaders')->willReturn($requestOptions['headers']); From 1189bf684f78bb6893ce58b548c4254925aa64c5 Mon Sep 17 00:00:00 2001 From: Can Demiralp Date: Wed, 21 Feb 2024 16:37:07 +0100 Subject: [PATCH 3/4] [ECP-8715] Fix unit tests after merge conflict --- Test/Unit/Helper/PaymentDetailsTest.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Test/Unit/Helper/PaymentDetailsTest.php b/Test/Unit/Helper/PaymentDetailsTest.php index cb4933870..346de42f8 100644 --- a/Test/Unit/Helper/PaymentDetailsTest.php +++ b/Test/Unit/Helper/PaymentDetailsTest.php @@ -15,7 +15,6 @@ use Adyen\AdyenException; use Adyen\Payment\Helper\PaymentsDetails; use Adyen\Payment\Test\Unit\AbstractAdyenTestCase; -use Adyen\Service\Checkout; use Magento\Framework\Exception\ValidatorException; use Magento\Sales\Api\Data\OrderInterface; use Magento\Sales\Model\Order\Payment; @@ -48,7 +47,7 @@ protected function setUp(): void $this->orderMock = $this->createMock(OrderInterface::class); $this->paymentMock = $this->createMock(Payment::class); - $this->checkoutServiceMock = $this->createMock(Checkout::class); + $this->checkoutServiceMock = $this->createMock(PaymentsApi::class); $this->adyenClientMock = $this->createMock(Client::class); $this->orderMock->method('getPayment')->willReturn($this->paymentMock); @@ -56,7 +55,7 @@ protected function setUp(): void $this->paymentMock->method('getOrder')->willReturn($this->orderMock); $this->adyenHelperMock->method('initializeAdyenClient')->willReturn($this->adyenClientMock); - $this->adyenHelperMock->method('createAdyenCheckoutService')->willReturn($this->checkoutServiceMock); + $this->adyenHelperMock->method('initializePaymentsApi')->willReturn($this->checkoutServiceMock); $this->paymentDetails = new PaymentsDetails( $this->checkoutSessionMock, @@ -90,7 +89,7 @@ public function testInitiatePaymentDetailsSuccessfully() $this->adyenHelperMock->method('buildRequestHeaders')->willReturn($requestOptions['headers']); $this->idempotencyHelperMock->method('generateIdempotencyKey')->willReturn($requestOptions['idempotencyKey']); - $serviceMock->expects($this->once()) + $this->checkoutServiceMock->expects($this->once()) ->method('paymentsDetails') ->with( $this->callback(function(PaymentDetailsRequest $detailsRequest) { From 416a91ed6fe70fe001c3fffaed80748f8298d5fd Mon Sep 17 00:00:00 2001 From: Can Demiralp Date: Wed, 21 Feb 2024 17:27:47 +0100 Subject: [PATCH 4/4] [ECP-8715] Fix redundant line --- Helper/PaymentsDetails.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/Helper/PaymentsDetails.php b/Helper/PaymentsDetails.php index 632d3062b..fa502e9b6 100644 --- a/Helper/PaymentsDetails.php +++ b/Helper/PaymentsDetails.php @@ -67,9 +67,6 @@ public function initiatePaymentDetails(OrderInterface $order, array $payload): a $requestOptions['idempotencyKey'] = $this->idempotencyHelper->generateIdempotencyKey($request); $requestOptions['headers'] = $this->adyenHelper->buildRequestHeaders(); - $requestOptions['idempotencyKey'] = $this->idempotencyHelper->generateIdempotencyKey($request); - $requestOptions['headers'] = $this->adyenHelper->buildRequestHeaders(); - $paymentDetailsObj = $service->paymentsDetails(new PaymentDetailsRequest($request), $requestOptions); $response = json_decode(json_encode($paymentDetailsObj->jsonSerialize()), true); } catch (AdyenException $e) {