diff --git a/changelog.txt b/changelog.txt index f34a11a2b..be51ae244 100644 --- a/changelog.txt +++ b/changelog.txt @@ -14,6 +14,7 @@ * Tweak - Add error logging in ECE critical Ajax requests. * Add - Add support for Stripe Link payments via the new Stripe Checkout Element on the block cart and block checkout pages. * Add - Add support for Stripe Link payments via the new Stripe Checkout Element on the product, cart, checkout and pay for order pages. +* Tweak - Remove the subscription order notes added each time a source wasn't migrated. = 8.8.1 - 2024-10-28 = * Tweak - Disables APMs when using the legacy checkout experience due Stripe deprecation by October 29, 2024. diff --git a/includes/compat/class-wc-stripe-subscriptions-legacy-sepa-token-update.php b/includes/compat/class-wc-stripe-subscriptions-legacy-sepa-token-update.php index b294942ae..c6cc78ad0 100644 --- a/includes/compat/class-wc-stripe-subscriptions-legacy-sepa-token-update.php +++ b/includes/compat/class-wc-stripe-subscriptions-legacy-sepa-token-update.php @@ -70,14 +70,10 @@ public function maybe_update_subscription_legacy_payment_method( $subscription_i public function maybe_update_subscription_source( WC_Subscription $subscription ) { try { $this->set_subscription_updated_payment_method( $subscription ); - - $order_note = __( 'Stripe Gateway: The payment method used for renewals was updated from Sources to PaymentMethods.', 'woocommerce-gateway-stripe' ); + $subscription->add_order_note( __( 'Stripe Gateway: The payment method used for renewals was updated from Sources to PaymentMethods.', 'woocommerce-gateway-stripe' ) ); } catch ( \Exception $e ) { - /* translators: Reason why the subscription payment method wasn't updated */ - $order_note = sprintf( __( 'Stripe Gateway: A Source is used for renewals but could not be updated to PaymentMethods. Reason: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ); + WC_Stripe_Logger::log( $e->getMessage() ); } - - $subscription->add_order_note( $order_note ); } /** @@ -131,6 +127,11 @@ private function set_subscription_updated_payment_method( WC_Subscription $subsc // Retrieve the source object from the API. $source_object = WC_Stripe_API::get_payment_method( $source_id ); + // Bail out, if the source object isn't expected to be migrated. eg Card sources are not migrated. + if ( isset( $source_object->type ) && 'card' === $source_object->type ) { + throw new \Exception( sprintf( 'Skipping migration of Source for subscription #%d. Source is a card.', $subscription->get_id() ) ); + } + // Bail out if the src_ hasn't been migrated to pm_ yet. if ( ! isset( $source_object->metadata->migrated_payment_method ) ) { throw new \Exception( sprintf( 'The Source has not been migrated to PaymentMethods on the Stripe account.', $subscription->get_id() ) ); diff --git a/readme.txt b/readme.txt index 45a5595e2..da8b0c80b 100644 --- a/readme.txt +++ b/readme.txt @@ -124,5 +124,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o * Tweak - Add error logging in ECE critical Ajax requests. * Add - Add support for Stripe Link payments via the new Stripe Checkout Element on the block cart and block checkout pages. * Add - Add support for Stripe Link payments via the new Stripe Checkout Element on the product, cart, checkout and pay for order pages. +* Tweak - Remove the subscription order notes added each time a source wasn't migrated. [See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt). diff --git a/tests/phpunit/admin/migrations/test-class-wc-stripe-subscriptions-repairer-legacy-sepa-tokens.php b/tests/phpunit/admin/migrations/test-class-wc-stripe-subscriptions-repairer-legacy-sepa-tokens.php index 498248b8e..90475e17b 100644 --- a/tests/phpunit/admin/migrations/test-class-wc-stripe-subscriptions-repairer-legacy-sepa-tokens.php +++ b/tests/phpunit/admin/migrations/test-class-wc-stripe-subscriptions-repairer-legacy-sepa-tokens.php @@ -328,18 +328,9 @@ function ( $id ) { $this->updater->maybe_migrate_before_renewal( $subscription_id ); $subscription = new WC_Subscription( $subscription_id ); - $notes = wc_get_order_notes( - [ 'order_id' => $subscription_id ] - ); // Confirm the subscription's payment method remains the same. $this->assertEquals( $pm_id, $subscription->get_meta( self::SOURCE_ID_META_KEY ) ); - - // Confirm a note is added when the Source wasn't migrated to PaymentMethods. - $this->assertEquals( - 'Stripe Gateway: A Source is used for renewals but could not be updated to PaymentMethods. Reason: The subscription is not using a Stripe Source for renewals.', - $notes[0]->content - ); } public function test_maybe_update_subscription_legacy_payment_method_adds_note_when_source_not_migrated() { @@ -361,18 +352,9 @@ function ( $id ) { $this->updater->maybe_migrate_before_renewal( $subscription_id ); $subscription = new WC_Subscription( $subscription_id ); - $notes = wc_get_order_notes( - [ 'order_id' => $subscription_id ] - ); // Confirm the subscription's payment method remains the same. $this->assertEquals( $source_id, $subscription->get_meta( self::SOURCE_ID_META_KEY ) ); - - // Confirm a note is added when the Source wasn't migrated to PaymentMethods. - $this->assertEquals( - 'Stripe Gateway: A Source is used for renewals but could not be updated to PaymentMethods. Reason: The Source has not been migrated to PaymentMethods on the Stripe account.', - $notes[0]->content - ); } /**