mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
[web] throw an error if multiple active subscriptions found (#31458)
GitOrigin-RevId: e0c2fe9ab73b0f8800f419ac1a3ff78adce29c5c
This commit is contained in:
@@ -322,6 +322,8 @@ async function processMigration(input, commit) {
|
||||
region: stripeClient.serviceName,
|
||||
}
|
||||
)
|
||||
|
||||
// handle no subscriptions found
|
||||
if (
|
||||
!stripeCustomer.subscriptions ||
|
||||
stripeCustomer.subscriptions.data.length === 0
|
||||
@@ -331,13 +333,25 @@ async function processMigration(input, commit) {
|
||||
'No Stripe subscriptions found for customer'
|
||||
)
|
||||
}
|
||||
// find the subscription with migration metadata
|
||||
|
||||
// handle multiple active subscriptions found
|
||||
const activeSubscriptions = stripeCustomer.subscriptions.data.filter(sub =>
|
||||
['active', 'past_due', 'incomplete'].includes(sub.status)
|
||||
)
|
||||
if (activeSubscriptions.length > 1) {
|
||||
throw new ReportError(
|
||||
'multiple-active-stripe-subscriptions',
|
||||
'Multiple active Stripe subscriptions found for customer'
|
||||
)
|
||||
}
|
||||
|
||||
// find the target subscription with migration metadata
|
||||
stripeSubscription = stripeCustomer.subscriptions.data.find(
|
||||
sub => sub.metadata?.recurly_to_stripe_migration_status === 'in_progress'
|
||||
)
|
||||
if (!stripeSubscription) {
|
||||
throw new ReportError(
|
||||
'no-stripe-subscription',
|
||||
'no-target-stripe-subscription',
|
||||
'No target Stripe subscription found for customer'
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user