2

I have created a module custom payment method. All is fine except that the custom payment method is not showing in create order page.

File system.xml:

<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" translate="label" type="text" sortOrder="400" showInDefault="1" showInWebsite="1" showInStore="1">
            <group id="adminpaymentmethod" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Admin Payment Method</label>
                <field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="0" canRestore="1">
                    <label>Enabled</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                     <comment><![CDATA[Version 1.0.0]]></comment>
                </field>
                <field id="title" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
                    <label>Title</label>
                </field>
                <field id="order_status" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="0" canRestore="1">
                    <label>New Order Status</label>
                    <source_model>Magento\Sales\Model\Config\Source\Order\Status\NewStatus</source_model>
                </field>
                <field id="allowspecific" translate="label" type="allowspecific" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="0" canRestore="1">
                    <label>Payment from Applicable Countries</label>
                    <source_model>Magento\Payment\Model\Config\Source\Allspecificcountries</source_model>
                </field>         
                <field id="specificcountry" translate="label" type="multiselect" sortOrder="51" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Payment from Specific Countries</label>
                    <source_model>Magento\Directory\Model\Config\Source\Country</source_model>
                    <can_be_empty>1</can_be_empty>
                </field>
                <field id="sort_order" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Sort Order</label>
                    <frontend_class>validate-number</frontend_class>
                </field>
                <field id="default" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Enable</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                     <comment><![CDATA[Payment  method is automatically selected if existed.]]>
                    </comment>
                </field>
                <field id="model"></field>
            </group>
        </section>
    </system>
</config>

File config.xml:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
        <default>
            <payment>
                <adminpaymentmethod>
                    <model>Bss\AdminPaymentMethod\Model\AdminPaymentMethod</model>
                    <enable>1</enable>
                    <order_status>pending</order_status>
                    <title>Admin Payment Method</title>
                    <allowspecific>0</allowspecific>
                    <default>1</default>
                </adminpaymentmethod>
            </payment>
        </default>
    </config>

File Model\AdminPaymentMethod.php:

class AdminPaymentMethod extends \Magento\Payment\Model\Method\AbstractMethod
{

    protected $_code = 'adminpaymentmethod';

    /**
     * Availability option
     *
     * @var bool
     */
    protected $_isOffline = true;
}

Can anyone help me?

4
  • please share the code of Bss\AdminPaymentMethod\Model\AdminPaymentMethod
    – Amit Bera
    Sep 12 '18 at 15:16
  • @AmitBera i updated my question! Sep 12 '18 at 15:24
  • @ThànhTrungTô - Do you have payment.xml file located in Bss\AdminPaymentMethod\etc folder?
    – sandip
    Sep 12 '18 at 17:02
  • 1
    @sandip i don't have it.Tks u !. I have corrected that error .replace id enable into active. it's work. Sep 13 '18 at 3:41
0

Please add this in your AdminPaymentMethod class

 /**
 *
 * Using internal pages for input payment data
 * Can be used in admin
 *
 * @var bool
 */
protected $_canUseInternal = true;

Hope it helps

Thanks Kanaka Kishore

0

For those using the new Magento payment provider gateway (https://devdocs.magento.com/guides/v2.3/payments-integrations/payment-gateway/payment-gateway-intro.html) for the custom payment method creation, in order to make your payment method available in admin order creation, you have to add <can_use_internal>1</can_use_internal> into your etc/config.xml inside the <default><payment><custom_payment_method> tag. Also, be sure to use the correct formBlockType argument inside your di.xml where you define your implementation of Magento\Payment\Model\Method\Adapter: if you use something like Magento\OfflinePayments\Block\Form\Checkmo you will get an error, personally I've used Magento\OfflinePayments\Block\Form\Cashondelivery and it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.