I am trying to override Magento Payment Helper data in my extension but it's not working.

I have overriden by using the preference method.

I have put below code in app/code/Demo/PaymentTest/etc/di.xml

<preference for="Magento\Payment\Helper\Data" type="Demo\PaymentTest\Helper\Data" />

Here is my Helper code

namespace Demo\PaymentTest\Helper;
class Data extends \Magento\Payment\Helper\Data
    public function getStoreMethods($store = null, $quote = null)

I am trying to override getStoreMethods method in my helper but it's not calling it.

Can you please tell me what am I doing wrong?

  • What are you trying to achieve ? Depending on the reason why you want to rewrite that method using plugins would be more appropriate – Raphael at Digital Pianism Jan 2 '17 at 11:30
  • Please share code how can i rewrite that method by using plugins? I want to restrict payment method. – Sanjay Jethva Jan 2 '17 at 11:33
  • 2
    @SanjayJethva, what Magento version do you use? Since Magento 2.1.3 \Magento\Payment\Helper\Data::getStoreMethods is deprecated and doesn't call anymore, use \Magento\Payment\Model\PaymentMethodList::getActiveList instead – joni jones Jan 3 '17 at 8:36
  • Hello @jonijones, Its working and thanks for your answer. – Sanjay Jethva Jan 3 '17 at 10:42

If you want to rewrite payment method, I suggest you use a plugin.

Create the following di.xml in the etc folder of your module:

    <type name="Magento\Payment\Helper\Data">
        <plugin name="restrictPaymentMethods" type="Demo\PaymentTest\Plugin\RestrictPaymentMethods" sortOrder="1" />

Then create Plugin\RestrictPaymentMethods.php :


namespace Demo\PaymentTest\Plugin;

class RestrictPaymentMethods

    public function afterGetStoreMethods(\Magento\Payment\Helper\Data $subject, $result)
        // $result will contain the original result
        // You can modify the $result array to restrict the payment methods
  • Hello @raphael-at-digital-pianism, Thanks for your answer. I have tried your code but its not working. File is calling but method is not calling. Thanks – Sanjay Jethva Jan 3 '17 at 5:35

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.