Bladeren bron

Merge pull request #25732 from overleaf/kh-stripe-preview-addon-purchase

[web] add support for previewing add-on changes for Stripe

GitOrigin-RevId: 46e7d0b96bf0935a4a3afcaf03d7a6f3c26d2108
Kristina 1 jaar geleden
bovenliggende
commit
8e6d1d5f07

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

@@ -38,6 +38,8 @@ const recurlyPlanCodeToStripeLookupKey = {
   group_professional_educational: 'group_professional_educational',
   group_collaborator: 'group_standard_enterprise',
   group_collaborator_educational: 'group_standard_educational',
+  assistant_annual: 'error_assist_annual',
+  assistant: 'error_assist_monthly',
 }
 
 /**

+ 7 - 2
services/web/app/src/Features/Subscription/SubscriptionController.js

@@ -335,7 +335,11 @@ async function previewAddonPurchase(req, res) {
     return HttpErrorHandler.notFound(req, res, `Unknown add-on: ${addOnCode}`)
   }
 
-  const paymentMethod = await RecurlyClient.promises.getPaymentMethod(userId)
+  /** @type {PaymentMethod[]} */
+  const paymentMethod = await Modules.promises.hooks.fire(
+    'getPaymentMethod',
+    userId
+  )
 
   let subscriptionChange
   try {
@@ -376,7 +380,7 @@ async function previewAddonPurchase(req, res) {
       },
     },
     subscriptionChange,
-    paymentMethod
+    paymentMethod[0]
   )
 
   await SplitTestHandler.promises.getAssignment(
@@ -482,6 +486,7 @@ async function previewSubscription(req, res, next) {
       userId,
       planCode
     )
+  /** @type {PaymentMethod[]} */
   const paymentMethod = await Modules.promises.hooks.fire(
     'getPaymentMethod',
     userId

+ 6 - 18
services/web/app/src/Features/Subscription/SubscriptionHandler.js

@@ -262,24 +262,12 @@ async function extendTrial(subscription, daysToExend) {
  * @return {Promise<PaymentProviderSubscriptionChange>}
  */
 async function previewAddonPurchase(userId, addOnCode) {
-  const subscription = await getSubscriptionForUser(userId)
-
-  try {
-    await RecurlyClient.promises.getAddOn(subscription.planCode, addOnCode)
-  } catch (err) {
-    if (err instanceof recurly.errors.NotFoundError) {
-      throw new NotFoundError({
-        message: 'Add-on not found',
-        info: { addOnCode },
-      })
-    }
-    throw err
-  }
-
-  const changeRequest = subscription.getRequestForAddOnPurchase(addOnCode)
-  const change =
-    await RecurlyClient.promises.previewSubscriptionChange(changeRequest)
-  return change
+  const change = await Modules.promises.hooks.fire(
+    'previewAddOnPurchase',
+    userId,
+    addOnCode
+  )
+  return change[0]
 }
 
 /**