Automattic / woocommerce-payments

Accept payments via credit card. Manage transactions within WordPress.
https://wordpress.org/plugins/woocommerce-payments/
Other
173 stars 69 forks source link

Afterpay cannot be used by UK or NZ customers who do not complete optional checkout fields #9046

Closed csmcneill closed 3 months ago

csmcneill commented 3 months ago

Describe the bug

In WooCommerce Core, customers using a UK or NZ address have optional fields: County and Region respectively. Both of these fields are passed as billing_state.

However, Afterpay via WooPayments requires that a state value be passed for physical products:

https://github.com/Automattic/woocommerce-payments/blob/50a2090375813418c8bb51ae49c822a57ed6d9d4/includes/class-wc-payment-gateway-wcpay.php#L4498-L4501

If it is not, an exception will be thrown:

https://github.com/Automattic/woocommerce-payments/blob/50a2090375813418c8bb51ae49c822a57ed6d9d4/includes/class-wc-payment-gateway-wcpay.php#L4521

As a result, customers attempting to make a purchase via Afterpay who leave these optional fields empty will experience an error on checkout — even though the address they are using is correct.

In my tests:

To Reproduce

  1. Onboard with a UK account.
  2. Enable Clearpay.
  3. Add a support email (otherwise Clearpay may be rejected).
  4. Add a physical product to the cart that is between £1–£1,200 GBP.
  5. Go to the checkout page.
  6. Add a UK address.
  7. Leave the optional County field blank.
  8. Place the order.
  9. Note the error.

[!NOTE] The error in step 9 will be a critical error with the checkout block unless testing alongside https://github.com/Automattic/woocommerce-payments/pull/9043

Actual behavior

Customers in NZ and UK cannot place orders via Afterpay unless they provide optional address details. The error does not indicate that the optional information is a requirement, which leads to reduced conversions, confused customers, and frustrated merchants.

Expected behavior

Either Afterpay:

Additional context

p1719933634918299-slack-C3NCP7ZJ6 p1720025787369259-slack-CU6SYV31A 8421059-zen

AashikP commented 3 months ago

A temporary workaround until this is sorted:

// Make the County (UK), and Region (NZ) mandatory fields.

add_filter('woocommerce_get_country_locale', function($locale) {
    $locale['GB']['state']['required'] = true;
    $locale['NZ']['state']['required'] = true;
    return $locale;
});

P.S: Not extensively tested. Try it on a staging/test env first before implementing on production.

csmcneill commented 3 months ago

@AashikP did you test this on shortcode and block-based checkout?

AashikP commented 3 months ago

did you test this on shortcode and block-based checkout?

Originally, I only tested in shortcode-based checkout, but it seems to work fine in the checkout block as well:

image image