{"id":339766,"date":"2022-06-16T07:18:52","date_gmt":"2022-06-16T07:18:52","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=339766"},"modified":"2023-05-09T11:14:29","modified_gmt":"2023-05-09T11:14:29","slug":"how-to-add-custom-field-for-a-payment-method-in-magento2","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/","title":{"rendered":"How to add custom field for a payment method in Magento 2?"},"content":{"rendered":"\n<p>This topic describes how to add a custom field to a payment method in the payment step of the checkout. The custom field allows the buyer to enter the phone for an payment method.<\/p>\n\n\n\n<p><strong>Step 1 &#8211; Create  a new module <\/strong><br>Create a new module named Learning\/PaymentMethod and register it.<\/p>\n\n\n\n<p><strong>Step 2 Add a db_schema.xml file.<\/strong><br>Add the mpesanumber column in the quote_payment and sales_order_payment tables using the declarative schema method.<\/p>\n\n\n\n<p>Create the app\/code\/Learning\/PaymentMethod\/etc\/db_schema.xml and define the declarative schema as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;schema xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:Setup\/Declaration\/Schema\/etc\/schema.xsd&quot;&gt;\n    \n    &lt;table name=&quot;quote_payment&quot; resource=&quot;checkout&quot; engine=&quot;innodb&quot; comment=&quot;Sales Flat Quote Payment&quot;&gt;\n        &lt;column xsi:type=&quot;text&quot; name=&quot;mpesanumber&quot; nullable=&quot;true&quot; comment=&quot;Mpesa Mobile Number&quot;\/&gt;\n    &lt;\/table&gt;\n    &lt;table name=&quot;sales_order_payment&quot; resource=&quot;sales&quot; engine=&quot;innodb&quot; comment=&quot;Sales Flat Order Payment&quot;&gt;\n        &lt;column xsi:type=&quot;text&quot; name=&quot;mpesanumber&quot; nullable=&quot;true&quot; comment=&quot;Mpesa Mobile Number&quot;\/&gt;\n    &lt;\/table&gt;\n&lt;\/schema&gt;<\/pre>\n\n\n\n<p><strong>Step 3- Override the payment method js files or if using new <a href=\"https:\/\/store.webkul.com\/Magento-2\/Payment-Extensions.html\">Magento 2 payment method<\/a> then add the code in the below files.<\/strong><br>Create the app\/code\/Learning\/PaymentMethod\/view\/frontend\/web\/js\/view\/payment\/testmethod.js file and add the following code:<br><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">\n define(\n    &#091;\n        &#039;uiComponent&#039;,\n        &#039;Magento_Checkout\/js\/model\/payment\/renderer-list&#039;\n    ],\n    function (Component,\n              rendererList) {\n        &#039;use strict&#039;;\n        rendererList.push(\n            {\n                type: &#039;testmethod&#039;,\n                component: &#039;Learning_PaymentMethod\/js\/view\/payment\/method-renderer\/testmethod&#039;\n            }\n        );\n        return Component.extend({});\n    }\n);<\/pre>\n\n\n\n<p><br>Create the app\/code\/Learning\/PaymentMethod\/view\/frontend\/web\/js\/view\/payment\/method-renderer\/testmethod.js file and add the following code:<br><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">\ndefine(\n    &#091;\n        &#039;jquery&#039;,\n        &#039;Magento_Checkout\/js\/view\/payment\/default&#039;,\n        &#039;mage\/url&#039;,\n        &#039;Magento_Checkout\/js\/model\/error-processor&#039;,\n        &#039;Magento_Checkout\/js\/action\/redirect-on-success&#039;,\n        &#039;Magento_Checkout\/js\/model\/quote&#039;,\n        &#039;mage\/validation&#039;\n    ],\n    function ($,Component,url, errorProcessor,redirectOnSuccessAction, quote) {\n        &#039;use strict&#039;;\n        \n        return Component.extend({\n            defaults: {\n                template: &#039;Learning_PaymentMethod\/payment\/testmethod&#039;,\n                mpesaNumber:&#039;&#039;,\n            },\n            \/** @inheritdoc *\/\n            initObservable: function () {\n                this._super()\n                    .observe(&#091;&#039;mpesaNumber&#039;]);\n\n                return this;\n            },\n            \/**\n         * @return {Object}\n         *\/\n        getData: function () {\n            return {\n                method: this.item.method,\n                \/\/ &#039;mpesanumber&#039;: this.mpesaNumber(),\n                &#039;additional_data&#039;: {\n                    &#039;mpesanumber&#039;: $(&#039;#lipampesanumber&#039;).val()\n                }\n            };\n        },\n        \/**\n         * @return {jQuery}\n         *\/\n        validate: function () {\n            var form = &#039;form&#091;data-role=mpesanumber_form]&#039;;\n\n            return $(form).validation() &amp;&amp; $(form).validation(&#039;isValid&#039;);\n        },\n       \n        });\n    }\n);<\/pre>\n\n\n\n<p><br>Create the app\/code\/Learning\/PaymentMethod\/view\/frontend\/web\/template\/payment\/testmethod.html file and add the following code:<br><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;div class=&quot;payment-method&quot; data-bind=&quot;css: {&#039;_active&#039;: (getCode() == isChecked())}&quot;&gt;\n    &lt;div class=&quot;payment-method-title field choice&quot;&gt;\n        &lt;input type=&quot;radio&quot;\n               name=&quot;payment&#091;method]&quot;\n               class=&quot;radio&quot;\n               data-bind=&quot;attr: {&#039;id&#039;: getCode()}, value: getCode(), checked: isChecked, click: selectPaymentMethod, visible: isRadioButtonVisible()&quot;\/&gt;\n        \n        &lt;label data-bind=&quot;attr: {&#039;for&#039;: getCode()}&quot; class=&quot;label&quot;&gt;\n            &lt;span data-bind=&quot;text: getTitle()&quot;&gt;&lt;\/span&gt;\n        &lt;\/label&gt;\n    &lt;\/div&gt;\n\n    &lt;div class=&quot;payment-method-content&quot;&gt;\n        &lt;!-- ko foreach: getRegion(&#039;messages&#039;) --&gt;\n        &lt;!-- ko template: getTemplate() --&gt;&lt;!-- \/ko --&gt;\n        &lt;!--\/ko--&gt;\n        &lt;div class=&quot;payment-method-billing-address&quot;&gt;\n            &lt;!-- ko foreach: $parent.getRegion(getBillingAddressFormName()) --&gt;\n            &lt;!-- ko template: getTemplate() --&gt;&lt;!-- \/ko --&gt;\n            &lt;!--\/ko--&gt;\n        &lt;\/div&gt;\n        &lt;form id=&quot;mpesanumber_form&quot; class=&quot;form form-mpsaisa-number&quot; data-role=&quot;mpesanumber_form&quot;&gt;\n            &lt;fieldset class=&quot;fieldset payment method&quot; data-bind=&#039;attr: {id: &quot;payment_form_&quot; + getCode()}&#039;&gt;\n                &lt;div class=&quot;field field-number required&quot;&gt;\n                    &lt;label for=&quot;mpesanumber&quot; class=&quot;label&quot;&gt;\n                    &lt;span&gt;&lt;!-- ko i18n: &#039;Mpesa Mobile Number&#039;--&gt;&lt;!-- \/ko --&gt;&lt;\/span&gt;\n                    &lt;\/label&gt;\n                    &lt;div class=&quot;control&quot;&gt;\n                        &lt;div class=&quot;name-info&quot;&gt;\n                            &lt;input type=&quot;text&quot; id=&quot;lipampesanumber&quot; name=&quot;payment&#091;mpesanumber]&quot; \n                            placeholder=&quot;Mpesa Mobile Number&quot; data-validate=&quot;{required:true}&quot;        data-bind=&#039;attr: {title: $t(&quot;Mpaisa Mobile Number&quot;)}&#039; class=&quot;input-text&quot;\/&gt;\n                        &lt;\/div&gt;\n                    &lt;\/div&gt;\n                &lt;\/div&gt;\n            &lt;\/fieldset&gt;\n        &lt;\/form&gt;\n        &lt;div class=&quot;checkout-agreements-block&quot;&gt;\n            &lt;!-- ko foreach: $parent.getRegion(&#039;before-place-order&#039;) --&gt;\n                &lt;!-- ko template: getTemplate() --&gt;&lt;!-- \/ko --&gt;\n            &lt;!--\/ko--&gt;\n        &lt;\/div&gt;\n        &lt;div class=&quot;actions-toolbar&quot; id=&quot;review-buttons-container&quot;&gt;\n            &lt;div class=&quot;primary&quot;&gt;\n                &lt;button class=&quot;action primary checkout&quot;\n                        type=&quot;submit&quot;\n                        data-bind=&quot;\n                        click: placeOrder,\n                        attr: {title: $t(&#039;Place Order&#039;)},\n                        enable: (getCode() == isChecked()),\n                        css: {disabled: !isPlaceOrderActionAllowed()}\n                        &quot;\n                        data-role=&quot;review-save&quot;&gt;\n                    &lt;span data-bind=&quot;i18n: &#039;Place Order&#039;&quot;&gt;&lt;\/span&gt;\n                &lt;\/button&gt;\n            &lt;\/div&gt;\n        &lt;\/div&gt;\n    &lt;\/div&gt;\n&lt;\/div&gt;<\/pre>\n\n\n\n<p><br><strong>Step 5: Add an Observer<\/strong><br>Create an Observer file to save the custom field data to the order. For the Observer file an events.xml file is required to call the observer for a particular event. For this example, the sales_model_service_quote_submit_before event is used.<br><br>Create the app\/code\/Learning\/PaymentMethod\/etc\/frontend\/events.xml file and add the following code:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?xml version=&quot;1.0&quot;?&gt;\n&lt;config xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:Event\/etc\/events.xsd&quot;&gt;\n\t\n    &lt;event name=&quot;sales_model_service_quote_submit_before&quot;&gt;\n        &lt;observer name=&quot;mpesa_field_observer_frontend_sales_orderpaymentsavebefore&quot; instance=&quot;Learning\\PaymentMethod\\Observer\\OrderPaymentSaveBefore&quot; \/&gt;\n    &lt;\/event&gt;\n    \n&lt;\/config&gt;<\/pre>\n\n\n\n<p><br>Then create the app\/code\/Learning\/PaymentMethod\/Observer\/OrderPaymentSaveBefore.php file.<br><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\n\nnamespace Learning\\PaymentMethod\\Observer;\n\nuse Magento\\Framework\\Event\\Observer as EventObserver;\nuse Magento\\Framework\\Event\\ObserverInterface;\nuse Magento\\OfflinePayments\\Model\\Purchaseorder;\nuse Magento\\Framework\\App\\Request\\DataPersistorInterface;\n\nclass OrderPaymentSaveBefore implements \\Magento\\Framework\\Event\\ObserverInterface\n{\n\n    \/**\n     * Construct\n     *\n     * @param \\Magento\\Sales\\Api\\Data\\OrderInterface $order\n     * @param \\Magento\\Quote\\Api\\CartRepositoryInterface $quoteRepository\n     * @param \\Psr\\Log\\LoggerInterface $logger\n     * @param \\Magento\\Framework\\Serialize\\Serializer\\Serialize $serialize\n     * @param \\Magento\\Webapi\\Controller\\Rest\\InputParamsResolver $inputParamsResolver\n     * @param \\Magento\\Framework\\App\\State $state\n     *\/\n    public function __construct(\n        \\Magento\\Sales\\Api\\Data\\OrderInterface $order,\n        \\Magento\\Quote\\Api\\CartRepositoryInterface $quoteRepository,\n        \\Psr\\Log\\LoggerInterface $logger,\n        \\Magento\\Framework\\Serialize\\Serializer\\Serialize $serialize,\n        \\Magento\\Webapi\\Controller\\Rest\\InputParamsResolver $inputParamsResolver,\n        \\Magento\\Framework\\App\\State $state\n    ) {\n        $this-&gt;order = $order;\n        $this-&gt;quoteRepository = $quoteRepository;\n        $this-&gt;logger = $logger;\n        $this-&gt;_serialize = $serialize;\n        $this-&gt;inputParamsResolver = $inputParamsResolver;\n        $this-&gt;_state = $state;\n    }\n    \n    public function execute(\\Magento\\Framework\\Event\\Observer $observer)\n    {\n        $order = $observer-&gt;getOrder();\n        $inputParams = $this-&gt;inputParamsResolver-&gt;resolve();\n        if ($this-&gt;_state-&gt;getAreaCode() != \\Magento\\Framework\\App\\Area::AREA_ADMINHTML) {\n            foreach ($inputParams as $inputParam) {\n                if ($inputParam instanceof \\Magento\\Quote\\Model\\Quote\\Payment) {\n                    $paymentData = $inputParam-&gt;getData(&#039;additional_data&#039;);\n                    \n                    $paymentOrder = $order-&gt;getPayment();\n                    $order = $paymentOrder-&gt;getOrder();\n                    $quote = $this-&gt;quoteRepository-&gt;get($order-&gt;getQuoteId());\n                    $paymentQuote = $quote-&gt;getPayment();\n                    $method = $paymentQuote-&gt;getMethodInstance()-&gt;getCode();\n                    if ($method == &#039;testmethod&#039;) {\n                        if (isset($paymentData&#091;&#039;mpesanumber&#039;])) {\n                            $paymentQuote-&gt;setData(&#039;mpesanumber&#039;, $paymentData&#091;&#039;mpesanumber&#039;]);\n                            $paymentOrder-&gt;setData(&#039;mpesanumber&#039;, $paymentData&#091;&#039;mpesanumber&#039;]);\n                        }\n                        \n                    }\n                }\n            }\n        }\n    }\n}<\/pre>\n\n\n\n<p><br><strong>Step 6: Compile and deploy the module<br><\/strong>Run the following sequence of commands to compile and deploy your custom module.<\/p>\n\n\n\n<p>Enable the new module.<\/p>\n\n\n\n<p>bin\/magento module:enable Learning_PaymentMethod<br>Install the new module.<\/p>\n\n\n\n<p>bin\/magento setup:upgrade<br>Compile the code.<\/p>\n\n\n\n<p>bin\/magento setup:di:compile<br>Deploy the static files.<\/p>\n\n\n\n<p>bin\/magento setup:static-content:deploy<br><strong>Step 7: Verify that the module works<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/06\/payment_method-1200x603.png\" alt=\"payment_method\" class=\"wp-image-339780\" width=\"510\" height=\"256\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/06\/payment_method-1200x603.png 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/06\/payment_method-300x151.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/06\/payment_method-250x126.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/06\/payment_method-768x386.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/06\/payment_method.png 1528w\" sizes=\"(max-width: 510px) 100vw, 510px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>We hope it will help you. Thank you!!<\/p>\n\n\n\n<p>If any issue or doubt please feel free to mention in comment section.<\/p>\n\n\n\n<p>We would be happy to help. Happy Coding!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This topic describes how to add a custom field to a payment method in the payment step of the checkout. The custom field allows the buyer to enter the phone for an payment method. Step 1 &#8211; Create a new module Create a new module named Learning\/PaymentMethod and register it. Step 2 Add a db_schema.xml <a href=\"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":375,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[1161,2070,3301],"class_list":["post-339766","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-checkout","tag-magento2","tag-payment-methods"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to add custom field for a payment method in Magento 2? - Webkul Blog<\/title>\n<meta name=\"description\" content=\"Follow this tutorial to add a custom field for a payment method in Magento 2 at the checkout step. Custom field allows buyers to enter a phone for a payment method.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to add custom field for a payment method in Magento 2? - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"Follow this tutorial to add a custom field for a payment method in Magento 2 at the checkout step. Custom field allows buyers to enter a phone for a payment method.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-06-16T07:18:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-05-09T11:14:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2022\/06\/payment_method-1200x603.png\" \/>\n<meta name=\"author\" content=\"Radhika Garg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Radhika Garg\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/\"},\"author\":{\"name\":\"Radhika Garg\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/1bfed7985110d44a908d093a4e322727\"},\"headline\":\"How to add custom field for a payment method in Magento 2?\",\"datePublished\":\"2022-06-16T07:18:52+00:00\",\"dateModified\":\"2023-05-09T11:14:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/\"},\"wordCount\":347,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2022\/06\/payment_method-1200x603.png\",\"keywords\":[\"Checkout\",\"Magento2\",\"payment methods\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/\",\"url\":\"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/\",\"name\":\"How to add custom field for a payment method in Magento 2? - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2022\/06\/payment_method-1200x603.png\",\"datePublished\":\"2022-06-16T07:18:52+00:00\",\"dateModified\":\"2023-05-09T11:14:29+00:00\",\"description\":\"Follow this tutorial to add a custom field for a payment method in Magento 2 at the checkout step. Custom field allows buyers to enter a phone for a payment method.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/06\/payment_method.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/06\/payment_method.png\",\"width\":1528,\"height\":768,\"caption\":\"payment_method\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to add custom field for a payment method in Magento 2?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/1bfed7985110d44a908d093a4e322727\",\"name\":\"Radhika Garg\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2319613aaa0bc878e7855f009fc5a889134810d78fa0d1e693180b36f82156a3?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2319613aaa0bc878e7855f009fc5a889134810d78fa0d1e693180b36f82156a3?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Radhika Garg\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/radhika-garg178\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to add custom field for a payment method in Magento 2? - Webkul Blog","description":"Follow this tutorial to add a custom field for a payment method in Magento 2 at the checkout step. Custom field allows buyers to enter a phone for a payment method.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/","og_locale":"en_US","og_type":"article","og_title":"How to add custom field for a payment method in Magento 2? - Webkul Blog","og_description":"Follow this tutorial to add a custom field for a payment method in Magento 2 at the checkout step. Custom field allows buyers to enter a phone for a payment method.","og_url":"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2022-06-16T07:18:52+00:00","article_modified_time":"2023-05-09T11:14:29+00:00","og_image":[{"url":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2022\/06\/payment_method-1200x603.png","type":"","width":"","height":""}],"author":"Radhika Garg","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Radhika Garg","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/"},"author":{"name":"Radhika Garg","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/1bfed7985110d44a908d093a4e322727"},"headline":"How to add custom field for a payment method in Magento 2?","datePublished":"2022-06-16T07:18:52+00:00","dateModified":"2023-05-09T11:14:29+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/"},"wordCount":347,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2022\/06\/payment_method-1200x603.png","keywords":["Checkout","Magento2","payment methods"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/","url":"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/","name":"How to add custom field for a payment method in Magento 2? - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2022\/06\/payment_method-1200x603.png","datePublished":"2022-06-16T07:18:52+00:00","dateModified":"2023-05-09T11:14:29+00:00","description":"Follow this tutorial to add a custom field for a payment method in Magento 2 at the checkout step. Custom field allows buyers to enter a phone for a payment method.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/06\/payment_method.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2022\/06\/payment_method.png","width":1528,"height":768,"caption":"payment_method"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/how-to-add-custom-field-for-a-payment-method-in-magento2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to add custom field for a payment method in Magento 2?"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/1bfed7985110d44a908d093a4e322727","name":"Radhika Garg","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2319613aaa0bc878e7855f009fc5a889134810d78fa0d1e693180b36f82156a3?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2319613aaa0bc878e7855f009fc5a889134810d78fa0d1e693180b36f82156a3?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Radhika Garg"},"url":"https:\/\/webkul.com\/blog\/author\/radhika-garg178\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/339766","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/375"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=339766"}],"version-history":[{"count":7,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/339766\/revisions"}],"predecessor-version":[{"id":380678,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/339766\/revisions\/380678"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=339766"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=339766"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=339766"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}