Просмотр исходного кода

[web] handle pending changes in finalization script (#31342)

GitOrigin-RevId: 3f17c32d897e818d0ae1b0e33e66350de8513a8a
Kristina 6 месяцев назад
Родитель
Сommit
a184a0c32f

+ 7 - 9
services/web/scripts/stripe/finalize-stripe-subscription-migration.mjs

@@ -433,16 +433,18 @@ function detectChanges(recurlySubscription, stripeSubscription, region) {
   const changes = []
 
   // Extract item details from Recurly subscription
+  const targetRecurlySubscription =
+    recurlySubscription.pending_subscription || recurlySubscription
   const recurlyPlanItem =
     PlansLocator.convertLegacyGroupPlanCodeToConsolidatedGroupPlanCodeIfNeeded(
-      recurlySubscription.plan.plan_code
+      targetRecurlySubscription.plan.plan_code
     )
   const simplifiedPlanCode = recurlyPlanItem.planCode.replace(
     /_free_trial.*$/,
     ''
   )
   const additionalLicenseQuantity =
-    (recurlySubscription.subscription_add_ons || []).find(
+    (targetRecurlySubscription.subscription_add_ons || []).find(
       addOn => addOn.add_on_code === 'additional-license'
     )?.quantity || 0
   const recurlyItems = [
@@ -450,9 +452,10 @@ function detectChanges(recurlySubscription, stripeSubscription, region) {
       code: simplifiedPlanCode,
       quantity: recurlyPlanItem.quantity + additionalLicenseQuantity,
       amount:
-        recurlySubscription.unit_amount_in_cents / recurlyPlanItem.quantity,
+        targetRecurlySubscription.unit_amount_in_cents /
+        recurlyPlanItem.quantity,
     },
-    ...(recurlySubscription.subscription_add_ons || [])
+    ...(targetRecurlySubscription.subscription_add_ons || [])
       .filter(addOn => addOn.add_on_code !== 'additional-license')
       .map(addOn => ({
         code: addOn.add_on_code,
@@ -499,11 +502,6 @@ function detectChanges(recurlySubscription, stripeSubscription, region) {
     changes.push(`State: Recurly=${recurlyState}, Stripe=${stripeState}`)
   }
 
-  // Verify no changes have been scheduled in Recurly
-  if (recurlySubscription.pending_subscription != null) {
-    changes.push('Pending change now exists in Recurly subscription')
-  }
-
   return changes
 }