Skip to content

Commit

Permalink
🤖 Merge PR #51537 [braintree] Add disbursement webhook notification k…
Browse files Browse the repository at this point in the history
…ind and body by @codingmatty

* Add disbursement webhook kind and body

* Update braintree test with added types
  • Loading branch information
codingmatty committed Mar 4, 2021
1 parent 5240d7c commit abb6bc6
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 3 deletions.
21 changes: 21 additions & 0 deletions types/braintree/braintree-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,24 @@ const gateway2: BraintreeGateway = braintree.connect({
if (!response) return;
const id = response.merchantAccount.masterMerchantAccount?.id;
})();

/**
* Disbursement webhook kind
*/
(async () => {
const notification = await gateway.webhookTesting.sampleNotification('disbursement', 'disbursementId');
const result = await gateway.webhookNotification.parse((notification).bt_signature, notification.bt_payload);

if (result.kind === 'disbursement') {
const id = result.disbursement.id;
const amount = result.disbursement.amount;
const disbursementDate = result.disbursement.disbursementDate;
const disbursementType = result.disbursement.disbursementType;
const transactionIds = result.disbursement.transactionIds;
const merchantAccount = result.disbursement.merchantAccount;
const retry = result.disbursement.retry;
const success = result.disbursement.success;
const exceptionMessage = result.disbursement.exceptionMessage;
const followUpAction = result.disbursement.followUpAction;
}
})();
50 changes: 47 additions & 3 deletions types/braintree/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,41 @@ declare namespace braintree {
url?: string;
}

/**
* Disbursement
*/

export class Disbursement {
id: string;
amount: string;
disbursementDate: Date;
disbursementType: DisbursementType;
transactionIds: string[];
merchantAccount: DisbursementMerchantAccount;
retry: boolean;
success: boolean;
exceptionMessage?: DisbursementExceptionMessage;
followUpAction?: DisbursementFollowUpAction;
}

export type DisbursementType = 'credit' | 'debit';

export interface DisbursementMerchantAccount {
id: string;
subMerchantAccount: boolean;
status: 'active';
}

export type DisbursementExceptionMessage =
| 'bank_rejected'
| 'insufficient_funds'
| 'account_not_authorized';

export type DisbursementFollowUpAction =
| 'contact_us'
| 'update_funding_information'
| 'none';

/**
* Merchant Account
*/
Expand Down Expand Up @@ -950,14 +985,20 @@ declare namespace braintree {
};
}

export interface DisbursementNotification extends BaseWebhookNotification {
kind: DisbursementNotificationKind;
disbursement: Disbursement;
}

export type WebhookNotification =
| TransactionNotification
| SubMerchantAccountApprovedNotification
| SubMerchantAccountDeclinedNotification
| SubscriptionNotification
| DisputeNotification
| AccountUpdaterNotification
| PaymentMethodNotification;
| PaymentMethodNotification
| DisbursementNotification;

export type AccountUpdaterNotificationKind =
| 'account_updater_daily_report';
Expand Down Expand Up @@ -990,6 +1031,10 @@ declare namespace braintree {
export type PaymentMethodNotificationKind =
| 'payment_method_revoked_by_customer';

export type DisbursementNotificationKind =
| 'disbursement'
| 'disbursement_exception';

export type WebhookNotificationKind =
| AccountUpdaterNotificationKind
| DisputeNotificationKind
Expand All @@ -998,11 +1043,10 @@ declare namespace braintree {
| SubMerchantAccountDeclinedNotificationKind
| TransactionNotificationKind
| PaymentMethodNotificationKind
| DisbursementNotificationKind
| 'check'
| 'connected_merchant_paypal_status_changed'
| 'connected_merchant_status_transitioned'
| 'disbursement'
| 'disbursement_exception'
| 'grantor_updated_granted_payment_method'
| 'granted_payment_method_revoked'
| 'local_payment_completed'
Expand Down

0 comments on commit abb6bc6

Please sign in to comment.