stripe-node updated typings for webhook verification (#20382)

* Added stripe-node typings for webhook verification

- See example on the stripe-node github for webhook signing here: https://github.com/stripe/stripe-node/tree/master/examples/webhook-signing

* Updated stripe-node types version
This commit is contained in:
Sampson Oliver
2017-10-12 20:23:28 +11:00
committed by Wesley Wigham
parent 972e5154d8
commit 2cdb812a31
2 changed files with 44 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
// Type definitions for stripe-node 4.6.0
// Type definitions for stripe-node 4.7.0
// Project: https://github.com/stripe/stripe-node/
// Definitions by: William Johnston <https://github.com/wjohnsto>, Peter Harris <https://github.com/codeanimal>
// Definitions by: William Johnston <https://github.com/wjohnsto>, Peter Harris <https://github.com/codeanimal>, Sampson Oliver <https://github.com/sampsonjoliver>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
@@ -71,7 +71,8 @@ declare namespace StripeNode {
orders: resources.Orders;
products: resources.Products;
skus: resources.SKUs;
webhooks: resources.WebHooks;
setHost(host: string): void;
setHost(host: string, port: string|number): void;
setHost(host: string, port: string|number, protocol: string): void;
@@ -3128,6 +3129,25 @@ declare namespace StripeNode {
interface ISkuAttributes {}
}
namespace webhooks {
interface StripeWebhookEvent<T> {
id: string;
object: string;
api_version: string;
created: Date;
data: {
object: T;
};
livemode: boolean;
pending_webhooks: number;
/**
* One of https://stripe.com/docs/api#event_types
* E.g. account.updated
*/
type: string;
}
}
namespace tokens {
interface IToken extends ICardToken, IBankAccountToken { }
@@ -6273,6 +6293,10 @@ declare namespace StripeNode {
del(skuId: string, options: HeaderOptions, response?: IResponseFn<IDeleteConfirmation>): Promise<IDeleteConfirmation>;
del(skuId: string, response?: IResponseFn<IDeleteConfirmation>): Promise<IDeleteConfirmation>;
}
class WebHooks {
constructEvent<T>(requestBody: any, signature: string | string[], endpointSecret: string): webhooks.StripeWebhookEvent<T>;
}
}
interface IObject {

View File

@@ -701,6 +701,23 @@ stripe.accounts.createExternalAccount("", { external_account: "tok_15V2YhEe31JkL
//#endregion
//#region WebHooks tests
// ##################################################################################
const webhookRequest = {
rawBody: '',
headers: { 'stripe-signature': '' }
};
const webhookSecret = '';
const event = stripe.webhooks.constructEvent<StripeNode.subscriptions.ISubscription>(
webhookRequest.rawBody,
webhookRequest.headers['stripe-signature'],
webhookSecret
);
//#endregion
//#region Coupons tests