checkout-magento2-plugin
checkout-magento2-plugin copied to clipboard
Model\Api\V3::processPayment method is broken. Using array as object
The problem
I ran into the following problem: for some reason, the $response array is being used as an object.
// CheckoutCom\Magento2\Model\Api\V3
private function processPayment(): array
{
// ...
// Get the payment
$response = $this->getPaymentResponse($amount, $currency, $reference); // $response has an array type
if ($this->api->isValidResponse($response)) {
// Process the payment response
$is3ds = property_exists($response, '_links')
&& isset($response->_links['redirect'])
&& isset($response->_links['redirect']['href']);
// ...
// Update the result
$this->result['success'] = $response->isSuccessful();
} else {
// ...
}
}
The method $this->api->isValidResponse expects an array and it get it, 'cause $this->getPaymentResponse return an array (or null).
// CheckoutCom\Magento2\Model\Service\ApiHandlerService
public function isValidResponse(array $response): bool
{
// ...
}
The alleged reason
I found out that this use of $response was correct as long as the legacy checkout/checkout-sdk-php v1.0.0 was used. I realized this by comparing the methods of the $response object used with the methods of the Model class.
Future
I do not know for what reason it turned out that this code still exists, but it causes errors that have to be fixed. I hope that this will be fixed in future releases.