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
}
}
@@ -1,6 +1,7 @@
if (personalSubscription.recurly)
include ./_personal_subscription_recurly
include ./_personal_subscription_recurly_sync_email
else
include ./_personal_subscription_custom
hr
hr
@@ -0,0 +1,18 @@
-if (user.email !== personalSubscription.recurly.account.email)
div
hr
form(async-form="updateAccountEmailAddress", name="updateAccountEmailAddress", action='/user/subscription/account/email', method="POST")
input(name='_csrf', type='hidden', value=csrfToken)
.form-group
form-messages(for="updateAccountEmailAddress")
.alert.alert-success(ng-show="updateAccountEmailAddress.response.success")
| #{translate('recurly_email_updated')}
div(ng-hide="updateAccountEmailAddress.response.success")
p !{translate("recurly_email_update_needed", { recurlyEmail: "<i>" + personalSubscription.recurly.account.email + "</i>", userEmail: "<i>" + user.email + "</i>" })}
.actions
button.btn-primary.btn(
type='submit',
ng-disabled="updateAccountEmailAddress.inflight"
)
span(ng-show="!updateAccountEmailAddress.inflight") #{translate("update")}
span(ng-show="updateAccountEmailAddress.inflight") #{translate("updating")}...