Magento – Magento2: How to add a payment method to admin create order

magento2paymentpayment-methods

Magento2 create order page

I have an invoice payment method. The customer's call center should be able to create orders from backend and add this specific payment method to the order. The payment method is a gateway, which then creates the invoice to the finance company's system.

How do I implement this?

Best Answer

At first, your payment method should be available for usage in Admin panel and you need to specify can_use_internal property in your payment method YourCustomPayment/etc/config.xml file:

<payment>
    <your_custom_payment_method_code>
        <model>YourCustomPaymentMethodFacade</model>
        ...
        <can_use_internal>1</can_use_internal>
    </your_custom_payment_method_code>
</payment>

On the next step, you need to create block class, depends on your integration it will extend \Magento\Payment\Block\Form\Cc or \Magento\Payment\Block\Form.

And, after block is created, you need to create template view for this block and specify it in the layout for billing form (YourPayment/view/adminhtml/layout/sales_order_create_index.xml):

<body>
    <referenceBlock name="order_create_billing_form">
        <action method="setMethodFormTemplate">
            <argument name="method" xsi:type="string">your_custom_payment_method_code</argument>
            <argument name="template" xsi:type="string">Magento_YourCustomPayment::form/cc.phtml</argument>
        </action>
    </referenceBlock>
</body>

And for YourPayment/view/adminhtml/layout/sales_order_create_load_block_billing_method.xml

<body>
    <referenceBlock name="order.create.billing.method.form">
        <action method="setMethodFormTemplate">
            <argument name="method" xsi:type="string">your_custom_payment_method_code</argument>
            <argument name="template" xsi:type="string">Magento_YourCustomPayment::form/cc.phtml</argument>
        </action>
    </referenceBlock>
</body>

For more details, please, see my answer How to add custom payment gateway extension in magento2.

UPD This and this topics describe how to configure payment method for Adminl panel.

Related Topic