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

No longer record source migration failures in subscription order notes #3566

Merged
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down Expand Up @@ -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() ) );
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
);
}

/**
Expand Down
Loading