mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-01 21:31:36 +02:00
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:
@@ -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',
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user