From 6ccdea663224473246fa10ad610ca90f035ee507 Mon Sep 17 00:00:00 2001 From: Rish Date: Wed, 28 Oct 2020 18:06:04 +0530 Subject: [PATCH] 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. --- ghost/members-api/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ghost/members-api/index.js b/ghost/members-api/index.js index 750f7b9587..7de37d32c9 100644 --- a/ghost/members-api/index.js +++ b/ghost/members-api/index.js @@ -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'); }