Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fatal error in purchasing a subscription with PRB and ECE when the subscription's price or sign-up fee is a string #3617

Merged
merged 8 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Tweak - Remove duplicate notice about the new checkout experience.
* 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).

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,16 +366,16 @@ 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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$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) $product_price + (float) WC_Subscriptions_Product::get_sign_up_fee( $product );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$product_price = (float) $product_price + (float) WC_Subscriptions_Product::get_sign_up_fee( $product );
$product_price += (float) WC_Subscriptions_Product::get_sign_up_fee( $product );

}

return $product_price;
return (float) $product_price;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return (float) $product_price;
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 @@ -117,6 +117,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
* Tweak - Remove duplicate notice about the new checkout experience.
* 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).

Expand Down
Loading