As soon as I add a restriction by billing address to a payment gateway that payment gateway will never appear, regardless of which country is chosen for the billing address. Example restriction I tried:

payment gateway billing address

I don't understand how it's expected to update the billing address options unless the billing address was taken before the payment methods were shown (i.e. #3035976: Keep billing information as a separate pane instead of replacing it with the payment information pane). Switching country does perform an AJAX request, but it doesn't update anything other than the address fields.

As soon as I remove the country restriction, the payment method appears.

Comments

Rob230 created an issue. See original summary.

rob230’s picture

So from looking at the code, it's unclear to me whether this is a bug or not. It seems to be another consequence of making the billing address part of the payment information. As it stands, it's impossible for these conditions to work with the checkout flow provided by Commerce.

public function evaluate(EntityInterface $entity) {
  $this->assertEntity($entity);
  /** @var \Drupal\commerce_order\Entity\OrderInterface $order */
  $order = $entity;
  $billing_profile = $order->getBillingProfile();
  if (!$billing_profile) {
    // The promotion can't be applied until the billing address is known.
    return FALSE;
  }
  $zone = new Zone([
    'id' => 'billing',
    'label' => 'N/A',
  ] + $this->configuration['zone']);
  $address = $billing_profile->get('address')->first();

  return $zone->match($address);
}

It returns FALSE until billing details have been saved on the order, so the only way to use that condition is to make billing address separate again: make your own checkout flow which has another step prior to 'Order information', undo the disabling of the separate BillingInformation pane in commerce_payment_commerce_checkout_pane_info_alter(), add billing information to your new step in the checkout flow, make your own PaymentInformation pane and use hook_commerce_checkout_pane_info_alter() to tell Drupal Commerce to use your class instead of the default one.

bojanz’s picture

Title: Restriction of payment gateway by billing address does not work » The billing address condition should not be shown for payment gateways

Confirming #2. You select the payment gateway then input the address, not vice-versa. There is no way to limit a payment gateway by billing address, by design. That allows payment gateways to specify that they don't need billing information, and have it be hidden.

That means that the payment gateway form must hide the billing address condition.

EDIT: Funny enough, shipping is vice-versa (address then selection), and we have the opposite problem (you can limit shipping methods by address but can't have a shipping method which hides the address selection)

rob230’s picture

Not sure I agree that the condition shouldn't be shown, as I intend to use it by asking for billing details first. In fact there are so many things in the checkout that need to depend on the billing country for me, putting it in the payment information pane has made things very difficult.

bojanz’s picture

It's a difficult tradeoff, but one we made long ago. People implementing custom panes will also be able to unhide the condition.

markdc’s picture

We have a use case for billing country conditions. Not every country accepts the same methods. For example, Benelux is a union of 3 countries but their online payment methods differ: iDEAL for Netherlands, Bancontact for Belgium and none of the above for Luxembourg. From a UX perspective this should be reversed (as hinted at in #3).

dwkitchen’s picture

Status: Active » Postponed

#3170412: Allow a store to always collect a billing address before payment method selection will use this condition to be able to set the payment gateway based on billing address.

The removal of the condition should be Postponed while that issue is worked on, once resolved this issue can be Closed (works as designed).

damienmckenna’s picture

Status: Postponed » Active
StatusFileSize
new373.98 KB

There are tangible business reasons why this is necessary.

In Commerce 1 on Drupal 7 it is possible to limit one payment method so it can only be used in one country, and other payment methods so they can be used in all countries except for that one. We've done that for years on a non-profit org's site and it works reliably.

A D7 rule that allows a certain billing method to only be available outside of the US

What is the recommended way of implementing this business rule in Commerce 2, if not via this scenario?