Skip to content

Commit 6a076e3

Browse files
authored
No longer record source migration failures in subscription order notes (#3566)
* Exclude card sources from being migrated to PMs * Skip adding an order note if the subscription source was not migrated * Tweak comments * Add changelog entries * Remove consts * Remove tests which confirm order note was added * Remove unsed $notes variable
1 parent 4596314 commit 6a076e3

File tree

4 files changed

+9
-24
lines changed

4 files changed

+9
-24
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* Tweak - Add error logging in ECE critical Ajax requests.
1515
* Add - Add support for Stripe Link payments via the new Stripe Checkout Element on the block cart and block checkout pages.
1616
* Add - Add support for Stripe Link payments via the new Stripe Checkout Element on the product, cart, checkout and pay for order pages.
17+
* Tweak - Remove the subscription order notes added each time a source wasn't migrated.
1718

1819
= 8.8.1 - 2024-10-28 =
1920
* Tweak - Disables APMs when using the legacy checkout experience due Stripe deprecation by October 29, 2024.

includes/compat/class-wc-stripe-subscriptions-legacy-sepa-token-update.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,10 @@ public function maybe_update_subscription_legacy_payment_method( $subscription_i
7070
public function maybe_update_subscription_source( WC_Subscription $subscription ) {
7171
try {
7272
$this->set_subscription_updated_payment_method( $subscription );
73-
74-
$order_note = __( 'Stripe Gateway: The payment method used for renewals was updated from Sources to PaymentMethods.', 'woocommerce-gateway-stripe' );
73+
$subscription->add_order_note( __( 'Stripe Gateway: The payment method used for renewals was updated from Sources to PaymentMethods.', 'woocommerce-gateway-stripe' ) );
7574
} catch ( \Exception $e ) {
76-
/* translators: Reason why the subscription payment method wasn't updated */
77-
$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() );
75+
WC_Stripe_Logger::log( $e->getMessage() );
7876
}
79-
80-
$subscription->add_order_note( $order_note );
8177
}
8278

8379
/**
@@ -131,6 +127,11 @@ private function set_subscription_updated_payment_method( WC_Subscription $subsc
131127
// Retrieve the source object from the API.
132128
$source_object = WC_Stripe_API::get_payment_method( $source_id );
133129

130+
// Bail out, if the source object isn't expected to be migrated. eg Card sources are not migrated.
131+
if ( isset( $source_object->type ) && 'card' === $source_object->type ) {
132+
throw new \Exception( sprintf( 'Skipping migration of Source for subscription #%d. Source is a card.', $subscription->get_id() ) );
133+
}
134+
134135
// Bail out if the src_ hasn't been migrated to pm_ yet.
135136
if ( ! isset( $source_object->metadata->migrated_payment_method ) ) {
136137
throw new \Exception( sprintf( 'The Source has not been migrated to PaymentMethods on the Stripe account.', $subscription->get_id() ) );

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
124124
* Tweak - Add error logging in ECE critical Ajax requests.
125125
* Add - Add support for Stripe Link payments via the new Stripe Checkout Element on the block cart and block checkout pages.
126126
* Add - Add support for Stripe Link payments via the new Stripe Checkout Element on the product, cart, checkout and pay for order pages.
127+
* Tweak - Remove the subscription order notes added each time a source wasn't migrated.
127128

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

tests/phpunit/admin/migrations/test-class-wc-stripe-subscriptions-repairer-legacy-sepa-tokens.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -328,18 +328,9 @@ function ( $id ) {
328328
$this->updater->maybe_migrate_before_renewal( $subscription_id );
329329

330330
$subscription = new WC_Subscription( $subscription_id );
331-
$notes = wc_get_order_notes(
332-
[ 'order_id' => $subscription_id ]
333-
);
334331

335332
// Confirm the subscription's payment method remains the same.
336333
$this->assertEquals( $pm_id, $subscription->get_meta( self::SOURCE_ID_META_KEY ) );
337-
338-
// Confirm a note is added when the Source wasn't migrated to PaymentMethods.
339-
$this->assertEquals(
340-
'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.',
341-
$notes[0]->content
342-
);
343334
}
344335

345336
public function test_maybe_update_subscription_legacy_payment_method_adds_note_when_source_not_migrated() {
@@ -361,18 +352,9 @@ function ( $id ) {
361352
$this->updater->maybe_migrate_before_renewal( $subscription_id );
362353

363354
$subscription = new WC_Subscription( $subscription_id );
364-
$notes = wc_get_order_notes(
365-
[ 'order_id' => $subscription_id ]
366-
);
367355

368356
// Confirm the subscription's payment method remains the same.
369357
$this->assertEquals( $source_id, $subscription->get_meta( self::SOURCE_ID_META_KEY ) );
370-
371-
// Confirm a note is added when the Source wasn't migrated to PaymentMethods.
372-
$this->assertEquals(
373-
'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.',
374-
$notes[0]->content
375-
);
376358
}
377359

378360
/**

0 commit comments

Comments
 (0)