I want selected customer group members only pay via Paypal, how to restrict by using Event Observer.
I just try this https://community.magento.com/t5/Magento-2-x-Programming/Magento-2-2-Observer-to-restrict-a-payment-... but not getting clarity, any help thanks.
Hello @Aveeva
Please follow the below steps to solve the issue:
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <event name="payment_method_is_active"> <observer name="disable_payment" instance="Vendor\Extension\Observer\PaymentMethodAvailable" /> </event> </config>
<?php namespace Vendor\Extension\Observer; use Magento\Framework\Event\ObserverInterface; class PaymentMethodAvailable implements ObserverInterface { public function execute(\Magento\Framework\Event\Observer $observer) { // you can replace "checkmo" with your required payment method code if($observer->getEvent()->getMethodInstance()->getCode()=="checkmo"){ $checkResult = $observer->getEvent()->getResult(); $checkResult->setData('is_available', false); } } }
I hope it helps.
Thank you.