0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Updated stripe to create webhook on boot configure

no-issue

This will allow us to a) have an endpoint to receive webhooks and b) get
hold of the webhook secret to validate the signature.
This commit is contained in:
Fabien O'Carroll 2019-09-24 17:20:59 +07:00
parent 4dc42709c3
commit 343fcecfff

View file

@ -19,21 +19,30 @@ module.exports = class StripePaymentProcessor {
this._public_token = config.publicKey;
this._checkoutSuccessUrl = config.checkoutSuccessUrl;
this._checkoutCancelUrl = config.checkoutCancelUrl;
this._webhookHandlerUrl = config.webhookHandlerUrl;
try {
this._product = await api.products.ensure(this._stripe, config.product);
} catch (err) {
return this._rejectReady(err);
}
this._plans = [];
for (const planSpec of config.plans) {
try {
this._plans = [];
for (const planSpec of config.plans) {
const plan = await api.plans.ensure(this._stripe, planSpec, this._product);
this._plans.push(plan);
} catch (err) {
return this._rejectReady(err);
}
try {
// @TODO Need to somehow not duplicate this every time we boot
const webhook = await create(this._stripe, 'webhookEndpoints', {
url: this._webhookHandlerUrl,
enabled_events: ['checkout.session.completed']
});
this._webhookSecret = webhook.secret;
} catch (err) {
console.log(err);
this._webhookSecret = process.env.WEBHOOK_SECRET;
}
} catch (err) {
return this._rejectReady(err);
}
return this._resolveReady({