0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-01 02:41:39 -05:00

Updated customer when member email is changed

refs: https://github.com/TryGhost/Ghost/issues/12055

This ensures that newsletters and billing related emails are all sent to
the same address
This commit is contained in:
Fabien O'Carroll 2020-09-28 13:10:23 +01:00
parent b189584f98
commit f41f366b5a

View file

@ -29,7 +29,7 @@ module.exports = function ({
async function update(data, options) {
debug(`update id:${options.id}`);
return Member.edit(_.pick(data, [
const member = await Member.edit(_.pick(data, [
'email',
'name',
'note',
@ -37,6 +37,14 @@ module.exports = function ({
'labels',
'geolocation'
]), options);
if (member._changed.email) {
await member.related('stripeCustomers').fetch();
const customers = member.related('stripeCustomers');
for (const customer of customers.models) {
await stripe.updateStripeCustomerEmail(customer.get('customer_id'), member.get('email'));
}
}
return member;
}
async function list(options = {}) {