This is an example for magento/magento2#33869.
- At least Magento 2.4.0 installation
- A product with price > 0
- Install this module
- Execute
composer config repositories.oneserv-magento2-33869 composer https://github.com/oneserv-heuser/magento2-33869
- Execute
composer require oneserv/magento2-33869 @dev
- Execute
- Execute
bin/magento module:enable Oneserv_ExamplePaymentMethod
- Execute
bin/magento setup:upgrade
- Create an empty cart via GraphQl
- Add your product to the cart
- Request all available payment methods
The payment method oneserv_example_payment_method
should not be available as the
AvailabilityValidator always returns false.
The payment method was created exactly as stated in the docs for creating payment methods.
The method is always available.
The cause of the problem is that Adapter::isAvailable() gets called from MethodList::getAvailableMethods(). The Adapter::isAvailable() method then tries to get the infoInstance as seen on line 290. If it's null it will not execute the availability validator from the validatorPool which would return false. The infoInstance is ALWAYS null in this case as the method instance gets freshly created from it's factory. The MethodList::getAvailableMethods() sets the infoInstance AFTER it calls the Adapter::isAvailable() method. So there is no way the validator gets called when using the new Payment Provider Gateway.
I guess this issue was never found as all of magentos payment methods are using the deprecated AbstractMethod class. I think this should be fixed asap as the method MethodList::getAvailableMethods() MUST work for all payment methods, especially if they're implemented the way they should be and not with deprecated classes.
I've implemented a workaround for this bug. It can be found in the Model of the payment method.
There I overwrite the isAvailable() function. At the moment the fix is not executed. To see the fix in action just
remove line 80 from the Model of the payment method and request all
available payment methods from the cart again. The payment method oneserv_example_payment_method
is not
available anymore.