Closed gpressutto5 closed 9 months ago
After some investigation, I'm seeing this error in Stripe when the payment fails:
Invalid level3: pricing must be consistent. Sum(unit_cost * quantity + tax_amount - discount_amount) + shipping_amount != total charged. In this case, 2300 != 1300.
Where 2300
is the original order amount and 1300
is the balance due after the gift card has been applied.
When I look at the YITH plugin code, I see that it stores the gift cards for the order in the WC session and then relies on the woocommerce_after_calculate_tax
action to manually adjust the cart totals using that data from the session.
When WooPayments builds out the level3 data for Stripe, it does so by looping through the line items on the order. Because the gift cards are not line items on the order and are stored in the session, we don't know they exist and can't update the payment intent with Stripe with the new total.
I'm still looking at potential solutions.
After much discussion in Slack, we're going to close this issue. We don't feel like there's a secure/scalable way to address this incompatibility within our code base.
Hi there,
I'm Francisco from YITH. Unfortunately, a valid solution for this issue will require an integration of both plugins, but it seems a bit impossible at the moment.
As a workaround, my suggestion is to use the default WooCommerce coupons field to redeem the gift card codes, instead of the ones added by the plugin by default, in this way, the codes will behave as coupons and the payment method will take the coupon line item without any problem.
To enable the coupon fields and disable the default gift card inputs you should have your settings like this:
If you have any doubts let me know and I will be happy to help you.
To enable the coupon fields and disable the default gift card inputs you should have your settings like this:
@franmglez92, I was not able to find this setting in the free version of this extension available on WPORG.
As a workaround, my suggestion is to use the default WooCommerce coupons field to redeem the gift card codes, instead of the ones added by the plugin by default, in this way, the codes will behave as coupons and the payment method will take the coupon line item without any problem.
Does the issue described herein still persist after this workaround has been applied?
I noticed that when I added a YITH gift card to my checkout, without the setting to use the default WooCommerce coupons field applied, I was unable to view my discounted card amongst the order line items in the blocks checkout and cart, which suggests there are some incompatibilities with core WooCommerce functionality.
Consequently, I agree with @brettshumaker's conclusions laid out above (https://github.com/Automattic/woocommerce-payments/issues/7949#issuecomment-1922287391) and also feel that we will be unable to create a fix for this issue until there is more alignment on how these coupons are added to cart. 😞
We received another instance of exactly the same error, but with the Gift Cards extension from Woo. The reference is: 7763223-zen
The error reported there was the same:
Error: The provided PaymentMethod was previously used with a PaymentIntent without Customer attachment, shared with a connected account without Customer attachment, or was detached from a Customer. It may not be used again. To use a PaymentMethod multiple times, you must attach it to a Customer first.
The merchant's customer did not have a saved card on their account and had never had one. They were eventually able to resolve the issue by saving a card to their account.
I dug into the details in Stripe, and I located a similar error about the discrepancy in order total and payable total too:
invalid_request_error - level3 Invalid level3: pricing must be consistent. Sum(unit_cost * quantity + tax_amount - discount_amount) + shipping_amount != total charged. In this case, 5600 != 600.
Of note: the merchant's customer has no less than three customer accounts in Stripe, but only one has the saved card. The other two are showing the above error. IMO this looks like Stripe isn't catching that Woo reduces the final order total based on the gift card usage (no matter which extension generates the gift card).
@sophiegyo, I've had a quick look through the Woo Gift Cards source code and I believe we face the same friction found by Brett above. It appears that Woo Gift Cards applies their discounts from cards stored to the session, rather than using cart or coupon fields that WooPayments can readily collect from line-order items at cart or checkout. I still feel that for us to support this functionality would not be scalable or secure in the long-term.
YITH Gift Cards provided an alternate option to "allow gift card codes in WooCommerce coupon fields", which allows WooPayments to find them prior to submitting payment information to Stripe. If Woo Gift Cards could also provide an option like this, I think that would be a better solution to this issue.
@sophiegyo, would you be able to raise an enhancement issue on the Woo Gift Cards plugin, suggesting that this be added to support compatibility with WooCommerce and WooPayments? You can quote https://github.com/Automattic/woocommerce-payments/issues/7949#issuecomment-1922287391 above in the new issue to explain why the enhancement is necessitated and why we need this change to be made on the external plugin, before it can be supported by WooPayments. Also, it appears WooCommerce Gift Cards is a private repository, so let me know if you're unable to create that issue and I can create it for you instead.
Apologies for any inconvenience, but I hope that is an acceptable path forward to resolve this issue for other WooCommerce Gift Card users. 🙏
Describe the bug
I don't know if this is an error on our side or on their side, but it only happens when using a new card. It works fine when using a saved card or another UPE method.
To Reproduce
Screenshots
Additional context
Might be related to #7858