I want to place order programmatically. I do not have COD enable when I placed the order programmatically so can it be possible that I can enable the COD before order place and disable COD after Order place.
To use Object Manager is not proper way but as i know this may be write answer. it helps you.
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $conf = $objectManager->get('Magento\Framework\App\Config\ScopeConfigInterface')->getValue('payment/cashondelivery/active'); $objectManager->get('Magento\Framework\App\Config\Storage\WriterInterface')->save('payment/cashondelivery/active', 1); /* your code */ $objectManager->get('Magento\Framework\App\Config\Storage\WriterInterface')->save('payment/cashondelivery/active', 0);
See below link
Refresh the cache programmatically in Magento 2 at window system
You have to use
Like Following Code
$this->resourceConfig->saveConfig('payment/cashondelivery/active', '1', 'default', ScopeInterface::SCOPE_STORES);
after complition order you need to set to
It will help you