woocommerce / woocommerce-gateway-stripe

The official Stripe Payment Gateway for WooCommerce
https://wordpress.org/plugins/woocommerce-gateway-stripe/
236 stars 206 forks source link

[ECE] Payment processing with taxes #3472

Closed Mayisha closed 1 month ago

Mayisha commented 1 month ago

Process payment with ECE Google Pay / Apple Pay button when tax is applied to the order.

Acceptance criteria

annemirasol commented 1 month ago

The ECE behavior seems correct, and matches PRB behavior -- the tax computation is based on the shipping address chosen in the PRB/ECE modal, which makes sense to me.

For example, I added a 10% tax for all CA addresses, and checked out a cart worth $18. The total becomes $19.80.

Screenshot 2024-09-26 at 12 57 21 PM

Changing the shipping address to a location not defined in my tax table, I get a total without taxes.

Screenshot 2024-09-26 at 12 58 07 PM

Is there anything else we want to check here?

Mayisha commented 1 month ago

Thanks @annemirasol for checking this.

  1. We need to test with different tax settings, especially with prices entered with/without tax and taxes based on billing, shipping, and store address.
Screenshot 2024-09-28 at 4 14 48 AM
  1. Check these tax related issues from WooPayments and see if we also have these problems.
annemirasol commented 1 month ago

Some findings: Similar to WooPayments, we are unable to display the correct tax amount in the express checkout modal if the product is virtual. This is regardless of whether tax is based on shipping address or based on billing address.

WooPayments has elected to disable express checkout for this scenario -- we likely will need to do the same but I will be doing my own timeboxed investigation if there are other potential solutions.

annemirasol commented 1 month ago

The following tax scenarios were tested:

*For each scenario, "Default customer location" is set to "No location by default", in order to test for scenarios where we have incomplete information.

Mayisha commented 1 month ago

Hi @annemirasol 👋

❗ We do not have access to the billing address attached to the ECE card used until after the user clicks "Pay". This means that we might display the wrong tax and total in the ECE modal.

Are we already hiding the ECE button in this case or do we need a fix for this?

❓ Shippable cart: If the billing address is not the same as the shipping address -- this is possible if the user has several addresses in https://payments.google.com/gp/w/home/addressbook -- we might display the incorrect tax in the ECE modal, but charge the correct tax on payment.

As you mentioned in the previous point, we do not have access to the billing address attached to the ECE card used until after the user clicks "Pay". Isn't the tax (and final payment) supposed to be calculated wrong for this scenario as well then? 🤔

annemirasol commented 1 month ago

@Mayisha

Isn't the tax (and final payment) supposed to be calculated wrong for this scenario as well then? 🤔

Correct, as long as the tax is based on the billing address, there is a chance the tax amount we display in the modal will be incorrect 😔.

Are we already hiding the ECE button in this case or do we need a fix for this?

Currently, we are only hiding it if the cart is not shippable i.e. there is no billing and shipping address available to the express checkout modal. The tax amount displayed will be incorrect if:

When the cart is shippable, the tax amount displayed will be incorrect if:

I do not know whether this latter scenario is equally likely as the former. What do you think? Do you think we should just turn off express checkout whenever taxes are based on billing address? We can easily do that, but I am worried that this kind of tax setup is very common, which would mean a lot of merchants will basically lose the option to have express checkout for their stores.

Some other options I am mulling over:

LMK what you think!

Mayisha commented 1 month ago

Thanks @annemirasol for the details.

Let the displayed taxes be wrong. We can display a notice that final taxes charged can differ based on the actual billing address.

I have created an issue for this https://github.com/woocommerce/woocommerce-gateway-stripe/issues/3521. As the final charged amount is correct, allowing the user to pay with the ECE button should be fine.

Mayisha commented 1 month ago

Closing this issue as

annemirasol commented 3 weeks ago

When there are no shipping locations defined, WC()->cart->needs_shipping() will return false, even if the cart contains shippable products. This means that, because of #3493, ECE will not show up if the store does not have any shipping locations defined, and tax is based on billing or shipping.

This is expected, and maybe even desired, as Google Pay will not let you select a shipping address that is not defined in the store's shipping locations. For example, if a Google Pay account has two shipping addresses connected to it, e.g. United States and United Kingdom, and only United States is defined as a shipping location, the customer cannot select the United Kingdom address inside the Google Pay modal.