Skip to content

Commit

Permalink
[ECP-9580] Fix partial capture request (#2839)
Browse files Browse the repository at this point in the history
Co-authored-by: Can Demiralp <[email protected]>
  • Loading branch information
candemiralp and Can Demiralp authored Dec 30, 2024
1 parent 3ab803c commit fe49f91
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
5 changes: 3 additions & 2 deletions Gateway/Http/Client/TransactionCapture.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
10 changes: 4 additions & 6 deletions Gateway/Request/CaptureDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
8 changes: 6 additions & 2 deletions Test/Unit/Gateway/Http/Client/TransactionCaptureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => []
]);
}
Expand All @@ -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);
Expand Down

0 comments on commit fe49f91

Please sign in to comment.