Răsfoiți Sursa

Merge pull request #25329 from overleaf/ls-enable-stripe-checkout-for-group-plan

Enable stripe checkout for group subscriptions

GitOrigin-RevId: 10a579ebca789773bd2c94f8240b7b979b6e8eb0
Liangjun Song 1 an în urmă
părinte
comite
caf8b5c3c5

+ 19 - 0
services/web/app/src/Features/Subscription/PaymentProviderEntities.js

@@ -87,6 +87,15 @@ class PaymentProviderSubscription {
     return isStandaloneAiAddOnPlanCode(this.planCode)
   }
 
+  /**
+   * Returns whether this subscription is a group subscription
+   *
+   * @return {boolean}
+   */
+  isGroupSubscription() {
+    return isGroupPlanCode(this.planCode)
+  }
+
   /**
    * Returns whether this subcription will have the given add-on next billing
    * period.
@@ -543,6 +552,15 @@ function isStandaloneAiAddOnPlanCode(planCode) {
   return STANDALONE_AI_ADD_ON_CODES.includes(planCode)
 }
 
+/**
+ * Returns whether the given plan code is a group plan
+ *
+ * @param {string} planCode
+ */
+function isGroupPlanCode(planCode) {
+  return planCode.includes('group')
+}
+
 /**
  * Returns whether subscription change will have have the ai bundle once the change is processed
  *
@@ -575,6 +593,7 @@ module.exports = {
   PaymentProviderPlan,
   PaymentProviderCoupon,
   PaymentProviderAccount,
+  isGroupPlanCode,
   isStandaloneAiAddOnPlanCode,
   subscriptionChangeIsAiAssistUpgrade,
   PaymentProviderImmediateCharge,

+ 15 - 7
services/web/app/src/Features/Subscription/PlansLocator.js

@@ -34,6 +34,10 @@ const recurlyPlanCodeToStripeLookupKey = {
   'student-annual': 'student_annual',
   student: 'student_monthly',
   student_free_trial_7_days: 'student_monthly',
+  group_professional: 'group_professional_enterprise',
+  group_professional_educational: 'group_professional_educational',
+  group_collaborator: 'group_standard_enterprise',
+  group_collaborator_educational: 'group_standard_educational',
 }
 
 /**
@@ -46,24 +50,28 @@ function mapRecurlyPlanCodeToStripeLookupKey(recurlyPlanCode) {
 }
 
 const recurlyPlanCodeToPlanTypeAndPeriod = {
-  collaborator: { planType: 'standard', period: 'monthly' },
-  collaborator_free_trial_7_days: { planType: 'standard', period: 'monthly' },
-  'collaborator-annual': { planType: 'standard', period: 'annual' },
-  professional: { planType: 'professional', period: 'monthly' },
+  collaborator: { planType: 'individual', period: 'monthly' },
+  collaborator_free_trial_7_days: { planType: 'individual', period: 'monthly' },
+  'collaborator-annual': { planType: 'individual', period: 'annual' },
+  professional: { planType: 'individual', period: 'monthly' },
   professional_free_trial_7_days: {
-    planType: 'professional',
+    planType: 'individual',
     period: 'monthly',
   },
-  'professional-annual': { planType: 'professional', period: 'annual' },
+  'professional-annual': { planType: 'individual', period: 'annual' },
   student: { planType: 'student', period: 'monthly' },
   student_free_trial_7_days: { planType: 'student', period: 'monthly' },
   'student-annual': { planType: 'student', period: 'annual' },
+  group_professional: { planType: 'group', period: 'annual' },
+  group_professional_educational: { planType: 'group', period: 'annual' },
+  group_collaborator: { planType: 'group', period: 'annual' },
+  group_collaborator_educational: { planType: 'group', period: 'annual' },
 }
 
 /**
  *
  * @param {RecurlyPlanCode} recurlyPlanCode
- * @returns {{ planType: 'standard' | 'professional' | 'student', period: 'annual' | 'monthly'}}
+ * @returns {{ planType: 'individual' | 'group' | 'student', period: 'annual' | 'monthly'}}
  */
 function getPlanTypeAndPeriodFromRecurlyPlanCode(recurlyPlanCode) {
   return recurlyPlanCodeToPlanTypeAndPeriod[recurlyPlanCode]

+ 6 - 6
services/web/test/unit/src/Subscription/PlansLocatorTests.js

@@ -120,7 +120,7 @@ describe('PlansLocator', function () {
         this.PlansLocator.getPlanTypeAndPeriodFromRecurlyPlanCode(
           'collaborator'
         )
-      expect(planType).to.equal('standard')
+      expect(planType).to.equal('individual')
       expect(period).to.equal('monthly')
     })
 
@@ -129,7 +129,7 @@ describe('PlansLocator', function () {
         this.PlansLocator.getPlanTypeAndPeriodFromRecurlyPlanCode(
           'collaborator_free_trial_7_days'
         )
-      expect(planType).to.equal('standard')
+      expect(planType).to.equal('individual')
       expect(period).to.equal('monthly')
     })
 
@@ -138,7 +138,7 @@ describe('PlansLocator', function () {
         this.PlansLocator.getPlanTypeAndPeriodFromRecurlyPlanCode(
           'collaborator-annual'
         )
-      expect(planType).to.equal('standard')
+      expect(planType).to.equal('individual')
       expect(period).to.equal('annual')
     })
 
@@ -147,7 +147,7 @@ describe('PlansLocator', function () {
         this.PlansLocator.getPlanTypeAndPeriodFromRecurlyPlanCode(
           'professional'
         )
-      expect(planType).to.equal('professional')
+      expect(planType).to.equal('individual')
       expect(period).to.equal('monthly')
     })
 
@@ -156,7 +156,7 @@ describe('PlansLocator', function () {
         this.PlansLocator.getPlanTypeAndPeriodFromRecurlyPlanCode(
           'professional_free_trial_7_days'
         )
-      expect(planType).to.equal('professional')
+      expect(planType).to.equal('individual')
       expect(period).to.equal('monthly')
     })
 
@@ -165,7 +165,7 @@ describe('PlansLocator', function () {
         this.PlansLocator.getPlanTypeAndPeriodFromRecurlyPlanCode(
           'professional-annual'
         )
-      expect(planType).to.equal('professional')
+      expect(planType).to.equal('individual')
       expect(period).to.equal('annual')
     })
 

+ 10 - 2
services/web/types/subscription/plan.ts

@@ -81,11 +81,19 @@ export type RecurlyPlanCode =
   | 'student'
   | 'student-annual'
   | 'student_free_trial_7_days'
+  | 'group_professional'
+  | 'group_professional_educational'
+  | 'group_collaborator'
+  | 'group_collaborator_educational'
 
 export type StripeLookupKey =
-  | 'collaborator_monthly'
-  | 'collaborator_annual'
+  | 'standard_monthly'
+  | 'standard_annual'
   | 'professional_monthly'
   | 'professional_annual'
   | 'student_monthly'
   | 'student_annual'
+  | 'group_standard_enterprise'
+  | 'group_professional_enterprise'
+  | 'group_standard_educational'
+  | 'group_professional_educational'