Check if AI assist standalone plan is used in shouldPlanChangeAtTermEnd (#26272)

GitOrigin-RevId: d6737ea28071d565109dba695876b6fbf3f5daa2
This commit is contained in:
Domagoj Kriskovic
2025-06-12 13:19:42 +02:00
committed by Copybot
parent cdec3e2644
commit e6d75ad47b
3 changed files with 16 additions and 2 deletions

View File

@@ -8,7 +8,8 @@
const OError = require('@overleaf/o-error')
const { DuplicateAddOnError, AddOnNotPresentError } = require('./Errors')
const PlansLocator = require('./PlansLocator')
const SubscriptionHelper = require('./SubscriptionHelper')
let SubscriptionHelper = null // Work around circular import (loaded at the bottom of the file)
const AI_ADD_ON_CODE = 'assistant'
const MEMBERS_LIMIT_ADD_ON_CODE = 'additional-license'
@@ -636,3 +637,5 @@ module.exports = {
subscriptionChangeIsAiAssistUpgrade,
PaymentProviderImmediateCharge,
}
SubscriptionHelper = require('./SubscriptionHelper')

View File

@@ -1,11 +1,20 @@
const { formatCurrency } = require('../../util/currency')
const GroupPlansData = require('./GroupPlansData')
const { isStandaloneAiAddOnPlanCode } = require('./PaymentProviderEntities')
/**
* If the user changes to a less expensive plan, we shouldn't apply the change immediately.
* This is to avoid unintended/artifical credits on users Recurly accounts.
*/
function shouldPlanChangeAtTermEnd(oldPlan, newPlan) {
if (
oldPlan.annual === newPlan.annual &&
isStandaloneAiAddOnPlanCode(oldPlan.planCode) &&
!isStandaloneAiAddOnPlanCode(newPlan.planCode)
) {
// changing from an standalone AI add-on plan to a non-AI plan should not be considered a downgrade
return false
}
return oldPlan.price_in_cents > newPlan.price_in_cents
}

View File

@@ -11,6 +11,7 @@ const {
PaymentProviderSubscription,
PaymentProviderSubscriptionAddOnUpdate,
} = require('../../../../app/src/Features/Subscription/PaymentProviderEntities')
const SubscriptionHelper = require('../../../../app/src/Features/Subscription/SubscriptionHelper')
const MODULE_PATH =
'../../../../app/src/Features/Subscription/PaymentProviderEntities'
@@ -32,6 +33,7 @@ describe('PaymentProviderEntities', function () {
requires: {
'@overleaf/settings': this.Settings,
'./Errors': Errors,
'./SubscriptionHelper': SubscriptionHelper,
},
})
})
@@ -154,7 +156,7 @@ describe('PaymentProviderEntities', function () {
expect(changeRequest).to.deep.equal(
new PaymentProviderSubscriptionChangeRequest({
subscription: this.subscription,
timeframe: 'term_end',
timeframe: 'now',
planCode: 'cheap-plan',
addOnUpdates: [
new PaymentProviderSubscriptionAddOnUpdate({