From b03b1e3bfcfd7dea3d645349c149f92db981a659 Mon Sep 17 00:00:00 2001 From: Liangjun Song <146005915+adai26@users.noreply.github.com> Date: Mon, 13 Oct 2025 09:01:34 +0100 Subject: [PATCH] Fetch all the subscriptions when backfilling user ids (#29005) GitOrigin-RevId: 07c091176e50cad250e6bb4dea94fa3424643fd2 --- .../web/scripts/stripe/add_user_id_to_stripe_customer.mjs | 7 +++++++ .../remove_admin_user_id_from_stripe_subscription.mjs | 1 + 2 files changed, 8 insertions(+) diff --git a/services/web/scripts/stripe/add_user_id_to_stripe_customer.mjs b/services/web/scripts/stripe/add_user_id_to_stripe_customer.mjs index 251d991dea..de702602ea 100644 --- a/services/web/scripts/stripe/add_user_id_to_stripe_customer.mjs +++ b/services/web/scripts/stripe/add_user_id_to_stripe_customer.mjs @@ -80,6 +80,12 @@ async function processSubscription( // Get customer details to check current metadata const customer = subscription.customer + if (customer.deleted) { + if (verbose) { + console.info(`Customer ${customer.id} is deleted, skipping`) + } + return + } if (customer.metadata?.userId === adminUserId) { if (verbose) { @@ -164,6 +170,7 @@ async function main(trackProgress) { const listParams = { limit: 100, // Stripe's maximum limit per request expand: ['data.customer'], // Expand customer data to reduce additional API calls + status: 'all', // Include subscriptions in all statuses (active, past_due, unpaid, canceled, etc.) } let hasMore = true diff --git a/services/web/scripts/stripe/remove_admin_user_id_from_stripe_subscription.mjs b/services/web/scripts/stripe/remove_admin_user_id_from_stripe_subscription.mjs index a44eb629ee..c2425b6ddd 100644 --- a/services/web/scripts/stripe/remove_admin_user_id_from_stripe_subscription.mjs +++ b/services/web/scripts/stripe/remove_admin_user_id_from_stripe_subscription.mjs @@ -143,6 +143,7 @@ async function main(trackProgress) { const listParams = { limit: 100, // Stripe's maximum limit per request + status: 'all', // Include subscriptions in all statuses (active, past_due, unpaid, canceled, etc.) } let hasMore = true