You tried wrong way, try following way:
SR/Stackexchange/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Payment\Model\MethodList">
<plugin name="cashondeliveryplugin_frontend" type="SR\Stackexchange\Plugin\Model\MethodList" sortOrder="10"/>
</type>
<type name="Magento\OfflinePayments\Model\Cashondelivery">
<plugin name="cashondeliveryplugin" type="SR\Stackexchange\Plugin\Model\Cashondelivery" sortOrder="10" disabled="false" />
</type>
</config>
SR/Stackexchange/Plugin/Model/MethodList.php
namespace SR\Stackexchange\Plugin\Model;
class MethodList
{
public function afterGetAvailableMethods(
\Magento\Payment\Model\MethodList $subject,
$availableMethods,
\Magento\Quote\Api\Data\CartInterface $quote = null
) {
foreach ($availableMethods as $key => $method) {
if($method->getCode() == 'cashondelivery') {
$codAvailability = $this->_pincodeModel->isCODAvailable($quote->getShippingAddress()->getPostcode()) ? 'yes' : 'no';
if ($codAvailability == 'no') {
unset($availableMethods[$key]);
}
}
}
return $availableMethods;
}
}
SR/Stackexchange/Plugin/Model/Cashondelivery.php
namespace SR\Stackexchange\Plugin\Model;
class Cashondelivery
{
public function aroundIsAvailable(
\Magento\OfflinePayments\Model\Cashondelivery $subject,
\Closure $proceed,
\Magento\Quote\Api\Data\CartInterface $quote = null
) {
$codAvailability = $this->_pincodeModel->isCODAvailable($quote->getShippingAddress()->getPostcode()) ? 'yes' : 'no';
if ($codAvailability == 'no') {
return false;
}
return $proceed($quote);;
}
}