I've got a custom payment module. How can I update the order status to complete on the action of place order? If the order is placed choosing the custom payment method.

Thanks in advance!


You can use event observer for changing status of an order:


You can visit below link:


you can use events: sales_order_save_after and sales_order_state_change_before. I refer sales_order_save_after event.

In our observer, we can get the state of order:


public function execute(\Magento\Framework\Event\Observer $observer)
    $order = $observer->getEvent()->getOrder();
    if ($order instanceof \Magento\Framework\Model\AbstractModel) {
       if($order->getState() == 'canceled' || $order->getState() == 'closed') {
            //Your code here
    return $this;

you can read more about observer : Magento 2 events list

NOTE: you should try with Plugin:


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    <type name="Magento\Sales\Api\OrderRepositoryInterface">
        <plugin name="order_state_plugin"




namespace vendor_name\module_name\Plugin;

class file.name
 * @param \Magento\Sales\Api\OrderRepositoryInterface $subject
 * @param \Magento\Sales\Api\Data\OrderInterface $result
 * @return mixed
 * @throws \Exception
public function afterSave(\Magento\Sales\Api\OrderRepositoryInterface $subject,$result)
    if($result->getState() == Order::STATE_COMPLETE) {
    return $result;


accept if helps

  • Hi, I need to update order status complete, If the custom payment method is selected. – Garry Nov 18 '19 at 12:10
  • create a condition on custom method like if(method_select) { update order status as above } – Asad Ullah Nov 18 '19 at 12:40
  • What will be the path for this plugin? – Garry Nov 18 '19 at 12:42
  • I have custom module. – Garry Nov 18 '19 at 12:43
  • 1
    you can create it like app/code/vendor_name/module_name/Plugin/file.name – Asad Ullah Nov 18 '19 at 12:45

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.