mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
Merge pull request #25852 from overleaf/ls-sync-stripe-subscription-logic
Replicate syncing logic for Stripe subscription GitOrigin-RevId: 9422a3e193160409eddd4c5f2c80e8578bd88559
This commit is contained in:
@@ -318,38 +318,7 @@ async function updateSubscriptionFromRecurly(
|
||||
requesterData
|
||||
) {
|
||||
if (recurlySubscription.state === 'expired') {
|
||||
const hasManagedUsersFeature =
|
||||
Features.hasFeature('saas') && subscription?.managedUsersEnabled
|
||||
|
||||
// If a payment lapses and if the group is managed or has group SSO, as a temporary measure we need to
|
||||
// make sure that the group continues as-is and no destructive actions are taken.
|
||||
if (hasManagedUsersFeature) {
|
||||
logger.warn(
|
||||
{ subscriptionId: subscription._id },
|
||||
'expired subscription has managedUsers feature enabled, skipping deletion'
|
||||
)
|
||||
} else {
|
||||
let hasGroupSSOEnabled = false
|
||||
if (subscription?.ssoConfig) {
|
||||
const ssoConfig = await SSOConfig.findOne({
|
||||
_id: subscription.ssoConfig._id || subscription.ssoConfig,
|
||||
})
|
||||
.lean()
|
||||
.exec()
|
||||
if (ssoConfig.enabled) {
|
||||
hasGroupSSOEnabled = true
|
||||
}
|
||||
}
|
||||
|
||||
if (hasGroupSSOEnabled) {
|
||||
logger.warn(
|
||||
{ subscriptionId: subscription._id },
|
||||
'expired subscription has groupSSO feature enabled, skipping deletion'
|
||||
)
|
||||
} else {
|
||||
await deleteSubscription(subscription, requesterData)
|
||||
}
|
||||
}
|
||||
await handleExpiredSubscription(subscription, requesterData)
|
||||
return
|
||||
}
|
||||
const updatedPlanCode = recurlySubscription.plan.plan_code
|
||||
@@ -450,6 +419,41 @@ async function _sendUserGroupPlanCodeUserProperty(userId) {
|
||||
}
|
||||
}
|
||||
|
||||
async function handleExpiredSubscription(subscription, requesterData) {
|
||||
const hasManagedUsersFeature =
|
||||
Features.hasFeature('saas') && subscription?.managedUsersEnabled
|
||||
|
||||
// If a payment lapses and if the group is managed or has group SSO, as a temporary measure we need to
|
||||
// make sure that the group continues as-is and no destructive actions are taken.
|
||||
if (hasManagedUsersFeature) {
|
||||
logger.warn(
|
||||
{ subscriptionId: subscription._id },
|
||||
'expired subscription has managedUsers feature enabled, skipping deletion'
|
||||
)
|
||||
} else {
|
||||
let hasGroupSSOEnabled = false
|
||||
if (subscription?.ssoConfig) {
|
||||
const ssoConfig = await SSOConfig.findOne({
|
||||
_id: subscription.ssoConfig._id || subscription.ssoConfig,
|
||||
})
|
||||
.lean()
|
||||
.exec()
|
||||
if (ssoConfig.enabled) {
|
||||
hasGroupSSOEnabled = true
|
||||
}
|
||||
}
|
||||
|
||||
if (hasGroupSSOEnabled) {
|
||||
logger.warn(
|
||||
{ subscriptionId: subscription._id },
|
||||
'expired subscription has groupSSO feature enabled, skipping deletion'
|
||||
)
|
||||
} else {
|
||||
await deleteSubscription(subscription, requesterData)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function _sendSubscriptionEvent(userId, subscriptionId, event) {
|
||||
const subscription = await Subscription.findOne(
|
||||
{ _id: subscriptionId },
|
||||
@@ -568,5 +572,6 @@ module.exports = {
|
||||
setRestorePoint,
|
||||
setSubscriptionWasReverted,
|
||||
voidRestorePoint,
|
||||
handleExpiredSubscription,
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user