Skip to content

Commit

Permalink
Fix fatal error in purchasing a subscription with PRB and ECE when th…
Browse files Browse the repository at this point in the history
…e subscription's price or sign-up fee is a string (#3617)

* cast product price to float

* add changelog

* update return type

* always return float
  • Loading branch information
Mayisha authored Nov 28, 2024
1 parent 28a5c49 commit c03c136
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions includes/payment-methods/class-wc-stripe-payment-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit c03c136

Please sign in to comment.