Sample payload and signature
We've provided a SampleNotification
method to generate a parsable signature and payload. This allows you to generate a sample notification and POST the contents of the payload and signature to your application to test your webhook handling code.
Dictionary<String, String> sampleNotification = gateway.WebhookTesting.SampleNotification(
WebhookKind.SUBSCRIPTION_WENT_PAST_DUE, "my_id"
);
WebhookNotification webhookNotification = gateway.WebhookNotification.Parse(
sampleNotification["bt_signature"],
sampleNotification["bt_payload"]
);
webhookNotification.Subscription.Id;
// "my_id"
This method expects two arguments: the kind of webhook notification to be generated, and an ID of the object which triggered it.
The webhook kind can be specified as any one of the following:
Braintree Auth
WebhookKind.CONNECTED_MERCHANT_STATUS_TRANSITIONED
WebhookKind.CONNECTED_MERCHANT_PAY_PAL_STATUS_CHANGED
Disbursement
WebhookKind.DISBURSEMENT
WebhookKind.DISBURSEMENT_EXCEPTION
WebhookKind.TRANSACTION_DISBURSED
Dispute
WebhookKind.DISPUTE_OPENED
WebhookKind.DISPUTE_LOST
WebhookKind.DISPUTE_WON
WebhookKind.DISPUTE_ACCEPTED
WebhookKind.DISPUTE_EXPIRED
WebhookKind.DISPUTE_DISPUTED
OAuth
WebhookKind.OAUTH_ACCESS_REVOKED
Sub-merchant Account
WebhookKind.SUB_MERCHANT_ACCOUNT_APPROVED
WebhookKind.SUB_MERCHANT_ACCOUNT_DECLINED
Subscription
WebhookKind.SUBSCRIPTION_CANCELED
WebhookKind.SUBSCRIPTION_CHARGED_SUCCESSFULLY
WebhookKind.SUBSCRIPTION_CHARGED_UNSUCCESSFULLY
WebhookKind.SUBSCRIPTION_EXPIRED
WebhookKind.SUBSCRIPTION_TRIAL_ENDED
WebhookKind.SUBSCRIPTION_WENT_ACTIVE
WebhookKind.SUBSCRIPTION_WENT_PAST_DUE
Check
WebhookKind.CHECK
Trigger a test notification from Braintree
Once you've created a webhook, you can use the Control Panel to fire a test notification to the webhook's destination URL. This notification's kind is WebhookKind.CHECK
.
To test a webook notification:
- Log into the Control Panel
- Click on the gear icon in the top right corner
- Click API from the drop-down menu
- Click on the Webhooks tab
- Click the Check URL link located to the right of the URL you'd like to check
Be careful when using this check in production – if your webhook handling code doesn’t look for the kind of webhooks it receives, this could lead to unexpected behavior.
For example, if your integration assumes it will only receive Subscription Canceled webhooks and you test the URL, it might cause an exception when your code tries to access the non-existent subscription object on the webhook.