{"id":19901,"date":"2021-09-02T13:34:44","date_gmt":"2021-09-02T13:34:44","guid":{"rendered":"https:\/\/www.cmarix.com\/blog\/?p=19901"},"modified":"2026-04-14T12:09:19","modified_gmt":"2026-04-14T12:09:19","slug":"how-to-create-private-or-custom-payment-method-in-magento-2","status":"publish","type":"post","link":"https:\/\/www.cmarix.com\/blog\/how-to-create-private-or-custom-payment-method-in-magento-2\/","title":{"rendered":"Use Case To Create Private or Custom Payment Method in Magento"},"content":{"rendered":"<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\" \"http:\/\/www.w3.org\/TR\/REC-html40\/loose.dtd\">\n<?xml encoding=\"utf-8\" ?><html><body><p>Magento has introduced impeccable payment gateways with an exclusive custom field. <a href=\"https:\/\/www.cmarix.com\/hire-magento-developer.html\">Hire a Magento Developers<\/a> and install a simple and easy payment gateway in your application.<\/p>\n<p>Payment Method assumes a significant part in running online businesses. Payment Method goes about as the heart of the online portal. There is no Payment Method, the customer won&rsquo;t feel good, influencing the online business. Magento 2 has a few inherent payment gateways like Paypal, Braintree, and so on. In some cases, it is needed to integrate a custom payment gateway.<\/p>\n<p>Magento 2 Create Payment Method proves that store admin have the right to produce however many payment methods as they need when your store depends on the Magento 2 stage, an incredible time of eCommerce architecture. Contingent upon the customer&rsquo;s necessity, you likely plug it in your rundown of the current payment method. The different <a href=\"https:\/\/www.adyen.com\/payment-methods\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">payment methods<\/a> bring the diversity of customer choice when they continue to checkout on your site. On the other hand, many payment methods are the incredible methodology to connect the worldwide commercial center.<\/p>\n<p>Here, we will teach you through a simple method suggested by <a href=\"https:\/\/www.cmarix.com\/magento-development.html\">Magento Development Company<\/a>:<\/p>\n<p><strong>(1)<\/strong> Steps of <strong>Create Custom Payment Method<\/strong> : First of all, Create <strong>registration.php<\/strong> file to register your module at <strong><em>app\/code\/Cmarix\/CustomPayment\/<\/em><\/strong> file path and paste the below code :<\/p>\n<h2 class=\"wp-block-heading\">Magento 2 Payment Methods API<\/h2>\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/lh3.googleusercontent.com\/wttRKc6Hw5ap7rY0vEtPBZMPfVFSpePewvRAtnvY9OUlif9r3lXWWTWZrcckVh8c4ePawz8mXiTBJZ4T4hptm2H492gLBxJNnCM1qX_B3_SqlUwtjR77W5w=s0\" alt=\"Payment Methods API\" loading=\"lazy\" decoding=\"async\"><\/figure>\n<p><strong>(2)<\/strong> Secondly, Create <strong>module.xml<\/strong> to define your module at <strong><em>app\/code\/Cmarix\/CustomPayment\/etc\/<\/em><\/strong> file path and paste the below code :<\/p>\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/lh4.googleusercontent.com\/ppbAqo7e83RiOEtPsMglzaE_FmTxK43uAra01KJjFSBQOnV0LhB-1e4uoXQBBdb04jbUVPPS8vhSfEJ_RWPG_ptv06oNp4KPCOiA7uY2kS7x5T52k9TQVHE=s0\" alt=\"Secondly Create\" loading=\"lazy\" decoding=\"async\"><\/figure>\n<p><strong>(3)<\/strong> Then, Create <strong>config.xml<\/strong> file to set your payment method active at <strong><em>app\/code\/Cmarix\/CustomPayment\/etc\/<\/em><\/strong> and paste the below code :<\/p>\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/lh3.googleusercontent.com\/DctcpHl-B01awYmkJVgOJU_7a-W5zmjam_QgU9P3tU5LrprA7qdMFgG71woPBHp4NxedRBvMGLJCY0MCD9tUlVwn55czxv3pmCNT0eck9wkEf1dXVGnVPBc=s0\" alt=\"Then Create\" loading=\"lazy\" decoding=\"async\"><\/figure>\n<p><strong>(4)<\/strong> Now, For display payment method in configuration Create <strong>system.xml<\/strong> file at <strong><em>app\/code\/Cmarix\/CustomPayment\/etc\/adminhtml\/<\/em><\/strong> and paste the below code :<\/p>\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/lh3.googleusercontent.com\/AetK5618hM-espAVEiIVwstvalDNVzAykJFL01nTKwy2VVmBKKMGMuj206S9jvAjvebeo50zQRSoQNz5LwNMEfSTlQnYReWcxfN6lt_mSR4oue9SxkkIGQw=s0\" alt=\"Now\" loading=\"lazy\" decoding=\"async\"><\/figure>\n<figure class=\"wp-block-image is-style-default\"><a href=\"https:\/\/www.cmarix.com\/inquiry.html\"><img class=\"alignnone\" src=\"https:\/\/lh4.googleusercontent.com\/V242yz_hnDXD9P3UIkU5FUp6XDpXHFBs_lbw_bLFT292AMr7tLJuM7Obvhym0RSf4LPwNuSuxMj_7JiFY80RGv4GFKXdmnIR_Y1fWzzy7WCizURW1dePFI4=s0\" alt=\"Hire Magento Developer India\" width=\"951\" height=\"271\" loading=\"lazy\" decoding=\"async\"><\/a><\/figure>\n<p>In addition, you can add more fields in the custom payment method based on your requirement.<\/p>\n<p><strong>(5)<\/strong> After that, To define the payment method, Create <strong>PaymentMethod.php<\/strong> file at <strong><em>app\/code\/Cmarix\/CustomPayment\/Model\/<\/em><\/strong> and paste the below code :<\/p>\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/lh4.googleusercontent.com\/XGeYTvlhcUeUm-STQh5pk8IZGMoj91xUPv4sgsZ8r1YUzej7I6pN3hWyOSzqUeydCTIMTmJmsOgGTZh_Rn26npSsZTVNAZckvokpZMVwDtkZomDDndqAff8=s0\" alt=\"define the payment method\" loading=\"lazy\" decoding=\"async\"><\/figure>\n<p><strong>(6)<\/strong> After that, To register template and render file create <strong>method-renderer.js<\/strong> file at <strong><em>app\/code\/Cmarix\/CustomPayment\/view\/frontend\/web\/js\/view\/payment\/<\/em><\/strong> and paste the below code :<\/p>\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/lh5.googleusercontent.com\/ELggf3cNCnseAV4MwOczogUlnwdnvn69MXdRrJ_20WT_TfmwFdRMdLXKYQEysQwYJHFnqhMf_SJ50RYOyRsc8LjthhN1epYdFyZ3lTx1R2gK3h0HrbDyeOA=s0\" alt=\"paste the below code\" loading=\"lazy\" decoding=\"async\"><\/figure>\n<p><strong>(7)<\/strong> Now, Create <strong>custompayment.js<\/strong> file at <strong><em>app\/code\/Cmarix\/CustomPayment\/view\/frontend\/web\/js\/view\/payment\/method-renderer\/ <\/em><\/strong>and paste the below code :<\/p>\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/lh3.googleusercontent.com\/4Ed6YIZEzfNNJhdYczo8NsrqpmKK2HCKSjawotROh4WrR3-F9rTFFWlcTq6-eZk1FmmYYZ3le9Mhyht3fngNPD3QWiC7zsh_C4VI0ByVVL1kdDTqpdW2JRg=s0\" alt=\"custompayment.js\" loading=\"lazy\" decoding=\"async\"><\/figure>\n<p><strong>(8)<\/strong> After that, Create <strong>custompayment.html<\/strong> template file at <strong><em>app\/code\/Cmarix\/CustomPayment\/view\/frontend\/web\/template\/payment\/ <\/em><\/strong>and paste the below code :<\/p>\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/lh3.googleusercontent.com\/lEoMssfzONo3HgBIyXwDuZTrjks3wCNpw8pfrTbwSaYmAEttmGUR4RqozEMO0ZjhYMhQw8D1x112gQ477ZePgXjIykeuJZimLWZOdv4B9GsDm64WxUh0pRk=s0\" alt=\"custompayment.html\" loading=\"lazy\" decoding=\"async\"><\/figure>\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/lh3.googleusercontent.com\/FppD2hB-9lwU61KbKyzTJ5L7bLadWdhZrGRcZhBs_Ep2XtcRHW2nhJH8w3FTAI-uIan9eBA9GG1tLAPw84EXMGffJOyppB6Krg04xOu_c7cWlMvV7nWxVMs=s0\" alt=\"checkout_index\" loading=\"lazy\" decoding=\"async\"><\/figure>\n<p><strong>(9)<\/strong> To display payment method at checkout page, Create <strong>checkout_index_index.xml<\/strong> file at <strong><em>app\/code\/Cmarix\/CustomPayment\/view\/frontend\/layout\/ <\/em><\/strong>and paste the below code :<\/p>\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/lh6.googleusercontent.com\/2XfvJatrMfGywvG3gNuQGp_KvIiuQEVwiRc_UW6_6P5c7qrxg9JXUq8KxttaALVxE2fjcPB3vCqmfBEe8_hy2sx77f85e2xzN95XT-4uavuw6WvILpGnv5w=s0\" alt=\"checkout_index_index\" loading=\"lazy\" decoding=\"async\"><\/figure>\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/lh4.googleusercontent.com\/xBpkNNqKcQ51XqJIl7OYs0C-0Ue2GTTKf-CiTTilgF6uSwi3zKG1-HbyVqj5TSDSZoZuip3CXHR6iJRu-3eof4eFxi3jsUBJGEECdhjqEU4Qagh_5xwWSFc=s0\" alt=\"below command\" loading=\"lazy\" decoding=\"async\"><\/figure>\n<p>In Last, you need to execute this below command:<\/p>\n<p>php bin\/magento s:up<\/p>\n<p>php bin\/magento s:s:d -f<\/p>\n<p>php bin\/magento c:c<\/p>\n<p>That is all! Finally, you can see your custom payment method. We hope this article is helpful for your Magento 2 tutorial. If you need further support, you can get in touch with us!<\/p>\n<\/body><\/html>\n","protected":false},"excerpt":{"rendered":"<p>Magento has introduced impeccable payment gateways with an exclusive custom field. Hire [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":51621,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[24],"tags":[],"class_list":["post-19901","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-magento-development"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.cmarix.com\/blog\/wp-json\/wp\/v2\/posts\/19901","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cmarix.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cmarix.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cmarix.com\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cmarix.com\/blog\/wp-json\/wp\/v2\/comments?post=19901"}],"version-history":[{"count":7,"href":"https:\/\/www.cmarix.com\/blog\/wp-json\/wp\/v2\/posts\/19901\/revisions"}],"predecessor-version":[{"id":49452,"href":"https:\/\/www.cmarix.com\/blog\/wp-json\/wp\/v2\/posts\/19901\/revisions\/49452"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cmarix.com\/blog\/wp-json\/wp\/v2\/media\/51621"}],"wp:attachment":[{"href":"https:\/\/www.cmarix.com\/blog\/wp-json\/wp\/v2\/media?parent=19901"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cmarix.com\/blog\/wp-json\/wp\/v2\/categories?post=19901"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cmarix.com\/blog\/wp-json\/wp\/v2\/tags?post=19901"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}