How To Create Payment Method In Magento 2

How To Create Payment Method In Magento 2

A payment gateway is a key to secure E-commerce business. Selecting a payment method that is suitable for your business type deserves proper attention. A wrong choice is going to be a disaster for your payment system. A customer’s trust and loyalty depend on the payment processing system you offer.

How a payment gateway should be?

  • 100% secure
  • Compatible with your store platform
  • Offers speedy payment process
  • Fraud detection
  • Invoicing capabilities
  • Impressive UI
  • Feasible costs
  • Support for international payments
  • Support policy
  • Types of cards supported
  • Support for recurring payments
  • Hosted/Non hosted payments

If you are a Magento store owner, you need to filter out the points that must be fulfilled by the payment gateway you use for your business requirements.

However, an ideal payment gateway that fulfills all your requirements exists only in a parallel world. But wait, you can create payment method in Magento 2 on your own! And this post shows you how to do it.

Steps to Create Payment Method in Magento 2:

  1. Create registration.php file at app/code/Meetanshi/CustomPayment/registration.php and add the below code to it:
  2. Create module.xml file at app/code/Meetanshi/CustomPayment/etc/module.xml and add below code to this file:
  3. Create config.xml file at app/code/Meetanshi/CustomPayment/etc/config.xml and add below code to this file:
  4. Create system.xml file at app/code/Meetanshi/CustomPayment/etc/adminhtml/system.xml and add below code to this file:
  5. Create PaymentMethod.php file at app/code/Meetanshi/CustomPayment/Model/PaymentMethod.php add below code to this file:
  6. Create checkout_index_index.xml file at app/code/Meetanshi/CustomPayment/view/frontend/layout/checkout_index_index.xml and add below code to this file:
  7. Create a method-renderer.js file at app/code/Meetanshi/CustomPayment/view/frontend/web/js/view/payment/method-renderer.js and add below code to this file:
  8. Create custompayment.js file at app/code/Meetanshi/CustomPayment/view/frontend/web/js/view/payment/method-renderer/custompayment.js add below code to this file:
  9. Create customtemplate.html file at app/code/Meetanshi/CustomPayment/view/frontend/web/template/payment/customtemplate.html and add below code to this file:
     

That’s it for creating custom payment methods in Magento 2 store. The extension will create backend settings to enable the payment method and set a title for it.

custom payment method creation

Once, the payment method is enabled, it can be displayed in the frontend while checking out the products:

custom payment method on checkout page in frontend

If you can find readymade solutions from here for your Magento 2 store, you would never need to visit this post again!

Please mention any doubts on the topic in the Comments section below. I’d be happy to help.

Do share the post with fellow developers via social media.

Thank you.

5
(based on 6 Reviews)

Sanjay is a co-founder at Meetanshi. He is a Certified Magento Developer who loves creating Magento E-commerce solutions. Owing to his contributions in Magento Forums and posting solutions, he is among the top 50 contributors of the Magento community in 2019. When he is not engrossed with anything related to Magento, he loves to play cricket.

Leave a reply:

Your email address will not be published.

SUBSCRIBE
3.8
(based on 5 Reviews)