First need to create a an event.xml file in your modules etc directory.
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="sales_order_invoice_pay">
<observer name="fs_invoice_pay_after" instance="Custom\StatusChange\Observer\InvoicePayAfter" />
</event>
</config>
Then you need to create an InvoicePayAfter.php file inside Observer directory like below.
<?php
namespace Custom\StatusChange\Observer;
class InvoicePayAfter implements \Magento\Framework\Event\ObserverInterface {
public function execute(\Magento\Framework\Event\Observer $observer) {
$order = $observer->getInvoice()->getOrder();
if ($order instanceof \Magento\Framework\Model\AbstractModel) {
if($order->getState() == 'processing') {
$order->setStatus('processing');
$order->save();
}
}
}
}
That's all hope this will help somebody.