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

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

GitOrigin-RevId: 46e7d0b96bf0935a4a3afcaf03d7a6f3c26d2108
This commit is contained in:
Kristina
2025-05-21 11:45:29 +02:00
committed by Copybot
parent 56de4c02da
commit bd1a25dbae
3 changed files with 15 additions and 20 deletions

View File

@@ -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',
}
/**

View File

@@ -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

View File

@@ -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]
}
/**