I have created an custom order status by following below link.


named "Online Payment Success" and I set this status to my order when a Invoice is generated for that order using event named "sales_order_invoice_pay" everything seems to work fine in my local setup but when I pushed the code to server the status is set but reverts back to processing

Code in Observer

namespace Vendor\Module\Observer;
use Magento\Framework\Event\Observer as EventObserver;
use Magento\Framework\Event\ObserverInterface;
class SalesOrderStatus implements ObserverInterface
    * @param EventObserver $observer
    * @return $this
    public function __construct(
        \Magento\Sales\Model\Order $order
        $this->order = $order;
    public function execute(EventObserver $observer)
            $paymentMethod  = $currentOrder->getPayment()->getMethodInstance()->getCode();
            if($paymentMethod=="braintree" || $paymentMethod=="paypal_express")
                $currentOrder->setState(\Magento\Sales\Model\Order::STATE_PROCESSING, true);
                $currentOrder->addStatusToHistory($currentOrder->getStatus(),"Invoice Generated");  

  • Add full details please – Jarnail S Oct 1 '20 at 7:44
  • @Jai Can u please check the code of my observer i have edited the problem description Thanks!! – Shehzad Rana Oct 1 '20 at 10:35

Your Answer

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

Browse other questions tagged or ask your own question.