[braintree] Move webhook notifications to their own types (#41922)

* Adds account updater webhook fields

* Create WebhookNotification subclasses

* Use x as T syntax
This commit is contained in:
jasonvideoblocks
2020-01-29 13:51:33 -08:00
committed by GitHub
parent fa411e40a2
commit b263fdcda8
2 changed files with 29 additions and 8 deletions
+3 -3
View File
@@ -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;
})();
+26 -5
View File
@@ -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 =