mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-01 15:50:13 +00:00
[braintree] Fix the type of the account updater webhook notification (#42348)
This commit is contained in:
@@ -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;
|
||||
})();
|
||||
|
||||
11
types/braintree/index.d.ts
vendored
11
types/braintree/index.d.ts
vendored
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user