mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -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:
parent
73982ab4ff
commit
aa228e9eb9
1 changed files with 10 additions and 8 deletions
|
@ -373,18 +373,20 @@ module.exports = function MembersApi({
|
||||||
});
|
});
|
||||||
let member = await users.get({email: customer.email});
|
let member = await users.get({email: customer.email});
|
||||||
if (!member) {
|
if (!member) {
|
||||||
const metadata = event.data.object.metadata;
|
const metadataName = _.get(event, 'data.object.metadata.name');
|
||||||
const name = (metadata && 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});
|
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);
|
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';
|
const emailType = 'signup';
|
||||||
await sendEmailWithMagicLink({email: customer.email, requestedType: emailType, options: {forceEmailType: true}});
|
await sendEmailWithMagicLink({email: customer.email, requestedType: emailType, options: {forceEmailType: true}});
|
||||||
} else if (event.data.object.mode === 'payment') {
|
} else if (event.data.object.mode === 'payment') {
|
||||||
|
|
Loading…
Add table
Reference in a new issue