From dbb528762e8b283b66ed64a302510240396341a5 Mon Sep 17 00:00:00 2001 From: Kristina <7614497+khjrtbrg@users.noreply.github.com> Date: Mon, 19 May 2025 15:05:55 +0200 Subject: [PATCH] [web] add support for previewing base plan changes for Stripe (#25619) GitOrigin-RevId: 458eeac52bc5fc010b9749f6fcd48350aa792582 --- .../Features/Subscription/SubscriptionController.js | 8 ++++++-- .../src/Features/Subscription/SubscriptionHandler.js | 11 ++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/services/web/app/src/Features/Subscription/SubscriptionController.js b/services/web/app/src/Features/Subscription/SubscriptionController.js index fe23512901..be2f409b86 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionController.js +++ b/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 }) diff --git a/services/web/app/src/Features/Subscription/SubscriptionHandler.js b/services/web/app/src/Features/Subscription/SubscriptionHandler.js index ecf05695da..332aa0d8ca 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionHandler.js +++ b/services/web/app/src/Features/Subscription/SubscriptionHandler.js @@ -73,11 +73,12 @@ async function createSubscription(user, subscriptionDetails, recurlyTokenIds) { * @return {Promise} */ 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] } /**