Skip to content

Commit b03e2fd

Browse files
committed
Fix - Stop retrying a Stripe subscription that no longer exists
A resource_missing error means the gateway subscription is gone for good (deleted, or created under the other API mode), but retry_subscription() handled it like a transient failure, so the daily cron re-attempted the same impossible lookup every day. One live site logged 1596 of these for a single row holding a test-mode id under live keys. Mark the gateway subscription unrecoverable on resource_missing and bail out early on the next run. Keying the marker by the gateway id keeps it self-invalidating: correcting the id on the row lets retries resume. Also log member_id instead of user_id, which the retry query never returns - every existing entry reads "user_id": "unknown". Closes #1420
1 parent e52cf15 commit b03e2fd

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

modules/membership/includes/Admin/Services/Stripe/StripeService.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2908,6 +2908,12 @@ public function retry_subscription( $subscription ) {
29082908
return $response;
29092909
}
29102910

2911+
if ( ! empty( $subscription['member_id'] ) && get_user_meta( $subscription['member_id'], 'urm_retry_unrecoverable_' . $subscription['sub_id'], true ) ) {
2912+
$response['message'] = __( 'Subscription no longer exists at Stripe and will not be retried', 'user-registration' );
2913+
2914+
return $response;
2915+
}
2916+
29112917
PaymentGatewayLogging::log_general(
29122918
'stripe',
29132919
'Retrying Stripe subscription payment' . "\n" . wp_json_encode(
@@ -3047,12 +3053,22 @@ public function retry_subscription( $subscription ) {
30473053
'error_code' => $e->getStripeCode(),
30483054
'error_message' => $e->getMessage(),
30493055
'subscription_id' => $subscription['subscription_id'],
3050-
'user_id' => $subscription['user_id'] ?? 'unknown',
3056+
'member_id' => $subscription['member_id'] ?? 'unknown',
30513057
),
30523058
JSON_PRETTY_PRINT
30533059
)
30543060
);
30553061

3062+
// A missing subscription can never come back (deleted, or created under the other API mode),
3063+
// so stop the daily cron from retrying this row forever.
3064+
if ( 'resource_missing' === $e->getStripeCode() && ! empty( $subscription['member_id'] ) ) {
3065+
update_user_meta(
3066+
$subscription['member_id'],
3067+
'urm_retry_unrecoverable_' . $subscription['sub_id'],
3068+
$e->getMessage()
3069+
);
3070+
}
3071+
30563072
$response['message'] = $e->getMessage();
30573073

30583074
return $response;

0 commit comments

Comments
 (0)