nestjs
nestjs copied to clipboard
Multiple stripe webhooks
Is it possible to set this up to work with two different webhook endpoints? (I need one for connect accounts & one for direct accounts.)
You can setup stripe with one webhook url and use mulitple @StripeWebhookHandler with different events
@CarsonF That's what I was doing initially but then I needed to create a webhook that used stripe connect (stripe sends different events to direct vs connect webhooks).
I think I can create the 2nd webhook to hit the same endpoint, but the webhook secret will be different, so that won't work.
Ahh my bad you're right.
I think you could configure the module twice with a different controller prefix. The decorator uses their discovery library which I believe is global, so both modules would find all handlers. Each webhook controller though would use its own signing secret verification first. Worth a shot.
I'd definitely try out the suggestion provided by @CarsonF first and see if it works out for you. In a future version we might be able to provide support for multiple configurations with some kind of name value that allows you to correlate webhook handlers to only be linked to the specific signing secret that matters for them.
Are there any major differences between connect accounts and direct accounts other than the signing secret?
Are there any major differences between connect accounts and direct accounts other than the signing secret?
I think that's the only difference as far as I understand.
I tried multiple setups of two webhook endpoints - two separate modules, two configurations in one module. Unfotunately nothing worked. The issues I encounted during my testing where:
- Basically, one of the configurations didn't expose endpoint at all. It kept returning 404 in Stripe dashboard.
- The other endpoint was established but returned an error
No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe
Once I removed any one of them and kept just one, it started to work perfectly.
Is there any other way to handle two webhook secrets? I'll have to switch to some custom endpoint otherwise :(
As a last resort you could probably monkey patch it:
StripePayloadService.prototype.tryHydratePayload = function (
signature: string,
payload: Buffer
) {
const decodedPayload = JSON.parse(
Buffer.isBuffer(payload) ? payload.toString('utf8') : payload
);
return this.stripeClient.webhooks.constructEvent(
payload,
signature,
decodedPayload.account
? stripeWebhookConnectSecret
: stripeWebhookDirectSecret
);
};
This is really a need, Direct and Connect hooks should be processed in different endpoints. I use Direct for my business webhooks, subscription start, end, upgrade etc. Connect is for people who have connected their stripe accounts so we can get updates from their accounts.
I'm happy to collaborate on implementing that, if you can guide me over
@underfisk can we have a release on #522 ?
@underfisk can we have a release on #522 ?
I don't have permissions to do that, only @WonderPanda