dotpay / magento2-payment

New payment module for Magento 2
2 stars 11 forks source link

Dotpay\Exception\BadParameter for currency and language #18

Open ilnytskyi opened 3 years ago

ilnytskyi commented 3 years ago
\Dotpay\Resource\Channel\Request

This class throws exception like

Dotpay\Exception\BadParameter\LanguageException: Incorrect language: nl

or

Incorrect currency:

Even when the module is disabled. In our case this happened for Nederlands and Serbia I looks like the module does not check if a certain feature is active when retreiving the config

payment/dotpay_main/active,0
payment/dotpay_oc/active,0
payment/dotpay_cc/active,0
\Dotpay\Payment\Model\Ui\AbstractConfigProvider::getConfig
and here
\Dotpay\Payment\Model\Ui\AbstractConfigProvider::getAgreements
It always builds and send a request

None of exceptions from \Dotpay\Resource\Channel\Request should happen and no requests to Dotpay server should be sent if the module is disabled under a store or globally.

On timeline view we can see that module performs curl request even when disabled, that cost our CPU additional 450ms.

Selection_580

Please fix both issues.

WORKAROUND: Patch methods, and add a fallback to accepted values instead of throwing an exception

        if (!Language::validate($language)) {
            //throw new LanguageException($language);
            //fallback to english
            $language = (string) 'en';
        }