Updated stripe checkout to store member name from metadata

refs TryGhost/members.js#29

- Uses the metadata option in stripe checkout flow to add member's name on creation via anonymous checkout flow
- Allows clients like memebrs.js to pass member's info like name from checkout signup flow
This commit is contained in:
Rish 2020-05-19 13:50:40 +05:30 committed by Rishabh Garg
parent 2f90c97629
commit 167811c5fd

View File

@ -301,8 +301,12 @@ module.exports = function MembersApi({
const customer = await stripe.getCustomer(event.data.object.customer, { const customer = await stripe.getCustomer(event.data.object.customer, {
expand: ['subscriptions.data.default_payment_method'] expand: ['subscriptions.data.default_payment_method']
}); });
let member = await users.get({email: customer.email});
const member = await users.get({email: customer.email}) || await users.create({email: customer.email}); if (!member) {
const metadata = event.data.object.metadata;
const name = (metadata && metadata.name) || '';
member = await users.create({email: customer.email, name});
}
await stripe.handleCheckoutSessionCompletedWebhook(member, customer); await stripe.handleCheckoutSessionCompletedWebhook(member, customer);
const payerName = _.get(customer, 'subscriptions.data[0].default_payment_method.billing_details.name'); const payerName = _.get(customer, 'subscriptions.data[0].default_payment_method.billing_details.name');