I have override "Magento\Checkout\Model\PaymentInformationManagement
" file in custom module
I want to prevent some "afterpay" payment method to be displayed for some country.
So i need to override "getPaymentInformation" method. I have override it & customize method
/**
* @inheritdoc
*/
public function getPaymentInformation($cartId)
{
$quote = $this->_quoteFactory->create()->load($cartId);
$countryId = $quote->getShippingAddress()->getCountryId();
$paymentMethods = $this->paymentMethodManagement->getList($cartId);
/** @var \Magento\Checkout\Api\Data\PaymentDetailsInterface $paymentDetails */
foreach ($paymentMethods as $method) {
print_r($method->getCode()); echo'</br>'; //getting method code here
}
exit;
$paymentDetails = $this->paymentDetailsFactory->create();
$paymentDetails->setPaymentMethods($this->paymentMethodManagement->getList($cartId));
$paymentDetails->setTotals($this->cartTotalsRepository->get($cartId));
return $paymentDetails;
}
I am not sure how to remove "afterpay" payment object/data & pass it to $paymentDetails->setPaymentMethods();
I have checked further found that it ultimately fetches methods from
Magento\Payment\Model\MethodList
& getAvailableMethods
May be i can customize in that method for the same requirement ?