I am trying to disable all payment methods when specific payment method is enabled for some set of pin codes.
Please find below code to get an idea of what I am doing.
di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Vendor\Module\Model\Module">
<plugin sortOrder="1" name="restrictByCustomer" type="Vendor\Module\Plugin\Payment\Method\Module\Available"/>
</type>
</config>
app/code/Vendor/Module/Plugin/Payment/Method/Module/Available.php
<?php
namespace Vendor\Module\Plugin\Payment\Method\Module;
use Magento\Customer\Model\Session as CustomerSession;
use Magento\Backend\Model\Auth\Session as BackendSession;
use Vendor\Module\Model\Module;
use \Magento\Checkout\Model\Session as CheckoutSession;
class Available
{
protected $checkoutSession;
protected $customerSession;
protected $backendSession;
public function __construct(
CustomerSession $customerSession,
BackendSession $backendSession,
CheckoutSession $checkoutSession
) {
$this->customerSession = $customerSession;
$this->backendSession = $backendSession;
$this->checkoutSession = $checkoutSession;
}
public function afterIsAvailable(\Magento\Payment\Model\Method\AbstractMethod $subject, $result)
{
$paymentMethods = $subject->getCode(); //I am getting only one payment method. I want to get all payment methods here.
if($subject->getCode() == 'clickcanarias')
{
return false;
}
return $result;
}
}
Basically, I am trying to disable all payment methods when my payment method is active. I want to get all the payment methods list in $subject
. For that purpose which class needs to override?