-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom payment methods are always available when using new Payment Provider Gateway #33869
Comments
Hi @oneserv-heuser. Thank you for your report.
Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:
For more details, please, review the Magento Contributor Assistant documentation. Please, add a comment to assign the issue:
🕙 You can find the schedule on the Magento Community Calendar page. 📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket. 🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel ✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel |
I can confirm that this issue exists, but not on an vanilla instance because of the nature of the problem. |
Hi @engcom-Echo. Thank you for working on this issue.
|
I reported this issue before It was closed with no solution: |
@JeffersonTeixeira The classical stale-bot treatment How did you fix it? Did you use the fix @ksenia-zlotin provided? |
For anyone stumbling across this, here is a temporary solution: <?php
declare(strict_types=1);
namespace Oneserv\B2BInvoice\Model\Method;
use Magento\Framework\App\Area;
use Magento\Framework\App\State;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Payment\Gateway\Command\CommandManagerInterface;
use Magento\Payment\Gateway\Command\CommandPoolInterface;
use Magento\Payment\Gateway\Config\ValueHandlerPoolInterface;
use Magento\Payment\Gateway\Data\PaymentDataObjectFactory;
use Magento\Payment\Gateway\Validator\ValidatorPoolInterface;
use Magento\Payment\Model\Method\Adapter;
use Magento\Quote\Api\Data\CartInterface;
use Magento\Quote\Model\Quote;
use Psr\Log\LoggerInterface;
/**
* Class B2BInvoice
*/
class B2BInvoice extends Adapter
{
private State $state;
/**
* B2BInvoice constructor.
*
* @param ManagerInterface $eventManager
* @param ValueHandlerPoolInterface $valueHandlerPool
* @param PaymentDataObjectFactory $paymentDataObjectFactory
* @param string $code
* @param string $formBlockType
* @param string $infoBlockType
* @param State $state
* @param CommandPoolInterface|null $commandPool
* @param ValidatorPoolInterface|null $validatorPool
* @param CommandManagerInterface|null $commandExecutor
* @param LoggerInterface|null $logger
*/
public function __construct(
ManagerInterface $eventManager,
ValueHandlerPoolInterface $valueHandlerPool,
PaymentDataObjectFactory $paymentDataObjectFactory,
string $code,
string $formBlockType,
string $infoBlockType,
State $state,
CommandPoolInterface $commandPool = null,
ValidatorPoolInterface $validatorPool = null,
CommandManagerInterface $commandExecutor = null,
LoggerInterface $logger = null
) {
parent::__construct(
$eventManager,
$valueHandlerPool,
$paymentDataObjectFactory,
$code,
$formBlockType,
$infoBlockType,
$commandPool,
$validatorPool,
$commandExecutor,
$logger
);
$this->state = $state;
}
/**
* @inheritdoc
* This is a temporary workaround for https://github.com/magento/magento2/issues/33869.
* It sets the info instance before the method gets executed. Otherwise, the validator doesn't get called
* correctly.
*/
public function isAvailable(CartInterface $quote = null)
{
if ($quote === null) {
return parent::isAvailable($quote);
}
/** @var Quote $quote */
/*
* This is needed to avoid issues when creating a new order via adminhtml. There is an error as the quote has
* empty data and somewhere deep in magento it causes an issue.
*/
try {
if (
$this->state->getAreaCode() === Area::AREA_ADMINHTML &&
$quote->getDataByKey(Quote::KEY_STORE_ID) === null
) {
return parent::isAvailable($quote);
}
} catch (LocalizedException $exception) {
return parent::isAvailable($quote);
}
$this->setInfoInstance($quote->getPayment());
return parent::isAvailable($quote);
}
} |
Hi @engcom-Lima. Thank you for working on this issue.
|
Hi @oneserv-heuser, Thank you for reporting the issue. Also please update below information:
|
Hi @engcom-Lima, |
Probably this is not an issue, but the way checks for Payment Method need to be added is bit different? The checks of Payment Method is also handled using the interface So we need to add a custom mapping and pass this as an argument in di.xml So something like below
Our custom check class should implement |
Hey @engcom-Lima Can you please have a look at my example and try to reproduce the issue? |
✅ Jira issue https://jira.corp.adobe.com/browse/AC-6081 is successfully created for this GitHub issue. |
✅ Confirmed by @engcom-Hotel. Thank you for verifying the issue. |
Having the same issue.... after roughly two years. Thanks for the workaround though. |
Preconditions (*)
Steps to reproduce (*)
Expected result (*)
Actual result (*)
Cause of the problem
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.
Possible workarounds
This is definitly nothing I want to do as I have no idea about the side effects on other payment methods using the deprecated model.
I will do this until this issue is fixed.
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.
The text was updated successfully, but these errors were encountered: