I have one small question, please suggest the correct answer.

In Magento 2 payment methods are based on billing address or shipping address

Thanks in advance

  • 1
    You want to display payment methods based on address. Right? – Dhaduk Mitesh Jan 24 '20 at 7:13
  • no just I want to know default Magento 2 payment methods are based on shipping address or billing address by default – Chala Chalapathi Jan 24 '20 at 7:15

By default in Magento 2 payment methods based on the billing address.

Here is example of that usage from the default payment method class:

to determine is payment method applicable for the customer's country the Magento\Payment\Model\Checks\CanUseForCountry::isApplicable(MethodInterface $paymentMethod, Quote $quote) method used, where the country comes from the Magento\Payment\Model\Checks\CanUseForCountry\CountryProvider::getCountry($quote) where billing address is prefered data source:

 * Get payment country
 * @param Quote $quote
 * @return int
public function getCountry(Quote $quote)
    $address = $quote->getBillingAddress() ? : $quote->getShippingAddress();
    return (!empty($address) && !empty($address->getCountry()))
        ? $address->getCountry()
        : $this->directoryHelper->getDefaultCountry();

I think other parts of code in Magento use a same logic: billing address is preferred, but in case it is not set yet we can use shipping address.

  • But in code, it takes the shipping address for the country. – Dhaduk Mitesh Feb 5 at 8:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.