0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Created member with name on checkout completion (#209)

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

Previously we would create the member, and then update their name from
stripe data, this mean that webhooks would be sent _without_ a name,
despite us possibly having the information to provide one.

Here we've updated the creation of members to include the name attached
to the default billing method, this will ensure that webhooks are sent
with all availiable information.
This commit is contained in:
Fabien 'egg' O'Carroll 2020-10-19 12:44:01 +01:00 committed by GitHub
parent 73982ab4ff
commit aa228e9eb9

View file

@ -373,18 +373,20 @@ module.exports = function MembersApi({
});
let member = await users.get({email: customer.email});
if (!member) {
const metadata = event.data.object.metadata;
const name = (metadata && metadata.name) || '';
const metadataName = _.get(event, 'data.object.metadata.name');
const payerName = _.get(customer, 'subscriptions.data[0].default_payment_method.billing_details.name');
const name = metadataName || payerName || null;
member = await users.create({email: customer.email, name});
} else {
const payerName = _.get(customer, 'subscriptions.data[0].default_payment_method.billing_details.name');
if (payerName && !member.get('name')) {
await users.update({name: payerName}, {id: member.get('id')});
}
}
await stripe.handleCheckoutSessionCompletedWebhook(member, customer);
const payerName = _.get(customer, 'subscriptions.data[0].default_payment_method.billing_details.name');
if (payerName && !member.get('name')) {
await users.update({name: payerName}, {id: member.get('id')});
}
const emailType = 'signup';
await sendEmailWithMagicLink({email: customer.email, requestedType: emailType, options: {forceEmailType: true}});
} else if (event.data.object.mode === 'payment') {