0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-18 02:21:47 -05:00

Removed magic link email for upgrade checkout

no issue

Previously, we were sending a magic link email to signup in case a logged-in member upgrades to a paid account, as we didn't check for logged in status while sending the magic link and always sent one on finishing checkout. Since Portal allows members to upgrade their account from free, it doesn't make sense to send another email to signup after completing checkout.

The fix here adds a metadata `checkoutType` to checkout session creation which can be passed in with `upgrade` value to denote an existing member is upgrading and doesn't need an email.
This commit is contained in:
Rish 2020-10-28 18:06:04 +05:30 committed by Rishabh Garg
parent accc2347e8
commit 6ccdea6632

View file

@ -388,6 +388,7 @@ module.exports = function MembersApi({
expand: ['subscriptions.data.default_payment_method']
});
let member = await users.get({email: customer.email});
const checkoutType = _.get(event, 'data.object.metadata.checkoutType');
if (!member) {
const metadataName = _.get(event, 'data.object.metadata.name');
const payerName = _.get(customer, 'subscriptions.data[0].default_payment_method.billing_details.name');
@ -402,9 +403,10 @@ module.exports = function MembersApi({
}
await stripe.handleCheckoutSessionCompletedWebhook(member, customer);
const emailType = 'signup';
await sendEmailWithMagicLink({email: customer.email, requestedType: emailType, options: {forceEmailType: true}});
if (checkoutType !== 'upgrade') {
const emailType = 'signup';
await sendEmailWithMagicLink({email: customer.email, requestedType: emailType, requestSrc, options: {forceEmailType: true}, tokenData: {}});
}
} else if (event.data.object.mode === 'payment') {
common.logging.info('Ignoring "payment" mode Checkout Session');
}