checkout-magento2-plugin icon indicating copy to clipboard operation
checkout-magento2-plugin copied to clipboard

Model\Api\V3::processPayment method is broken. Using array as object

Open andrej22116 opened this issue 3 months ago • 0 comments

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.

andrej22116 avatar Apr 05 '24 15:04 andrej22116