-
Notifications
You must be signed in to change notification settings - Fork 882
Description
Is your feature request related to a problem? Please describe.
In some scenarios for me (normally when using Stripe Connect), we don't have enough information to create a Stripe instance until we have parsed the webhook event.
Specifically, we may need the Event.account property to determine what credentials/API key to use to create a Stripe instance.
However, the Stripe.Webhooks utility is only available after creating a Stripe instance.
Describe the solution you'd like
After inspecting the code, it seems the webhook utilities instance does not depend at all on a specific Stripe instance.
Lines 70 to 72 in 12fe437
| export function createWebhooks( | |
| platformFunctions: PlatformFunctions | |
| ): WebhookObject { |
This webhook utilites instance could be made available as a static property on the Stripe constructor, and that instance also shared on the individual instances.
Like so:
const Stripe = require('stripe');
// Available as a static property
Stripe.webhooks.constructEventAsync(...);
// Remains available on the instance also
const client = Stripe('...');
client.webhooks === Stripe.webhooks // trueHappy to help with a PR if you agree with the logic.
Describe alternatives you've considered
A workaround is using new Stripe('').webhooks to get an instance of the webhook utilities, but it feels like a hack, because it relies on the internal workings of the Stripe() constructor not attempting to validate the empty API key.
Additional context
No response