I am working on this Magento 2 extension and part of the features is to push information about the orders to an external application using web services. I need to push this information after an order is placed in the checkout.

At the moment I am using the event checkout_onepage_controller_success_action which triggers the method to create the orders in the external app. I placed this event in /etc/frontend/events.xml.

So far this is working but I found an issue with the orders status. Sometimes the orders are still in pending status and some other times the orders are in processing. The reason for this is because the payment method first initialize the orders as pending and after the payment is approved, the orders changed to processing. I want to push only processing orders. It seems that sometimes the event checkout_onepage_controller_success_action runs before the payment is authorized and this is causing the issues.

Any idea how to solve this? how can I make sure the payment processing runs before I run my code in checkout_onepage_controller_success_action?

Following my code:


<?xml version="1.0"?>
 * Copyright © 2017 companyname.com
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="checkout_onepage_controller_success_action">
        <observer name="companyname_order_success" instance="Companyname\Shipping\Observer\CreateCompanynameOrderObserver" />


 * Create an order in Companyname when order status match the statuses in the backend
 * @param EventObserver $observer
 * @return void
public function execute(EventObserver $observer){
    $order_ids  = $observer->getEvent()->getOrderIds();
    $order_id   = $order_ids[0];

    //Loading order details
    $orderModel         = $this->_orderFactory->create();
    $order              = $orderModel->load($order_id);
    $shipping_method    = $order->getShippingMethod();
    $order_status       = $order->getStatus();

    if($order_status == 'processing'){
        //Push to external app

4 Answers 4


You can try the event


It runs after order is submited successfully (and in back-end when you created an order too)

For example, in events.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

    <event name="checkout_submit_all_after">
        <observer name="yourcompany_yourmodule_checkout_submit_all_after" instance="YourCompany\YourModule\Observer\ProcessOrder" />


And in the observer

public function execute(\Magento\Framework\Event\Observer $observer)
    $order = $observer->getOrder();
    $quote = $observer->getQuote();

    // Do whatever you want here

    return $this;
  • This is not working for me. The event is not been fired. I tried with "checkout_submit_all_after" and also with "sales_order_place_after" but the only event I am able to capture with an observer is checkout_onepage_controller_success_action. Any suggestions? Oct 17, 2018 at 14:37
  • @DanielSilva I had the same problem with events not firing but then it did work when moved from frontend to global. That is, moved from etc/frontend/events.xml to etc/events.xml. This shouldn't happen but it does even though the content is identical. Oct 10, 2019 at 13:39
  • 2
    According to this old issue, Magento can't capture sales_order_* events, the solution is to change "frontend" folder to "webapi_rest". Oct 10, 2019 at 14:23
  • this didn't fire on paypal for me Jul 24, 2020 at 23:10

Please use sales_order_place_after event.

This event call only once and when order is successfully placed from the file vendor/magento/module-sales/Model/Order.php in the below function.

     * Place order
     * @return $this
    public function place()
        $this->_eventManager->dispatch('sales_order_place_before', ['order' => $this]);
        $this->_eventManager->dispatch('sales_order_place_after', ['order' => $this]);
        return $this;
  • 1
    I can confirm that this event is called for paypal checkout (which didn't call checkout_submit_all_after) and also for free orders (with cart rules causing price to equal zero) Jul 25, 2020 at 1:03

You can use the sales_order_state_change_before event. It provides access to the order and will allow you to check if the payment was processed. Then, when the payment is processed, it will be fired again, which will allow you to create the company name.

In general, Magento 2 appears to be moving away from events in favor of plugins. While many in the community may not agree with that approach, it's definitely something to keep in mind here.

  • Thanks for the answer @tjons. It seems that there are not much events left in Magento 2. I will try to use sales_order_state_change_before and let you know how it goes.
    – Eduardo
    Mar 3, 2017 at 2:22
  • Hey @tjons, I tried sales_order_state_change_before instead of checkout_onepage_controller_success_action but it was not working. Not sure where I need to place this event and if it will be triggered during the checkout. I have my event in etc/frontend/events.xml any clue why?
    – Eduardo
    Mar 6, 2017 at 18:21
  • 2020 and events still exist gladly...
    – Black
    Nov 10, 2020 at 12:33

Use Plugin instead, follow below steps

1- Create di.xml inside etc/di.xml file

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <type name="Magento\Sales\Api\OrderManagementInterface">
        <plugin name="order_place_after_plugin"

2- Create OrderPlace.php Plugin in app\code\Vendor\Order\Plugin\OrderPlace.php


namespace Vendor\Module\Plugin;

use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\OrderManagementInterface;

class OrderPlace
     * @param OrderManagementInterface $subject
     * @param OrderInterface $order
     * @return OrderInterface
    public function afterPlace(
        OrderManagementInterface $subject,
        OrderInterface $order
    ) {
        $orderId = $order->getIncrementId();
        // Your code goes here

        return $order;


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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