Ver Fonte

[web] add support for previewing base plan changes for Stripe (#25619)

GitOrigin-RevId: 458eeac52bc5fc010b9749f6fcd48350aa792582
Kristina há 1 ano atrás
pai
commit
dbb528762e

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

@@ -468,6 +468,7 @@ async function previewSubscription(req, res, next) {
   if (!planCode) {
     return HttpErrorHandler.notFound(req, res, 'Missing plan code')
   }
+  // TODO: use PaymentService to fetch plan information
   const plan = await RecurlyClient.promises.getPlan(planCode)
   const userId = SessionManager.getLoggedInUserId(req.session)
   const subscriptionChange =
@@ -475,14 +476,17 @@ async function previewSubscription(req, res, next) {
       userId,
       planCode
     )
-  const paymentMethod = await RecurlyClient.promises.getPaymentMethod(userId)
+  const paymentMethod = await Modules.promises.hooks.fire(
+    'getPaymentMethod',
+    userId
+  )
   const changePreview = makeChangePreview(
     {
       type: 'premium-subscription',
       plan: { code: plan.code, name: plan.name },
     },
     subscriptionChange,
-    paymentMethod
+    paymentMethod[0]
   )
 
   res.render('subscriptions/preview-change', { changePreview })

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

@@ -73,11 +73,12 @@ async function createSubscription(user, subscriptionDetails, recurlyTokenIds) {
  * @return {Promise<PaymentProviderSubscriptionChange>}
  */
 async function previewSubscriptionChange(userId, planCode) {
-  const subscription = await getSubscriptionForUser(userId)
-  const changeRequest = subscription?.getRequestForPlanChange(planCode)
-  const change =
-    await RecurlyClient.promises.previewSubscriptionChange(changeRequest)
-  return change
+  const change = await Modules.promises.hooks.fire(
+    'previewSubscriptionChange',
+    userId,
+    planCode
+  )
+  return change[0]
 }
 
 /**