Explorar el Código

Fetch all the subscriptions when backfilling user ids (#29005)

GitOrigin-RevId: 07c091176e50cad250e6bb4dea94fa3424643fd2
Liangjun Song hace 10 meses
padre
commit
b03b1e3bfc

+ 7 - 0
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

+ 1 - 0
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