I'm using a third party one page checkout module on this system. And added an observer "payment_method_is_active" event for the cash on delivery and bank transfer methods to enable them only for local orders.
This is how payment method hiding works at the observer.
if($observer->getEvent()->getMethodInstance()->getCode()=="cashondelivery"){
$checkResult = $observer->getEvent()->getResult();
$checkResult->setData('is_available', true);
if($getCountry == 'LK'){
$checkResult = $observer->getEvent()->getResult();
return $checkResult->setData('is_available', true); //this is enabling the payment method at checkout page
}
else {
$checkResult = $observer->getEvent()->getResult();
return $checkResult->setData('is_available', false); //this is disabling the payment method at checkout page
}
}
When the cart page loads: If the country is selected to a foreign country, cart page loads hiding both payment methods without any errors, then if I change it to the default country, it loads the two methods with this error.
The same error appears for the bank transfer method also.
When the cart page loads: But, If the country is selected to the default at page reload, both payment methods shows on the page without any errors. And the hiding / showing methods working nicely according to the country selection without any error.
Please help to fix this error. Any help would be appreciated.