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

TypeError: Argument 1 passed to regexReplace() must be of the type string #40

Closed RitterKnightCreative closed 3 years ago

RitterKnightCreative commented 3 years ago

Description

Upgraded from 1.2.0 to 1.2.2.

Getting a generic error message after clicking/tapping on any of the options: PayPal button, Pay Later or Debit/Credit Card.

server-error

Stack trace leads back to this:

2021-07-06 19:44:29 [-][-][-][error][TypeError] TypeError: Argument 1 passed to craft\helpers\StringHelper::regexReplace() must be of the type string, null given, called in /home/NEW/vendor/craftcms/commerce-paypal-checkout/src/gateways/Gateway.php on line 543 and defined in /home/NEW/vendor/craftcms/cms/src/helpers/StringHelper.php:1069
Stack trace:
#0 /home/NEW/vendor/craftcms/commerce-paypal-checkout/src/gateways/Gateway.php(543): craft\helpers\StringHelper::regexReplace()
#1 /home/NEW/vendor/craftcms/commerce-paypal-checkout/src/gateways/Gateway.php(510): craft\commerce\paypalcheckout\gateways\Gateway->_buildPurchaseUnits()
#2 /home/NEW/vendor/craftcms/commerce-paypal-checkout/src/gateways/Gateway.php(310): craft\commerce\paypalcheckout\gateways\Gateway->buildCreateOrderRequestData()
#3 /home/NEW/vendor/craftcms/commerce/src/services/Payments.php(285): craft\commerce\paypalcheckout\gateways\Gateway->purchase()
#4 /home/NEW/vendor/craftcms/commerce/src/controllers/PaymentsController.php(440): craft\commerce\services\Payments->processPayment()
#5 [internal function]: craft\commerce\controllers\PaymentsController->actionPay()
#6 /home/NEW/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()
#7 /home/NEW/vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams()
#8 /home/NEW/vendor/craftcms/cms/src/web/Controller.php(190): yii\base\Controller->runAction()
#9 /home/NEW/vendor/yiisoft/yii2/base/Module.php(534): craft\web\Controller->runAction()
#10 /home/NEW/vendor/craftcms/cms/src/web/Application.php(278): yii\base\Module->runAction()
#11 /home/NEW/vendor/craftcms/cms/src/web/Application.php(581): craft\web\Application->runAction()
#12 /home/NEW/vendor/craftcms/cms/src/web/Application.php(257): craft\web\Application->_processActionRequest()
#13 /home/NEW/vendor/yiisoft/yii2/base/Application.php(392): craft\web\Application->handleRequest()
#14 /home/NEW/web/index.php(23): yii\base\Application->run()
#15 {main}

Downgrading to 1.2.0 seems to solve the issue.

I noticed the code that was changed was here.

I'm not sure why my Craft::$app->getConfig()->getGeneral()->siteName would be null though? I noticed {{ siteName }} from a Twig template works just fine but dumping out the general config it's null. It seems to be set just fine in the CP?

Additional info

nfourtythree commented 3 years ago

Hi @RitterKnightCreative

Thank you for bringing this to our attention. We have pushed up a fix for this issue and will look to get a release out asap.

Thanks!

elivz commented 3 years ago

FYI this fix makes the plugin no longer compatible with Craft < 3.6 (the stated requirement in the readme and composer.json is 3.3.4.1 or higher). The $site->getName() method was added in 3.6, prior to that you'd have to use $site->name instead.

nfourtythree commented 3 years ago

Good spot @elivz thanks for that. I wrongly assumed we had increased the cms version requirement.

The code has been updated to just reference ->name which is compatible with versions 3.3.4 and upwards. In versions on or after 3.6 this will simply call the getName method via a magic method. This will be refactored when the cms requirement is updated.

Pushing out a patch for this now.

Thanks again!