2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00

Improved handling of Stripe webhooks on boot

no-issue

This version of members-api includes changes to how webhooks are
managed, previously they would be deleted and recreated on every boot of
Ghost. Now they are created and the secret is persisted, on boot the
webhook is updated to the most current url and events. If the api
version is wrong or the update fails, the webhook is deleted and
recreated and the settings updated.

 - Installed @tryghost/members-api@0.24.0
 - Updated config to work with 0.24.0
This commit is contained in:
Fabien O'Carroll 2020-07-09 16:17:54 +02:00 committed by Fabien 'egg' O'Carroll
parent 20a95de8f7
commit 832ecad43b
4 changed files with 29 additions and 8 deletions

View file

@ -144,9 +144,26 @@ function createApiInstance(config) {
paymentConfig: {
stripe: config.getStripePaymentConfig()
},
memberStripeCustomerModel: models.MemberStripeCustomer,
stripeCustomerSubscriptionModel: models.StripeCustomerSubscription,
memberModel: models.Member,
models: {
/**
* Settings do not have their own models, so we wrap the webhook in a "fake" model
*/
StripeWebhook: {
async upsert(data, options) {
const settings = [{
key: 'members_stripe_webhook_id',
value: data.webhook_id
}, {
key: 'members_stripe_webhook_secret',
value: data.secret
}];
await models.Settings.edit(settings, options);
}
},
StripeCustomer: models.MemberStripeCustomer,
StripeCustomerSubscription: models.StripeCustomerSubscription,
Member: models.Member
},
logger: logging
});

View file

@ -174,6 +174,10 @@ class MembersConfigProvider {
billingSuccessUrl: urls.billingSuccess,
billingCancelUrl: urls.billingCancel,
webhookHandlerUrl: urls.webhookHandler,
webhook: {
id: this._settingsCache.get('members_stripe_webhook_id'),
secret: this._settingsCache.get('members_stripe_webhook_secret')
},
product: {
name: this._settingsCache.get('stripe_product_name')
},

View file

@ -52,7 +52,7 @@
"@tryghost/kg-markdown-html-renderer": "2.0.1",
"@tryghost/kg-mobiledoc-html-renderer": "3.0.1",
"@tryghost/magic-link": "0.4.10",
"@tryghost/members-api": "0.23.2",
"@tryghost/members-api": "0.24.0",
"@tryghost/members-csv": "0.2.1",
"@tryghost/members-ssr": "0.8.2",
"@tryghost/mw-session-from-token": "0.1.5",

View file

@ -486,10 +486,10 @@
jsonwebtoken "^8.5.1"
lodash "^4.17.15"
"@tryghost/members-api@0.23.2":
version "0.23.2"
resolved "https://registry.npmjs.org/@tryghost/members-api/-/members-api-0.23.2.tgz#a4c644e175d4ede7cec2797c75f822b1f801f8bc"
integrity sha512-/1r7/gg7xPHeEikt5FwXx1zmwK3pdqBsCk55Nc0W+TRZznAvKSGuUMNx3mpdQpSf6ry7/0E8RyEaC5p521W6iQ==
"@tryghost/members-api@0.24.0":
version "0.24.0"
resolved "https://registry.yarnpkg.com/@tryghost/members-api/-/members-api-0.24.0.tgz#d4f07ec52e6a93f5563e26e1c2d083fb69fb2da1"
integrity sha512-2jIl02vDdT9iphsTiQB2mmLANZ7UVmZB50xPuGIL9b8YEE4vddHHR8yPoW97TdSqHOMFIQ7CZPyOJjxQ5gFqUA==
dependencies:
"@tryghost/magic-link" "^0.4.10"
bluebird "^3.5.4"