Describe the bug
I am currently trying to make a plugin of mine (https://wordpress.org/plugins/wc-donation-platform/) compatible with Stripe Express Checkout. In the process, I've stumbled across an issue that is causing an incorrect amount to be charged.
When Express Checkout is enabled on the product page, every time the product selection field is changed, the total amount is calculated using an AJAX request (stripe-payment-request.js, wc-ajax=wc_stripe_get_selected_product_data).
When someone clicks on the payment button, the total amount is calculated one more time (stripe-payment-request.js, wc-ajax=wc_stripe_add_to_cart).
The payment modal displays the amount calculated using wc_stripe_get_selected_product_data, but the amount calculated using wc_stripe_add_to_cart is actually charged.
Normally this is not a problem, because the two amounts are the same, but if the amounts differ the user's trust in the Google Pay modal is betrayed.
To Reproduce
Steps to reproduce the behavior:
Activate Stripe Express Checkout for Product Pages
Click the Google Pay button on a product page. In this example, the product costs $1 (Screenshot 1)
The wrong amount is charged (Screenshot 2)
Expected behavior
The amount displayed in the Google Pay window matches the charged amount. At the very least, some form of error message should pop up.
Screenshots
Screenshot 1:
Screenshot 2:
Environment (please complete the following information):
WordPress Version: 5.9
WooCommerce Version: 6.1.1
Stripe Plugin Version: 6.1.0
Browser [e.g. chrome, safari] and Version: Chrome 97.0.4692.71
Additional context
By the way, the Express Checkout handling is implemented much more elegantly by the official PayPal plugin (the amount is calculated only once when clicking the button, which saves server resources.)
In addition, it is easier to pass additional individual parameters, because PayPal sends all parameters matching "[name^='attribute_']". Stripe uses $(".variations_form").find(".variations select") here, which makes it much more difficult, because the same selectors are also used by WooCommerce itself, which causes conflicts if you want to sneak additional parameters along. This makes it much easier to make WooCommerce PayPal Payments compatible with other plugins.
Describe the bug I am currently trying to make a plugin of mine (https://wordpress.org/plugins/wc-donation-platform/) compatible with Stripe Express Checkout. In the process, I've stumbled across an issue that is causing an incorrect amount to be charged.
When Express Checkout is enabled on the product page, every time the product selection field is changed, the total amount is calculated using an AJAX request (stripe-payment-request.js, wc-ajax=wc_stripe_get_selected_product_data). When someone clicks on the payment button, the total amount is calculated one more time (stripe-payment-request.js, wc-ajax=wc_stripe_add_to_cart). The payment modal displays the amount calculated using wc_stripe_get_selected_product_data, but the amount calculated using wc_stripe_add_to_cart is actually charged. Normally this is not a problem, because the two amounts are the same, but if the amounts differ the user's trust in the Google Pay modal is betrayed.
To Reproduce Steps to reproduce the behavior:
Activate Stripe Express Checkout for Product Pages
Add the following PHP code:
Click the Google Pay button on a product page. In this example, the product costs $1 (Screenshot 1)
The wrong amount is charged (Screenshot 2)
Expected behavior The amount displayed in the Google Pay window matches the charged amount. At the very least, some form of error message should pop up.
Screenshots Screenshot 1:
Screenshot 2:
Environment (please complete the following information):
Additional context By the way, the Express Checkout handling is implemented much more elegantly by the official PayPal plugin (the amount is calculated only once when clicking the button, which saves server resources.) In addition, it is easier to pass additional individual parameters, because PayPal sends all parameters matching "[name^='attribute_']". Stripe uses $(".variations_form").find(".variations select") here, which makes it much more difficult, because the same selectors are also used by WooCommerce itself, which causes conflicts if you want to sneak additional parameters along. This makes it much easier to make WooCommerce PayPal Payments compatible with other plugins.