From 8476e7cbd7eeca2ab5409cf71340c8bdc582c757 Mon Sep 17 00:00:00 2001 From: Fabien O'Carroll Date: Tue, 7 Sep 2021 16:34:08 +0200 Subject: [PATCH] Added disconnectStripe method to handle cleaning up refs https://github.com/TryGhost/Team/issues/1006 As part of the work to handle cleaning up webhooks when we disconnect from Stripe, I'm moving the logic to clear out the Stripe related data from the database into a disconnectStripe method. This then allows us to start handling the cleanup of webhooks via the Stripe API. --- ghost/members-api/lib/MembersAPI.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ghost/members-api/lib/MembersAPI.js b/ghost/members-api/lib/MembersAPI.js index 0e366ce5c7..0270503663 100644 --- a/ghost/members-api/lib/MembersAPI.js +++ b/ghost/members-api/lib/MembersAPI.js @@ -168,6 +168,16 @@ module.exports = function MembersAPI({ logging: common.logging }); + async function disconnectStripe() { + await Product.forge().query().update({ + monthly_price_id: null, + yearly_price_id: null + }); + await StripePrice.forge().query().del(); + await StripeProduct.forge().query().del(); + await StripeCustomer.forge().query().del(); + } + const ready = paymentConfig.stripe ? Promise.all([ stripeMigrations.populateProductsAndPrices().then(() => { return stripeMigrations.populateStripePricesFromStripePlansSetting(stripeConfig.plans); @@ -387,6 +397,7 @@ module.exports = function MembersAPI({ getMemberIdentityToken, getMemberIdentityData, setMemberGeolocationFromIp, + disconnectStripe, getPublicConfig, bus, sendEmailWithMagicLink,