Skip to content

Commit 94d8fa5

Browse files
committed
Fix: "This value must be greater than or equal to 1" error during change payment method for subscription (#4227)
* prepare mandate data from subscription object on change payment method page * add changelog
1 parent 0e90669 commit 94d8fa5

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

changelog.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
* Fix - Fix BLIK visibility based on account and billing countries.
6363
* Add - Use Stripe Configuration API to manage payment methods enabled/disabled states.
6464
* Dev - Add track events when enabling/disabling payment methods.
65-
65+
* Fix - Prepare mandate data from subscription object on change payment method page.
6666

6767
= 9.3.2 - 2025-04-10 =
6868
* Fix - Fix express checkout for block cart and block checkout for WooCommerce 9.8.0+.

includes/compat/trait-wc-stripe-subscriptions.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,8 +845,10 @@ private function create_mandate_options_for_order( $order, $subscriptions ) {
845845

846846
$sub_amount = 0;
847847

848+
$cart_contain_switches = WC_Subscriptions_Switcher::cart_contains_switches();
849+
$is_changing_payment_method = $this->is_changing_payment_method_for_subscription();
850+
848851
// If this is a switch order we set the mandate options based on the new subscription.
849-
$cart_contain_switches = WC_Subscriptions_Switcher::cart_contains_switches();
850852
if ( $cart_contain_switches ) {
851853
foreach ( WC()->cart->cart_contents as $cart_item ) {
852854
$subscription_price = WC_Subscriptions_Product::get_price( $cart_item['data'] );
@@ -858,6 +860,13 @@ private function create_mandate_options_for_order( $order, $subscriptions ) {
858860

859861
$sub_billing_period = WC_Subscriptions_Product::get_period( $cart_item['data'] );
860862
$sub_billing_interval = absint( WC_Subscriptions_Product::get_interval( $cart_item['data'] ) );
863+
} elseif ( $is_changing_payment_method ) {
864+
// On the change payment method page, the $order object sent in this function is actually a subscription.
865+
$subscription = $order;
866+
867+
$sub_amount = WC_Stripe_Helper::get_stripe_amount( $subscription->get_subtotal(), $currency );
868+
$sub_billing_period = strtolower( $subscription->get_billing_period() );
869+
$sub_billing_interval = $subscription->get_billing_interval();
861870
} else {
862871
// If this is the first order, not a renewal, then get the subscriptions for the parent order.
863872
if ( empty( $subscriptions ) ) {
@@ -887,7 +896,7 @@ private function create_mandate_options_for_order( $order, $subscriptions ) {
887896
}
888897

889898
$has_interval = $sub_billing_period && $sub_billing_interval > 0;
890-
if ( $has_interval && ( 1 === count( $subscriptions ) || $cart_contain_switches ) ) {
899+
if ( $has_interval && ( 1 === count( $subscriptions ) || $cart_contain_switches || $is_changing_payment_method ) ) {
891900
$mandate_options['amount_type'] = 'fixed';
892901
$mandate_options['interval'] = $sub_billing_period;
893902
$mandate_options['interval_count'] = $sub_billing_interval;

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,5 +172,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
172172
* Fix - Fix BLIK visibility based on account and billing countries.
173173
* Add - Use Stripe Configuration API to manage payment methods enabled/disabled states.
174174
* Dev - Add track events when enabling/disabling payment methods.
175+
* Fix - Prepare mandate data from subscription object on change payment method page.
175176

176177
[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

0 commit comments

Comments
 (0)