From bd1a25dbaec0c7772e78c35ff3d4346b5a6e03ea Mon Sep 17 00:00:00 2001 From: Kristina <7614497+khjrtbrg@users.noreply.github.com> Date: Wed, 21 May 2025 11:45:29 +0200 Subject: [PATCH] Merge pull request #25732 from overleaf/kh-stripe-preview-addon-purchase [web] add support for previewing add-on changes for Stripe GitOrigin-RevId: 46e7d0b96bf0935a4a3afcaf03d7a6f3c26d2108 --- .../src/Features/Subscription/PlansLocator.js | 2 ++ .../Subscription/SubscriptionController.js | 9 +++++-- .../Subscription/SubscriptionHandler.js | 24 +++++-------------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/services/web/app/src/Features/Subscription/PlansLocator.js b/services/web/app/src/Features/Subscription/PlansLocator.js index a418e23b78..24343e1109 100644 --- a/services/web/app/src/Features/Subscription/PlansLocator.js +++ b/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', } /** diff --git a/services/web/app/src/Features/Subscription/SubscriptionController.js b/services/web/app/src/Features/Subscription/SubscriptionController.js index d0025c460b..9b2cec1398 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionController.js +++ b/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 diff --git a/services/web/app/src/Features/Subscription/SubscriptionHandler.js b/services/web/app/src/Features/Subscription/SubscriptionHandler.js index 332aa0d8ca..39a44f305f 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionHandler.js +++ b/services/web/app/src/Features/Subscription/SubscriptionHandler.js @@ -262,24 +262,12 @@ async function extendTrial(subscription, daysToExend) { * @return {Promise} */ 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] } /**