How To Create Order State And Status Magento 2

Create a file UpgradeData.php in custom module setup Folder  and copy below code to create custom order status and state


namespace Module\Custom\Setup;

use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

class UpgradeData implements UpgradeDataInterface
{
public function upgrade(
ModuleDataSetupInterface $installer,
ModuleContextInterface $context
) {

$installer->startSetup();

if (version_compare($context->getVersion(), '1.0.10', '<')) {
$table = $installer->getTable('sales_order_status');
if ($installer->getConnection()->isTableExists($table) == true) {
$installer->getConnection()->insert(
$installer->getTable('sales_order_status'),
[
'status' => 'refund_review',
'label' => 'Refund Review'
]
);
$installer->getConnection()->insert(
$installer->getTable('sales_order_status_state'),
[
'status' => 'refund_review',
'state' => 'refund_review',
'is_default' => 0,
'visible_on_front' => 0,
]
);
}
$installer->endSetup();
}

$installer->endSetup();
}
}