Skip to content

Commit

Permalink
[ECP-9501] Fix response handling for PayPal express payments (#126)
Browse files Browse the repository at this point in the history
* [ECP-9501] Bump required module-payment version

* [ECP-9501] Remove gift card related response data and return /payments response

---------

Co-authored-by: Can Demiralp <[email protected]>
Co-authored-by: Peter Ojo <[email protected]>
  • Loading branch information
3 people authored Oct 23, 2024
1 parent cb091f4 commit cef16f2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 19 additions & 1 deletion Model/AdyenInitPayments.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,10 @@ public function execute(

try {
$response = $this->transactionPaymentClient->placeRequest($transfer);
$paymentsResponse = $this->returnFirstTransactionPaymentResponse($response);

return json_encode(
$this->paymentResponseHandler->formatPaymentResponse($response['resultCode'], $response['action'])
$this->paymentResponseHandler->formatPaymentResponse($paymentsResponse['resultCode'], $paymentsResponse['action'])
);
} catch (Exception $e) {
throw new ClientException(
Expand Down Expand Up @@ -200,4 +202,20 @@ protected function buildPaymentsRequest(Quote $quote, array $stateData): array

return array_merge($request, $stateData);
}

/**
* This method cleans up the unnecessary gift card response data
* and returns the actual `/payments` API response.
*
* @param array $response
* @return array
*/
private function returnFirstTransactionPaymentResponse(array $response): array
{
if (array_key_exists('hasOnlyGiftCards', $response)) {
unset($response['hasOnlyGiftCards']);
}

return reset($response);
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
],
"require": {
"adyen/module-payment": "^9.7.1"
"adyen/module-payment": "^9.8.1"
},
"require-dev": {
"phpunit/phpunit": "~9.6.1",
Expand Down

0 comments on commit cef16f2

Please sign in to comment.