5

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?

3
  • 1
    you have to add products first then you can see payment methods.
    – Nitesh
    Mar 11 '17 at 8:00
  • is it possible magento 1
    – user51361
    May 29 '17 at 9:28
  • Using Standard Way with Adapter Class, rakeshjesadiya.com/… Jun 5 '20 at 12:14
6

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.

2
  • Thanks, I think I got this. I would need to trigger some actions (call to gateway, etc) after Submit order, how can I hook up? Nov 23 '16 at 10:00
  • @TeroLahtinen, please, see my updated answer.
    – joni jones
    Nov 23 '16 at 10:25
1

I had the same issue on Magento 2.2.0 I just added the can_use_internal flag in my config.xml file on Magento 2.3.2 version and it's worked

Can use internal flag

0

Add this in events.xml

 <event name="payment_method_is_active">
        <observer name="disable_po" instance="Dev14\Replacements\Observer\PaymentMethod" />
    </event>

and in file use this code

<?php
namespace Dev14\Replacements\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\Request\DataPersistorInterface;
use Magento\Framework\App\ObjectManager;

class PaymentMethod implements ObserverInterface
{
    protected $_appState;
    public function __construct(
        \Magento\Framework\App\State $appState,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
    ) {
        $this->_appState = $appState;
        $this->scopeConfig = $scopeConfig;
    }

    /**
     *
     * @param \Magento\Framework\Event\Observer $observer
     * @return void
     */
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $result = $observer->getEvent()->getResult();
        $method_instance = $observer->getEvent()->getMethodInstance();
        $quote = $observer->getEvent()->getQuote();
        if(null !== $quote){
            if($method_instance->getCode() =='cashondelivery')
            {
                $result->setData('is_available',false);
            }
        }


    }

}

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.