Просмотр исходного кода

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

Update pricing logic for seats adding

GitOrigin-RevId: 8312941c88ade2e5ee83c806939628714880b416
Liangjun Song 1 год назад
Родитель
Сommit
735fd761cd

+ 0 - 2
services/web/app/src/Features/Subscription/RecurlyClient.js

@@ -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,
   })
 

+ 0 - 2
services/web/app/src/Features/Subscription/RecurlyEntities.js

@@ -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
   }

+ 15 - 16
services/web/app/src/Features/Subscription/SubscriptionGroupHandler.js

@@ -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
-
-    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
-      }
+    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 (
+      planPriceInCents / 100 > recurlySubscription.planPrice &&
+      legacyUnitPriceInCents > 0
+    ) {
+      unitPrice = legacyUnitPriceInCents / 100
     }
 
     changeRequest = recurlySubscription.getRequestForAddOnPurchase(

+ 0 - 2
services/web/test/unit/src/Subscription/RecurlyClientTests.js

@@ -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,
     }
 

+ 0 - 1
services/web/test/unit/src/Subscription/RecurlyEntitiesTest.js

@@ -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({

+ 7 - 3
services/web/test/unit/src/Subscription/SubscriptionGroupHandlerTests.js

@@ -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(