From c03c136e22c4868d8c2c8cf9bdcee3d821566f85 Mon Sep 17 00:00:00 2001 From: Mayisha <33387139+Mayisha@users.noreply.github.com> Date: Thu, 28 Nov 2024 15:14:54 +0600 Subject: [PATCH] Fix fatal error in purchasing a subscription with PRB and ECE when the subscription's price or sign-up fee is a string (#3617) * cast product price to float * add changelog * update return type * always return float --- changelog.txt | 1 + .../class-wc-stripe-express-checkout-helper.php | 6 +++--- .../payment-methods/class-wc-stripe-payment-request.php | 6 +++--- readme.txt | 1 + 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/changelog.txt b/changelog.txt index bfb70bf673..f616171ca1 100644 --- a/changelog.txt +++ b/changelog.txt @@ -9,6 +9,7 @@ * Tweak - Include page URL information in the SSL-required log for the Stripe Express Checkout Element. * Fix - Fix ECE modal not loading on pay for order page when coupon is applied. * Fix - Do not load express payment buttons on switch subscription page. +* Fix - Resolve a fatal error by casting product price and subscription sign up fee to 'float' while adding them. * Fix - Return 'is_live' as true in account summary response when test mode is disabled in gateway settings and charge is enabled in Stripe account. * Fix - Prevents notices being displayed on WordPress 6.7 due to loading translations too early (only shown on stores with WP_DEBUG enabled). * Tweak - Update links to plugin documentation and Stripe documentation. diff --git a/includes/payment-methods/class-wc-stripe-express-checkout-helper.php b/includes/payment-methods/class-wc-stripe-express-checkout-helper.php index e502446948..c4a05b359e 100644 --- a/includes/payment-methods/class-wc-stripe-express-checkout-helper.php +++ b/includes/payment-methods/class-wc-stripe-express-checkout-helper.php @@ -147,7 +147,7 @@ public function get_total_label() { * @param bool|null $is_deposit Whether this is a deposit. * @param int $deposit_plan_id Deposit plan ID. * - * @return integer Total price. + * @return float Total price. */ public function get_product_price( $product, $is_deposit = null, $deposit_plan_id = 0 ) { // If prices should include tax, using tax inclusive price. @@ -180,10 +180,10 @@ public function get_product_price( $product, $is_deposit = null, $deposit_plan_i // Add subscription sign-up fees to product price. if ( in_array( $product->get_type(), [ 'subscription', 'subscription_variation' ] ) && class_exists( 'WC_Subscriptions_Product' ) ) { - $product_price = $product_price + WC_Subscriptions_Product::get_sign_up_fee( $product ); + $product_price = (float) $product_price + (float) WC_Subscriptions_Product::get_sign_up_fee( $product ); } - return $product_price; + return (float) $product_price; } /** diff --git a/includes/payment-methods/class-wc-stripe-payment-request.php b/includes/payment-methods/class-wc-stripe-payment-request.php index 8b0997f70a..9d503193e0 100644 --- a/includes/payment-methods/class-wc-stripe-payment-request.php +++ b/includes/payment-methods/class-wc-stripe-payment-request.php @@ -366,13 +366,13 @@ public function get_button_label() { * @since 5.2.0 * * @param object $product WC_Product_* object. - * @return integer Total price. + * @return float Total price. */ public function get_product_price( $product ) { - $product_price = $product->get_price(); + $product_price = (float) $product->get_price(); // Add subscription sign-up fees to product price. if ( in_array( $product->get_type(), [ 'subscription', 'subscription_variation' ] ) && class_exists( 'WC_Subscriptions_Product' ) ) { - $product_price = $product->get_price() + WC_Subscriptions_Product::get_sign_up_fee( $product ); + $product_price += (float) WC_Subscriptions_Product::get_sign_up_fee( $product ); } return $product_price; diff --git a/readme.txt b/readme.txt index f646c583ac..0fbb01f162 100644 --- a/readme.txt +++ b/readme.txt @@ -119,6 +119,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o * Tweak - Include page URL information in the SSL-required log for the Stripe Express Checkout Element. * Fix - Fix ECE modal not loading on pay for order page when coupon is applied. * Fix - Do not load express payment buttons on switch subscription page. +* Fix - Resolve a fatal error by casting product price and subscription sign up fee to 'float' while adding them. * Fix - Return 'is_live' as true in account summary response when test mode is disabled in gateway settings and charge is enabled in Stripe account. * Fix - Prevents notices being displayed on WordPress 6.7 due to loading translations too early (only shown on stores with WP_DEBUG enabled). * Tweak - Update links to plugin documentation and Stripe documentation.