In a custom Magento 2 module, I have some code that successfully creates an order from a quote and sets the status to "pending".
After payment, I would like to programmatically validate the order, generate the invoice and send the confirmation email to the client.
The code that sets the status to complete:
// Update the status $order = $this->orderFactory->create()->loadByIncrementId($orderIncrementId); $order->setStatus('complete'); $order->save();
Unfortunately, this doesn't generate an invoice and send the final email. How are we supposed to perform these action programmatically from an existing/pending order?