Merge pull request #2609 from overleaf/ta-cmg-recurly-email-update

Add UI to Update Recurly Email

GitOrigin-RevId: 920a741fd9b4312f031bdd40e3d6bec48f1bd579
This commit is contained in:
Timothée Alby
2020-02-21 04:21:12 +00:00
committed by Copybot
parent 506543d6a0
commit f5e2983a6b
12 changed files with 213 additions and 6 deletions
@@ -574,6 +574,27 @@ module.exports = RecurlyWrapper = {
)
},
updateAccountEmailAddress(accountId, newEmail, callback) {
const data = {
email: newEmail
}
const requestBody = RecurlyWrapper._buildXml('account', data)
RecurlyWrapper.apiRequest(
{
url: `accounts/${accountId}`,
method: 'PUT',
body: requestBody
},
(error, response, body) => {
if (error != null) {
return callback(error)
}
RecurlyWrapper._parseAccountXml(body, callback)
}
)
},
getAccountActiveCoupons(accountId, callback) {
return RecurlyWrapper.apiRequest(
{
@@ -326,6 +326,18 @@ module.exports = SubscriptionController = {
)
},
updateAccountEmailAddress(req, res, next) {
const user = AuthenticationController.getSessionUser(req)
RecurlyWrapper.updateAccountEmailAddress(user._id, user.email, function(
error
) {
if (error) {
return next(new HttpErrors.InternalServerError({}).withCause(error))
}
res.sendStatus(200)
})
},
reactivateSubscription(req, res, next) {
const user = AuthenticationController.getSessionUser(req)
logger.log({ user_id: user._id }, 'reactivating subscription')
@@ -127,6 +127,12 @@ module.exports = {
SubscriptionController.processUpgradeToAnnualPlan
)
webRouter.post(
'/user/subscription/account/email',
AuthenticationController.requireLogin(),
SubscriptionController.updateAccountEmailAddress
)
// Currently used in acceptance tests only, as a way to trigger the syncing logic
return publicApiRouter.post(
'/user/:user_id/features/sync',
@@ -223,7 +223,8 @@ module.exports = {
: undefined
),
trial_ends_at: recurlySubscription.trial_ends_at,
activeCoupons: recurlyCoupons
activeCoupons: recurlyCoupons,
account: recurlySubscription.account
}
}