Try following codesales_order_place_after: This event is dispatched after the order payment is placed.
<?php
use Magento\Framework\Event\ObserverInterface;
class Example implements ObserverInterface
{
protected $orderFactory;
public$order function= __construct$observer->getEvent(
\Magento\Quote\Model\QuoteFactory $quoteFactory,
\Magento\Sales\Model\Order $orderFactory
) {
$this->orderFactory = $orderFactory;
}
public function execute>getOrder(\Magento\Framework\Event\Observer $observer);
$incrementId = {$order->getIncrementId();
$orderIds
sales_order_save_after: This event is called every time the order is saved. For eg. Order status changed, invoiced, shipped & credit memo.
$order = $observer->getEvent()->getOrderIds>getOrder();
$orderId = $orderIds[0];
}
}$order->getId();