From b263fdcda8ad7c71164fa2f8afb5ea3a376601a6 Mon Sep 17 00:00:00 2001 From: jasonvideoblocks Date: Wed, 29 Jan 2020 16:51:33 -0500 Subject: [PATCH] [braintree] Move webhook notifications to their own types (#41922) * Adds account updater webhook fields * Create WebhookNotification subclasses * Use x as T syntax --- types/braintree/braintree-tests.ts | 6 +++--- types/braintree/index.d.ts | 31 +++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/types/braintree/braintree-tests.ts b/types/braintree/braintree-tests.ts index 2de2377a94..939c59cbbb 100644 --- a/types/braintree/braintree-tests.ts +++ b/types/braintree/braintree-tests.ts @@ -14,9 +14,8 @@ import { PaymentMethod, PaymentMethodNonce, Transaction, - SampleNotification, - WebhookNotification, WebhookNotificationKind, + SubscriptionNotification, } from 'braintree'; /** @@ -109,5 +108,6 @@ const gateway: BraintreeGateway = new braintree.BraintreeGateway({ const notificationResponse = await gateway.webhookNotification.parse(sampleResponse.bt_signature, sampleResponse.bt_payload).catch(console.error); if (!notificationResponse) return; - const notification: WebhookNotification = notificationResponse; + const notification: SubscriptionNotification = notificationResponse as SubscriptionNotification; + const subscription = notification.subscription; })(); diff --git a/types/braintree/index.d.ts b/types/braintree/index.d.ts index 456c2856ba..d4b682fc4b 100644 --- a/types/braintree/index.d.ts +++ b/types/braintree/index.d.ts @@ -836,13 +836,34 @@ declare namespace braintree { bt_payload: string; } - export class WebhookNotification { + export abstract class WebhookNotification { kind: WebhookNotificationKind; timestamp: Date; - subscription?: Subscription; - merchantAccount?: MerchantAccount; - transaction?: Transaction; - dispute?: Dispute; + } + + export class TransactionNotification extends WebhookNotification { + transaction: Transaction; + } + + export class SubMerchantAccountApprovedNotification extends WebhookNotification { + merchantAccount: MerchantAccount; + } + + export class SubMerchantAccountDeclinedNotification extends WebhookNotification { + merchantAccount: MerchantAccount; + } + + export class SubscriptionNotification extends WebhookNotification { + subscription: Subscription; + } + + export class DisputeNotification extends WebhookNotification { + dispute: Dispute; + } + + export class AccountUpdaterNotification extends WebhookNotification { + reportDate: Date; + reportUrl: string; } export type WebhookNotificationKind =