maksuturva / magento2_payment_module

Svea Payment module for Magento 2
Other
4 stars 13 forks source link

PaymentMethodIsActive observer fails with payment methods using Magento\Payment\Model\Method\Adapter #12

Closed mattijv closed 1 year ago

mattijv commented 4 years ago

Preface

Although most first party Magento payment mehtods use the Magento\Payment\Model\Method\AbstractMethod as their base, that way of building payment methods is officially deprecated (see https://devdocs.magento.com/guides/v2.3/payments-integrations/payment-gateway/payment-gateway-intro.html). All future payment methods should extend the Magento\Payment\Model\Method\Adapter instead.

Issue

The Svea\Maksuturva\Model\Observer\PaymentMethodIsActive observer calls the getBaseConfigData of the method without checking if the method is an instance of Svea\Maksuturva\Model\PaymentAbstract where that method is defined. As previously all methods extended the Magento\Payment\Model\Method\AbstractMethod which is a subclass of the Magento\Framework\DataObject this worked by pure luck, since the DataObject magic methods handled the call to the undefined getBaseConfigData method.

However newer payment methods extend the Magento\Payment\Model\Method\Adapter which is not a subclass of Magento\Framework\DataObject and will therefore cause a fatal error when the undefined getBaseConfigData is called.

Possible fix

The observer should check that the method is an instance of the correct base class before calling a method only defined in that class.