0

How can show BANK TRANSFER payments method to specific customer(s), I added customer attribute to the payment method. then if BANK TRANSFER is yes I want to display it to customer. so how can I do it?

1

I can suggest creating a module that will be responsible for displaying the payment methods by customer group.

E.g. Enable all payment methods and select visibility of each payment method as per customer group.

That way, all payment methods are activated but are only visible to specified customer groups.

1
  • thanks for the idea, but they have a custom field, we have to check it and show the method. – Lasantha Feb 23 '18 at 6:30
0

Finally I have written a module for solve it, this is a mix of related stack overflow answers. Thanks all who wrote valuable answers. This works for me. anyone can improve this, thanks

// First create a module 

// add an event \app\code\Vender\SetBanktranfer\etc

<?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="Vender_SetBanktranfer_EabledPgByCustomerattr" instance="Vender\SetBanktranfer\Observer\EabledPgByCustomerattr" />
 </event>
</config>

// My observer is EabledPgByCustomerattr - \app\code\Vender\SetBanktranfer\Observer
<?php
namespace Vender\SetBanktranfer\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\Request\DataPersistorInterface;
use Magento\Framework\App\ObjectManager;
class EabledPgByCustomerattr implements ObserverInterface
{
    public function __construct(\Psr\Log\LoggerInterface $logger)
    {
        $this->_logger = $logger;
    }
    /**
     *
     * @param \Magento\Framework\Event\Observer $observer
     * @return void
     */
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $result          = $observer->getEvent()->getResult();
        $method_instance = $observer->getEvent()->getMethodInstance();
        $quote           = $observer->getEvent()->getQuote();
        $this->_logger->info($method_instance->getCode());
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $customerSession = $objectManager->get('Magento\Customer\Model\Session');   
        $customerObj = $objectManager->create('Magento\Customer\Model\Customer')->load($customerSession->getCustomerId());      
        $approvedCredit = $customerObj->getData('approved_for_credit_acc');


                if ($method_instance->getCode() == 'banktransfer') {
                    if(($customerSession->isLoggedIn()) && ($approvedCredit == 1)) {
                        $result->setData('is_available', true);
                    }
                    else{
                        $result->setData('is_available', false);
                    }
                }

    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.