craftcms / commerce-paypal-checkout

PayPal Checkout gateway for Craft Commerce.
https://plugins.craftcms.com/commerce-paypal-checkout
MIT License
5 stars 10 forks source link

Handling PayPal errors doesn't work #62

Closed boboldehampsink closed 2 years ago

boboldehampsink commented 2 years ago

Description Handling PayPal errors doesn't work because of wrong type hinting.

To Reproduce How, and what happened?

  1. When PayPal returns an error, it gets handled and cast as an object, where it expects an HttpResponse. Seeing the following error:
    TypeError: craft\commerce\paypalcheckout\gateways\Gateway::getResponseModel(): Argument #1 ($data) must be of type PayPalHttp\HttpResponse, stdClass given, called in /app/vendor/craftcms/commerce-paypal-checkout/src/gateways/Gateway.php on line 484
    File "/app/vendor/craftcms/commerce-paypal-checkout/src/gateways/Gateway.php", line 366, in craft\commerce\paypalcheckout\gateways\Gateway::getResponseModel
    public function getResponseModel(HttpResponse $data): RequestResponseInterface
    File "/app/vendor/craftcms/commerce-paypal-checkout/src/gateways/Gateway.php", line 484, in craft\commerce\paypalcheckout\gateways\Gateway::completePurchase
    return $this->getResponseModel($data);
    File "/app/vendor/craftcms/commerce/src/services/Payments.php", line 423, in craft\commerce\services\Payments::completePayment
    $response = $gateway->completePurchase($transaction);
    File "/app/vendor/craftcms/commerce/src/controllers/PaymentsController.php", line 480, in craft\commerce\controllers\PaymentsController::actionCompletePayment
    $success = $plugin->getPayments()->completePayment($transaction, $error);
    File "/app/vendor/yiisoft/yii2/base/InlineAction.php", line 57, in yii\base\InlineAction::runWithParams
    return call_user_func_array([$this->controller, $this->actionMethod], $args);
    ...

Expected behavior Error handling to work

Additional info

Additional context See this line where a stdClass is created instead of a HttpResponse: https://github.com/craftcms/commerce-paypal-checkout/blob/develop/src/gateways/Gateway.php#L474

nfourtythree commented 2 years ago

Hi @boboldehampsink

Thank you for reporting this, it has been fixed in version 2.1.0.1 of this plugin.

Thanks!