If you are developing any payment related extension in Magento2 and you want to get the active Payment methods list with the multi selection option in Magento configuration,
You can follow this code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
use \Magento\Framework\App\Config\ScopeConfigInterface; use \Magento\Payment\Model\Config; class Paymethods implements \Magento\Framework\Option\ArrayInterface { protected $_appConfigScopeConfigInterface; protected $_paymentModelConfig; public function __construct( ScopeConfigInterface $appConfigScopeConfigInterface, Config $paymentModelConfig) { $this->_appConfigScopeConfigInterface = $appConfigScopeConfigInterface; $this->_paymentModelConfig = $paymentModelConfig; } public function toOptionArray() { $payments = $this->_paymentModelConfig->getActiveMethods(); $methods = array(); foreach ($payments as $paymentCode=>$paymentModel) { $paymentTitle = $this->_appConfigScopeConfigInterface->getValue('payment/'.$paymentCode.'/title'); $methods[$paymentCode] = array( 'label' => $paymentTitle, 'value' => $paymentCode ); } return $methods; } } |
Do let us know if you face any trouble or suggestions. We will always be happy to assist you.
Happy Coding.
Click to rate this post!
[Total: 5 Average: 4.6]