I have integrated Custom payment module. I want to save every order placed with custom payment selected should be set to complete.
( If the selected payment mode is with MYPay ) Order Status -> complete
I have tried like this
vendor_name\module_name\etc\di.xml
di.xml file
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Checkout\Model\DefaultConfigProvider" type="Iostpay\Iostpaymagento\Model\DefaultConfigProvider" />
<type name="Magento\Sales\Api\OrderRepositoryInterface">
<plugin name="order_state_plugin"
type="Iostpay\Iostpaymagento\Model\Plugin\OrderStatePlugin"/>
</type>
</config>
Plugin
vendor_name\module_name\Plugin\OrderStatePlugin.php
<?php
namespace vendor_name\module_name\Plugin;
class OrderStatePlugin
{
/**
* @param \Magento\Sales\Api\OrderRepositoryInterface $subject
* @param \Magento\Sales\Api\Data\OrderInterface $result
* @return mixed
* @throws \Exception
*/
public function afterSave(\Magento\Sales\Api\OrderRepositoryInterface $subject,$result)
{
if($result->getState() == Order::STATE_COMPLETE) {
}
return $result;
}
But If this is the only way to do. what do I need to update in the plugin Code?
Does anyone know how to do this? Thanks in Advance.