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.
This commit is contained in:
Fabien O'Carroll 2021-09-07 16:34:08 +02:00
parent ae1f905766
commit 8476e7cbd7

View File

@ -168,6 +168,16 @@ module.exports = function MembersAPI({
logging: common.logging 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([ const ready = paymentConfig.stripe ? Promise.all([
stripeMigrations.populateProductsAndPrices().then(() => { stripeMigrations.populateProductsAndPrices().then(() => {
return stripeMigrations.populateStripePricesFromStripePlansSetting(stripeConfig.plans); return stripeMigrations.populateStripePricesFromStripePlansSetting(stripeConfig.plans);
@ -387,6 +397,7 @@ module.exports = function MembersAPI({
getMemberIdentityToken, getMemberIdentityToken,
getMemberIdentityData, getMemberIdentityData,
setMemberGeolocationFromIp, setMemberGeolocationFromIp,
disconnectStripe,
getPublicConfig, getPublicConfig,
bus, bus,
sendEmailWithMagicLink, sendEmailWithMagicLink,