craftcms/commerce-paypal-checkout

Handling PayPal errors doesn't work

boboldehampsink opened this issue · 1 comments

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

  • Craft version: 4
  • Commerce PayPal Checkout version: 2.1
  • Commerce version: 4.1
  • PHP version: 8.1
  • Database driver & version: PostgreSQL
  • Other Plugins & versions: -

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

Hi @boboldehampsink

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

Thanks!