Răsfoiți Sursa

Merge pull request #24833 from overleaf/kh-add-stripe-get-subscription

[web] fetch Stripe subscription

GitOrigin-RevId: bffc31224aece584f4f1e3294bb1285d17f99195
M Fahru 1 an în urmă
părinte
comite
a29280a1fe

+ 18 - 0
services/web/app/src/Features/Subscription/PlansLocator.js

@@ -36,6 +36,15 @@ const recurlyPlanCodeToStripeLookupKey = {
   student_free_trial_7_days: 'student_monthly',
   student_free_trial_7_days: 'student_monthly',
 }
 }
 
 
+const stripeLookupKeyToRecurlyPlanCode = {
+  professional_annual: 'professional-annual',
+  professional_monthly: 'professional',
+  standard_annual: 'collaborator-annual',
+  standard_monthly: 'collaborator',
+  student_annual: 'student-annual',
+  student_monthly: 'student',
+}
+
 /**
 /**
  *
  *
  * @param {RecurlyPlanCode} recurlyPlanCode
  * @param {RecurlyPlanCode} recurlyPlanCode
@@ -45,6 +54,14 @@ function mapRecurlyPlanCodeToStripeLookupKey(recurlyPlanCode) {
   return recurlyPlanCodeToStripeLookupKey[recurlyPlanCode]
   return recurlyPlanCodeToStripeLookupKey[recurlyPlanCode]
 }
 }
 
 
+/**
+ * @param {StripeLookupKey} stripeLookupKey
+ * @returns {RecurlyPlanCode}
+ */
+function mapStripeLookupKeyToRecurlyPlanCode(stripeLookupKey) {
+  return stripeLookupKeyToRecurlyPlanCode[stripeLookupKey]
+}
+
 const recurlyPlanCodeToPlanTypeAndPeriod = {
 const recurlyPlanCodeToPlanTypeAndPeriod = {
   collaborator: { planType: 'standard', period: 'monthly' },
   collaborator: { planType: 'standard', period: 'monthly' },
   collaborator_free_trial_7_days: { planType: 'standard', period: 'monthly' },
   collaborator_free_trial_7_days: { planType: 'standard', period: 'monthly' },
@@ -82,5 +99,6 @@ module.exports = {
   ensurePlansAreSetupCorrectly,
   ensurePlansAreSetupCorrectly,
   findLocalPlanInSettings,
   findLocalPlanInSettings,
   mapRecurlyPlanCodeToStripeLookupKey,
   mapRecurlyPlanCodeToStripeLookupKey,
+  mapStripeLookupKeyToRecurlyPlanCode,
   getPlanTypeAndPeriodFromRecurlyPlanCode,
   getPlanTypeAndPeriodFromRecurlyPlanCode,
 }
 }

+ 4 - 0
services/web/app/src/Features/Subscription/SubscriptionViewModelBuilder.js

@@ -260,6 +260,10 @@ async function buildUsersSubscriptionViewModel(user, locale = 'en') {
   }
   }
 
 
   if (personalSubscription && paymentRecord && paymentRecord.subscription) {
   if (personalSubscription && paymentRecord && paymentRecord.subscription) {
+    // don't return subscription payment information
+    delete personalSubscription.paymentProvider
+    delete personalSubscription.recurly
+
     const tax = paymentRecord.subscription.taxAmount || 0
     const tax = paymentRecord.subscription.taxAmount || 0
     // Some plans allow adding more seats than the base plan provides.
     // Some plans allow adding more seats than the base plan provides.
     // This is recorded as a subscription add on.
     // This is recorded as a subscription add on.

+ 1 - 0
services/web/test/acceptance/src/helpers/Subscription.mjs

@@ -25,6 +25,7 @@ class PromisifiedSubscription {
     this.ssoConfig = options.ssoConfig
     this.ssoConfig = options.ssoConfig
     this.groupPolicy = options.groupPolicy
     this.groupPolicy = options.groupPolicy
     this.addOns = options.addOns
     this.addOns = options.addOns
+    this.paymentProvider = options.paymentProvider
   }
   }
 
 
   async ensureExists() {
   async ensureExists() {

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

@@ -114,6 +114,22 @@ describe('PlansLocator', function () {
     })
     })
   })
   })
 
 
+  describe('mapStripeLookupKeyToRecurlyPlanCode', function () {
+    it('should return the recurly plan code for existing plans', function () {
+      const planCode = 'standard_monthly'
+      const lookupKey =
+        this.PlansLocator.mapStripeLookupKeyToRecurlyPlanCode(planCode)
+      expect(lookupKey).to.equal('collaborator')
+    })
+
+    it('should return undefined for unknown plans', function () {
+      const planCode = 'foobar'
+      const lookupKey =
+        this.PlansLocator.mapStripeLookupKeyToRecurlyPlanCode(planCode)
+      expect(lookupKey).to.equal(undefined)
+    })
+  })
+
   describe('getPlanTypeAndPeriodFromRecurlyPlanCode', function () {
   describe('getPlanTypeAndPeriodFromRecurlyPlanCode', function () {
     it('should return the plan type and period for "collaborator"', function () {
     it('should return the plan type and period for "collaborator"', function () {
       const { planType, period } =
       const { planType, period } =