mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 22:23:42 +01:00
[web] remap customer.metadata.recurlyAccountCode in migration scripts (#31097)
* remap customer.metadata.recurlyAccountCode to customer.metadata.userId * verify recurlyAccountCode is what we expect it to be before setting GitOrigin-RevId: 8ab1d5e311dba34bb8c15d01096f6c31273a7506
This commit is contained in:
@@ -1023,6 +1023,19 @@ async function processCustomer(
|
||||
if (account.createdAt) {
|
||||
metadata.recurlyCreatedAt = account.createdAt.toISOString()
|
||||
}
|
||||
if (
|
||||
existingCustomer.metadata != null &&
|
||||
existingCustomer.metadata.recurlyAccountCode === recurlyAccountCode &&
|
||||
existingCustomer.metadata.userId == null
|
||||
) {
|
||||
metadata.recurlyAccountCode = ''
|
||||
metadata.userId = recurlyAccountCode
|
||||
} else {
|
||||
logWarn('Stripe customer metadata cannot be remapped', {
|
||||
...context,
|
||||
existingCustomerMetadata: existingCustomer.metadata,
|
||||
})
|
||||
}
|
||||
|
||||
/** @type {Stripe.CustomerUpdateParams} */
|
||||
const customerParams = {
|
||||
|
||||
@@ -314,7 +314,8 @@ async function processMigration(input, commit) {
|
||||
mongoSubscription,
|
||||
stripeSubscription,
|
||||
recurlySubscription,
|
||||
stripeClient
|
||||
stripeClient,
|
||||
stripeCustomer
|
||||
)
|
||||
return {
|
||||
status: 'migrated',
|
||||
@@ -403,7 +404,8 @@ async function performCutover(
|
||||
mongoSubscription,
|
||||
stripeSubscription,
|
||||
recurlySubscription,
|
||||
stripeClient
|
||||
stripeClient,
|
||||
stripeCustomer
|
||||
) {
|
||||
const adminUserId = mongoSubscription.admin_id.toString()
|
||||
|
||||
@@ -473,6 +475,25 @@ async function performCutover(
|
||||
`Successfully migrated to Stripe but failed to register analytics mapping: ${err.message}`
|
||||
)
|
||||
}
|
||||
|
||||
// Step 6. Remap customer metadata (if needed) in Stripe
|
||||
if (
|
||||
stripeCustomer.metadata != null &&
|
||||
stripeCustomer.metadata.recurlyAccountCode != null &&
|
||||
stripeCustomer.metadata.userId == null
|
||||
) {
|
||||
try {
|
||||
await stripeClient.updateCustomerMetadata(stripeCustomer.id, {
|
||||
recurlyAccountCode: '',
|
||||
userId: adminUserId,
|
||||
})
|
||||
} catch (err) {
|
||||
throw new ReportError(
|
||||
'customer-metadata-removal-failed',
|
||||
`Successfully migrated to Stripe and registered analytics mapping but failed to remove customer metadata: ${err.message}`
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function parseArgs() {
|
||||
|
||||
Reference in New Issue
Block a user