From cd9b92d2981810e7c139bbd60f89b38837cf3f83 Mon Sep 17 00:00:00 2001 From: Wilco Waaijer Date: Mon, 11 Nov 2019 21:29:39 +0100 Subject: [PATCH] Added stripe.webhooks.generateTestHeaderString (#40292) --- types/stripe/index.d.ts | 32 ++++++++++++++++++++++++++++++++ types/stripe/stripe-tests.ts | 5 +++++ 2 files changed, 37 insertions(+) diff --git a/types/stripe/index.d.ts b/types/stripe/index.d.ts index d259b19b05..892b51a07a 100644 --- a/types/stripe/index.d.ts +++ b/types/stripe/index.d.ts @@ -13888,6 +13888,38 @@ declare namespace Stripe { endpointSecret: string, tolerance?: number, ): events.IEvent; + + /** + * Generates a header to be used for webhook mocking + */ + generateTestHeaderString(options: IWebHookGenerateTestHeaderStringOptions): string; + } + + interface IWebHookGenerateTestHeaderStringOptions { + /** + * Timestamp of the header. Defaults to Date.now() + */ + timestamp?: number; + + /** + * JSON stringified payload object, containing the 'id' and 'object' parameters + */ + payload?: string; + + /** + * Stripe webhook secret 'whsec_...' + */ + secret?: string; + + /** + * Version of API to hit. Defaults to 'v1'. + */ + scheme?: string; + + /** + * Computed webhook signature + */ + signature?: string; } class EphemeralKeys { diff --git a/types/stripe/stripe-tests.ts b/types/stripe/stripe-tests.ts index b042211534..e5bd2d5f99 100644 --- a/types/stripe/stripe-tests.ts +++ b/types/stripe/stripe-tests.ts @@ -1488,6 +1488,11 @@ const event: Stripe.events.IEvent = stripe.webhooks.constructEvent( webhookSecret, ); +const header: string = stripe.webhooks.generateTestHeaderString({ + payload: JSON.stringify(event), + secret: webhookSecret, +}); + //#endregion //#region Coupons tests