Skip to content

Make webhooks utilities available as a static property #1956

@brettwillis

Description

@brettwillis

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.

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 // true

Happy 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions