From ad853d661a2dcfda0e6c36f8c751a5137042376b Mon Sep 17 00:00:00 2001 From: Kristina <7614497+khjrtbrg@users.noreply.github.com> Date: Fri, 27 Mar 2026 10:53:06 +0100 Subject: [PATCH] [migration] fix issues found in finalization script during stage 3b (#32472) * accept taxInfoPending as tax id comparison point * convert recurly unit amount to minor units correctly for no cent currencies * Use original subscription currency in finalization check * make it easier to spot migrated with tax info pending --------- Co-authored-by: John Lees-Miller Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> GitOrigin-RevId: d3c74032bc06369fcf6bafb4cfaff85c49a3cfef --- ...te_recurly_customers_to_stripe.helpers.mjs | 19 +++++++++++++------ ...finalize-stripe-subscription-migration.mjs | 13 ++++++++++--- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/services/web/scripts/helpers/migrate_recurly_customers_to_stripe.helpers.mjs b/services/web/scripts/helpers/migrate_recurly_customers_to_stripe.helpers.mjs index b997cca46a..ed05085b15 100644 --- a/services/web/scripts/helpers/migrate_recurly_customers_to_stripe.helpers.mjs +++ b/services/web/scripts/helpers/migrate_recurly_customers_to_stripe.helpers.mjs @@ -1459,13 +1459,8 @@ export async function compareAccountFields({ if (taxIdTypeResult.type && address?.country) { expectedTaxIdType = taxIdTypeResult.type expectedTaxIdValue = vatNumber - } else { - expectedMetadata.taxInfoPending = vatNumber } } - if (!expectedMetadata.taxInfoPending) { - expectedMetadata.taxInfoPending = '' - } for (const [key, expectedValue] of Object.entries(expectedMetadata)) { const stripeValue = stripeCustomer.metadata?.[key] ?? '' @@ -1504,7 +1499,19 @@ export async function compareAccountFields({ // Tax ID if (expectedTaxIdType && expectedTaxIdValue) { const normalizedExpectedTaxIdValue = normalizeTaxIdValue(expectedTaxIdValue) - const stripeTaxIds = stripeCustomer.tax_ids?.data || [] + const stripePendingTaxId = stripeCustomer.metadata?.taxInfoPending + ? [ + { + type: expectedTaxIdType, + value: stripeCustomer.metadata.taxInfoPending, + }, + ] + : null + const stripeTaxIdsFromStripe = stripeCustomer.tax_ids?.data + const stripeTaxIds = + Array.isArray(stripeTaxIdsFromStripe) && stripeTaxIdsFromStripe.length > 0 + ? stripeTaxIdsFromStripe + : stripePendingTaxId || [] const matchingTaxId = stripeTaxIds.find( tid => tid.type === expectedTaxIdType && diff --git a/services/web/scripts/stripe/finalize-stripe-subscription-migration.mjs b/services/web/scripts/stripe/finalize-stripe-subscription-migration.mjs index b2bb9c6a3b..76812baf68 100755 --- a/services/web/scripts/stripe/finalize-stripe-subscription-migration.mjs +++ b/services/web/scripts/stripe/finalize-stripe-subscription-migration.mjs @@ -56,7 +56,7 @@ import AccountMappingHelper from '../../app/src/Features/Analytics/AccountMappin import PlansLocator from '../../app/src/Features/Subscription/PlansLocator.mjs' import UserAnalyticsIdCache from '../../app/src/Features/Analytics/UserAnalyticsIdCache.mjs' import CustomerIoHandler from '../../modules/customer-io/app/src/CustomerIoHandler.mjs' -import { ReportError } from './helpers.mjs' +import { ReportError, convertToMinorUnits } from './helpers.mjs' import isEqual from 'lodash/isEqual.js' import { compareAccountFields } from '../helpers/migrate_recurly_customers_to_stripe.helpers.mjs' import { @@ -472,6 +472,12 @@ async function processMigration(input, commit) { result.status = 'migrated' result.note = 'Successfully migrated to Stripe' + + if (stripeCustomer.metadata?.taxInfoPending) { + result.status += '-tax-info-pending' + result.note += '; Tax info pending' + } + return result } else { result.status = 'validated' @@ -511,12 +517,13 @@ function detectSubscriptionChanges( (targetRecurlySubscription.addOns || []).find( addOn => addOn.addOn.code === 'additional-license' )?.quantity || 0 + const currency = recurlySubscription.currency const recurlyItems = [ { code: simplifiedPlanCode, quantity: recurlyPlanItem.quantity + additionalLicenseQuantity, amount: - Math.round(targetRecurlySubscription.unitAmount * 100) / + convertToMinorUnits(targetRecurlySubscription.unitAmount, currency) / recurlyPlanItem.quantity, }, ...(targetRecurlySubscription.addOns || []) @@ -524,7 +531,7 @@ function detectSubscriptionChanges( .map(addOn => ({ code: addOn.addOn.code, quantity: addOn.quantity, - amount: Math.round(addOn.unitAmount * 100), + amount: convertToMinorUnits(addOn.unitAmount, currency), })), ].sort((a, b) => a.code.localeCompare(b.code))