diff --git a/Gateway/Http/Client/TransactionCapture.php b/Gateway/Http/Client/TransactionCapture.php index 0ed6dbb10..05a71cbd7 100644 --- a/Gateway/Http/Client/TransactionCapture.php +++ b/Gateway/Http/Client/TransactionCapture.php @@ -72,8 +72,6 @@ public function placeRequest(TransferInterface $transferObject): array { $request = $transferObject->getBody(); $headers = $transferObject->getHeaders(); - $idempotencyKeyExtraData = $headers['idempotencyExtraData']; - unset($headers['idempotencyExtraData']); $clientConfig = $transferObject->getClientConfig(); $client = $this->adyenHelper->initializeAdyenClientWithClientConfig($clientConfig); @@ -86,6 +84,9 @@ public function placeRequest(TransferInterface $transferObject): array return $this->placeMultipleCaptureRequests($service, $request, $requestOptions); } + $idempotencyKeyExtraData = $request['idempotencyExtraData']; + unset($request['idempotencyExtraData']); + $idempotencyKey = $this->idempotencyHelper->generateIdempotencyKey( $request, $idempotencyKeyExtraData ?? null diff --git a/Gateway/Request/CaptureDataBuilder.php b/Gateway/Request/CaptureDataBuilder.php index 99b3d2354..ff8ce9557 100644 --- a/Gateway/Request/CaptureDataBuilder.php +++ b/Gateway/Request/CaptureDataBuilder.php @@ -109,7 +109,10 @@ public function build(array $buildSubject): array $requestBody = [ "amount" => $modificationAmount, "reference" => $payment->getOrder()->getIncrementId(), - "paymentPspReference" => $pspReference + "paymentPspReference" => $pspReference, + "idempotencyExtraData" => [ + 'totalInvoiced' => $payment->getOrder()->getTotalInvoiced() ?? 0 + ] ]; //Check additionaldata @@ -119,11 +122,6 @@ public function build(array $buildSubject): array } $request['body'] = $requestBody; $request['clientConfig'] = ["storeId" => $payment->getOrder()->getStoreId()]; - $request['headers'] = [ - 'idempotencyExtraData' => [ - 'totalInvoiced' => $payment->getOrder()->getTotalInvoiced() ?? 0 - ] - ]; return $request; } diff --git a/Test/Unit/Gateway/Http/Client/TransactionCaptureTest.php b/Test/Unit/Gateway/Http/Client/TransactionCaptureTest.php index 19348bed5..801c94f77 100644 --- a/Test/Unit/Gateway/Http/Client/TransactionCaptureTest.php +++ b/Test/Unit/Gateway/Http/Client/TransactionCaptureTest.php @@ -43,11 +43,12 @@ protected function setUp(): void 'amount' => ['value' => 100, 'currency' => 'USD'], 'paymentPspReference' => 'testPspReference', 'applicationInfo' => $applicationInfo, + 'idempotencyExtraData' => ['someData'] ]; $this->transferObject = $this->createConfiguredMock(TransferInterface::class, [ 'getBody' => $this->request, - 'getHeaders' => ['idempotencyExtraData' => ['someData']], + 'getHeaders' => [], 'getClientConfig' => [] ]); } @@ -63,10 +64,13 @@ private function configureAdyenMocks(array $response = null, \Exception $excepti $this->adyenHelper->method('buildRequestHeaders')->willReturn([]); $this->adyenHelper->expects($this->once())->method('logRequest'); + $trimmedRequest = $this->request; + unset($trimmedRequest['idempotencyExtraData']); + $this->idempotencyHelper->expects($this->once()) ->method('generateIdempotencyKey') ->with( - $this->request, + $trimmedRequest, $this->equalTo(['someData']) ) ->willReturn($expectedIdempotencyKey);