Magento – Custom payment method is not showing in checkout Magento 2.3

checkout-pagemagento2.3payment-methods

I am new to Magento.I have created a payment method , it is showing in magento admin panel but not showing in checkout page.

etc/adminhtml/system.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <section id="payment">
            <group id="Newpayment" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Newpayment</label>
                <field id="active" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Enabled</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
                <field id="title" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Title</label>
                </field>
                <field id="int_id" translate="label" type="text" sortOrder="21" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Merchant ID</label>
                </field> 
                <field id="mer_id" translate="label" type="text" sortOrder="22" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Merchant Settlement ID</label>
                </field>
                <field id="mer_dis_name" translate="label" type="text" sortOrder="23" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Merchant Display Name</label>
                </field>
                <field id="merchant_priv_key" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Merchant Private Key</label>
                    <backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>
                </field>
                <field id="merchant_pub_key" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Merchant Public Key</label>
                    <backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>
                </field>
                <field id="api_key" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>API Key</label>
                </field>
                <field id="debug" translate="label" type="select" sortOrder="85" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Debug</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
                <field id="environment" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Environment</label>
                    <source_model>Magento\Newpayment\Model\Environment</source_model>
                    <config_path>payment/Newpayment/environment</config_path>
                </field>
                <field id="sort_order" translate="label" type="text" sortOrder="160" showInDefault="1" showInWebsite="1"
                       showInStore="0">
                    <label>Sort Order</label>
                    <frontend_class>validate-number</frontend_class>
                </field>
            </group>
        </section>
    </system>
</config>

etc/config.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <default>
        <payment>
            <Newpayment>
                <debug>1</debug>
                <active>1</active>
                <model>Magento\Newpayment\Model\Newpayment</model>
                <sandbox_url>https://test.Newpayment.com/pg/pay</sandbox_url>
                <production_url>https://secure.Newpayment.com/pg/pay</production_url>
                <environment>sandbox</environment>
                <merchant_priv_key backend_model="Magento\Config\Model\Config\Backend\Encrypted" />
                <merchant_pub_key backend_model="Magento\Config\Model\Config\Backend\Encrypted" />
                <order_status>pending_payment</order_status>
                <title>Payment method (Newpayment)</title>
                <currency>INR</currency>
                <can_authorize>0</can_authorize>
                <can_capture>1</can_capture>
                <can_void>0</can_void>
                <can_use_checkout>1</can_use_checkout>
                <is_gateway>1</is_gateway>
                <sort_order>1</sort_order>
                <redirect_url>Newpayment/standard/redirect</redirect_url>
                <return_url>Newpayment/standard/response</return_url>
                <cancel_url>Newpayment/standard/cancel</cancel_url>
            </Newpayment>
        </payment>
    </default>
</config>

etc/module.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Magento_Newpayment" setup_version="2.0.0">
        <sequence>
            <module name="Magento_Sales"/>
            <module name="Magento_Payment"/>
            <module name="Magento_Checkout"/>
        </sequence>
    </module>
</config>

etc/payment.xml

<?xml version="1.0"?>

<payment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Payment:etc/payment.xsd">
    <methods>
        <method name="Newpayment">
            <allow_multiple_address>1</allow_multiple_address>
        </method>
    </methods>
</payment>

view/frontend/layout/checkout_index_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="checkout.root">
            <arguments>
                <argument name="jsLayout" xsi:type="array">
                    <item name="components" xsi:type="array">
                        <item name="checkout" xsi:type="array">
                            <item name="children" xsi:type="array">
                                <item name="steps" xsi:type="array">
                                    <item name="children" xsi:type="array">
                                        <item name="billing-step" xsi:type="array">
                                            <item name="component" xsi:type="string">uiComponent</item>
                                            <item name="children" xsi:type="array">
                                                <item name="payment" xsi:type="array">
                                                    <item name="children" xsi:type="array">
                                                        <item name="renders" xsi:type="array">
                                                            <!-- merge payment method renders here -->
                                                            <item name="children" xsi:type="array">
                                                                <item name="Newpayment" xsi:type="array">
                                                                    <item name="component" xsi:type="string">Magento_Newpayment/js/view/payment/Newpayment</item>
                                                                    <item name="methods" xsi:type="array">
                                                                        <item name="Newpayment" xsi:type="array">
                                                                            <item name="isBillingAddressRequired" xsi:type="boolean">true</item>
                                                                        </item>
                                                                    </item>
                                                                </item>
                                                            </item>
                                                        </item>
                                                    </item>
                                                </item>
                                            </item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </item>
                </argument>
            </arguments>
        </referenceBlock>
    </body>
</page>

view/frontend/web/js/view/payment/method-render/Newpayment.js

define(
        [
            'Magento_Checkout/js/view/payment/default',
            'Magento_Newpayment/js/action/set-payment-method',
        ],
        function (Component,setPaymentMethod) {
            'use strict';

            return Component.extend({
                defaults: {
                    template: 'Magento_Newpayment/payment/form',
                },
                redirectAfterPlaceOrder: false,

                afterPlaceOrder: function(){
                    setPaymentMethod();
                }
            });
        }
    );

view/frontend/web/js/view/payment/Newpayment.js

define(
    [
        'uiComponent',
        'Magento_Checkout/js/model/payment/renderer-list'
    ],
    function (
        Component,
        rendererList
    ) {
        'use strict';
        rendererList.push(
            {
                type: 'Newpayment',
                component: 'Magento_Newpayment/js/view/payment/method-renderer/Newpayment'
            }
        );
        return Component.extend({});
    }
);

view/frontend/web/template/payment/form.html

<div class="payment-method" data-bind="css: {'_active': (getCode() == isChecked())}">
    <div class="payment-method-title field choice">
        <input type="radio"
               name="payment[method]"
               class="radio"
               data-bind="attr: {'id': getCode()}, value: getCode(), checked: isChecked, click: selectPaymentMethod, visible: isRadioButtonVisible()"/>
        <label class="label" data-bind="attr: {'for': getCode()}">
            <span data-bind="text: getTitle()"></span>
        </label>
    </div>

    <div class="payment-method-content">
        <!-- ko foreach: getRegion('messages') -->
        <!-- ko template: getTemplate() --><!-- /ko -->
        <!--/ko-->
        <div class="payment-method-billing-address">
            <!-- ko foreach: $parent.getRegion(getBillingAddressFormName()) -->
            <!-- ko template: getTemplate() --><!-- /ko -->
            <!--/ko-->
        </div>
        <div class="checkout-agreements-block">
            <!-- ko foreach: $parent.getRegion('before-place-order') -->
            <!-- ko template: getTemplate() --><!-- /ko -->
            <!--/ko-->
        </div>

        <div class="actions-toolbar">
            <div class="primary">
                <button class="action primary checkout"
                        type="submit"
                        data-bind="
                        click: placeOrder,
                        attr: {title: $t('Place Order')},
                        enable: (getCode() == isChecked())
                        " disabled>
                    <span data-bind="i18n: 'Continue'"></span>
                </button>
            </div>
        </div>
    </div>
</div>

registration.php

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Magento_Newpayment',
    __DIR__
);

Best Answer

in Magento\Newpayment\Model\Newpayment do you have

public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = NULL){
    return $this->getConfigData('active') || $this->getConfigData('active');
}

?

Btw, the payment method through etc/config.xml is obsolete in latest versions of magento..

Take a look at magento tutorials for payment gateway/integration:

https://devdocs.magento.com/guides/v2.3/payments-integrations/payment-gateway/payment-gateway-intro.html

Related Topic