[braintree] Fix the type of the account updater webhook notification (#42348)

This commit is contained in:
jasonvideoblocks
2020-02-13 20:43:20 -05:00
committed by GitHub
parent 35f0b3bdf9
commit 8cbc83c0d1
2 changed files with 27 additions and 3 deletions

View File

@@ -123,9 +123,26 @@ const gateway: BraintreeGateway = new braintree.BraintreeGateway({
const notification = await gateway.webhookNotification.parse(sampleResponse.bt_signature, sampleResponse.bt_payload).catch(console.error);
if (!notification) return;
// this should cause the type of `notification` to be narrowed to `SubscriptionNotification`
// this should cause the type of `notification` to be narrowed to `PaymentMethodNotification`
if (notification.kind !== kind) return;
const metadata = notification.revokedPaymentMethodMetadata;
if (!metadata.revokedPaymentMethod) return;
})();
(async () => {
const kind: WebhookNotificationKind = 'account_updater_daily_report';
const subscriptionId = '123456';
const sampleResponse = await gateway.webhookTesting.sampleNotification(kind, subscriptionId).catch(console.error);
if (!sampleResponse) return;
const notification = await gateway.webhookNotification.parse(sampleResponse.bt_signature, sampleResponse.bt_payload).catch(console.error);
if (!notification) return;
// this should cause the type of `notification` to be narrowed to `AccountUpdaterNotification`
if (notification.kind !== kind) return;
const reportUrl = notification.accountUpdaterDailyReport.reportUrl;
if (!reportUrl) return;
})();

View File

@@ -827,6 +827,14 @@ declare namespace braintree {
| 'VisaCheckoutCard'
| 'SamsungPayCard';
/**
* Account Updater
*/
export class AccountUpdaterDailyReport {
reportDate: Date;
reportUrl: string;
}
/**
* Webhooks
*/
@@ -868,8 +876,7 @@ declare namespace braintree {
export interface AccountUpdaterNotification extends BaseWebhookNotification {
kind: AccountUpdaterNotificationKind;
reportDate: Date;
reportUrl: string;
accountUpdaterDailyReport: AccountUpdaterDailyReport;
}
export interface PaymentMethodNotification extends BaseWebhookNotification {