Merge pull request #23372 from overleaf/ls-update-pricing-logic-for-seats-adding

Update pricing logic for seats adding

GitOrigin-RevId: 8312941c88ade2e5ee83c806939628714880b416
This commit is contained in:
Liangjun Song
2025-02-06 13:00:37 +00:00
committed by Copybot
parent 5facec8ed2
commit 735fd761cd
6 changed files with 21 additions and 25 deletions

View File

@@ -261,7 +261,6 @@ function subscriptionFromApi(apiSubscription) {
apiSubscription.currency == null ||
apiSubscription.currentPeriodStartedAt == null ||
apiSubscription.currentPeriodEndsAt == null ||
apiSubscription.createdAt == null ||
apiSubscription.collectionMethod == null
) {
throw new OError('Invalid Recurly subscription', {
@@ -283,7 +282,6 @@ function subscriptionFromApi(apiSubscription) {
currency: apiSubscription.currency,
periodStart: apiSubscription.currentPeriodStartedAt,
periodEnd: apiSubscription.currentPeriodEndsAt,
createdAt: apiSubscription.createdAt,
collectionMethod: apiSubscription.collectionMethod,
})

View File

@@ -25,7 +25,6 @@ class RecurlySubscription {
* @param {number} props.total
* @param {Date} props.periodStart
* @param {Date} props.periodEnd
* @param {Date} props.createdAt
* @param {string} props.collectionMethod
* @param {RecurlySubscriptionChange} [props.pendingChange]
*/
@@ -43,7 +42,6 @@ class RecurlySubscription {
this.total = props.total
this.periodStart = props.periodStart
this.periodEnd = props.periodEnd
this.createdAt = props.createdAt
this.collectionMethod = props.collectionMethod
this.pendingChange = props.pendingChange ?? null
}

View File

@@ -132,22 +132,21 @@ async function _addSeatsSubscriptionChange(userId, adding) {
)
} else {
let unitPrice
const newPlanPricesAppliedAt = new Date('2025-01-08T14:00:00Z')
const isLegacyPriceApplicable =
new Date(recurlySubscription.createdAt) < newPlanPricesAppliedAt
const pattern =
/^group_(collaborator|professional)_(2|3|4|5|10|20|50)_(educational|enterprise)$/
const [, planCode, size, usage] = plan.planCode.match(pattern)
const currency = recurlySubscription.currency
const planPriceInCents =
GroupPlansData[usage][planCode][currency][size].price_in_cents
const legacyUnitPriceInCents =
GroupPlansData[usage][planCode][currency][size]
.additional_license_legacy_price_in_cents
if (isLegacyPriceApplicable) {
const pattern =
/^group_(collaborator|professional)_(2|3|4|5|10|20|50)_(educational|enterprise)$/
const [, planCode, size, usage] = plan.planCode.match(pattern)
const currency = recurlySubscription.currency
const legacyPriceInCents =
GroupPlansData[usage][planCode][currency][size]
.additional_license_legacy_price_in_cents
if (legacyPriceInCents > 0) {
unitPrice = legacyPriceInCents / 100
}
if (
planPriceInCents / 100 > recurlySubscription.planPrice &&
legacyUnitPriceInCents > 0
) {
unitPrice = legacyUnitPriceInCents / 100
}
changeRequest = recurlySubscription.getRequestForAddOnPurchase(

View File

@@ -50,7 +50,6 @@ describe('RecurlyClient', function () {
total: 16.5,
periodStart: new Date(),
periodEnd: new Date(),
createdAt: new Date(),
collectionMethod: 'automatic',
})
@@ -81,7 +80,6 @@ describe('RecurlyClient', function () {
currency: this.subscription.currency,
currentPeriodStartedAt: this.subscription.periodStart,
currentPeriodEndsAt: this.subscription.periodEnd,
createdAt: this.subscription.createdAt,
collectionMethod: this.subscription.collectionMethod,
}

View File

@@ -372,7 +372,6 @@ describe('RecurlyEntities', function () {
total: 11.5,
periodStart: new Date(),
periodEnd: new Date(),
createdAt: new Date(),
collectionMethod: 'automatic',
})
const change = new RecurlySubscriptionChange({

View File

@@ -50,7 +50,6 @@ describe('SubscriptionGroupHandler', function () {
getRequestForFlexibleLicensingGroupPlanUpgrade: sinon
.stub()
.returns(this.changeRequest),
createdAt: '2025-01-01T00:00:00Z',
currency: 'USD',
hasAddOn(code) {
return this.addOns.some(addOn => addOn.code === code)
@@ -472,7 +471,10 @@ describe('SubscriptionGroupHandler', function () {
})
it('should return the subscription change preview with legacy add-on price', async function () {
this.recurlySubscription.createdAt = '2025-01-01T00:00:00Z'
this.recurlySubscription.planPrice =
this.GroupPlansData.enterprise.collaborator.USD[5].price_in_cents /
100 -
1
preview =
await this.Handler.promises.previewAddSeatsSubscriptionChange(
@@ -490,7 +492,9 @@ describe('SubscriptionGroupHandler', function () {
})
it('should return the subscription change preview with non-legacy add-on price', async function () {
this.recurlySubscription.createdAt = '2030-01-01T00:00:00Z'
this.recurlySubscription.planPrice =
this.GroupPlansData.enterprise.collaborator.USD[5].price_in_cents /
100
preview =
await this.Handler.promises.previewAddSeatsSubscriptionChange(