Shopping is no more constrained by geographic borders as online Ecommerce stores are ruling the global market. Whenever online shopping is considered, payment methods prove to be the most vital factor. According to a survey, the lack of a preferred payment method is the most common cause of cart abandonment, which needs to be taken seriously. When it comes to Magento 2, being the most popular Ecommerce platform, it provides many default payment methods.

However, sometimes you may need to create a custom payment method in Magento 2 store to integrate with your choice of payment gateway if it’s not already available.

Here, we are providing steps to create a new custom payment method in Magento 2 with a simple example:

In this blog, we will focus on implementing Stripe payment gateway. Create following files one by one:

1. Create Magecomp/Stripe/registration.php to register your payment gateway extension.

2. Create Magecomp/Stripe/composer.json

3. Create Magecomp/Stripe/etc/module.xml to define your module name.

4. Create Magecomp/Strpe/etc/config.xml to define your stripe payment method.

5. Create Magecomp/Stripe/etc/adminhtml/system.xml to display payment method in admin payment method section.

6. Create Magecomp/Stripe/etc/frontend/di.xml for dependency Injection configuration.

7. Create model file to define payment method Magecomp/Stripe/Model/Payment.php

8. Create model file to define Allowed CC type Magecomp/Stripe/Model/Source/Cctype.php

9. Create Magecomp/Stripe/view/frontend/web/js/view/payment/ stripepayments.js to register our template or renderer file.

10. Create Magecomp/Stripe/view/frontend/web/js/view/payment/method-renderer/ stripemethod.js

11. Create Magecomp/Stripe/view/frontend/web/template/payment/stripe.html template file.

12. Create Magecomp/Stripe/view/frontend/layout/checkout_index_index.xml to define payment method at checkout page.

Run below commands to install above extension:

If you have followed the steps in a perfect manner, you can see your custom payment method (here Stripe payment method) at checkout page. I hope this guide was helpful to serve your purpose. Comments and queries are always welcomed.

Payment API

[Total: 21   Average: 4/5]