Sample payload and signature

We've provided a sample_notification 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.

Python
Copy
Copied
sample_notification = gateway.webhook_testing.sample_notification(
    braintree.WebhookNotification.Kind.SubscriptionWentPastDue,
    "my_id"
)

webhook_notification = gateway.webhook_notification.parse(
  sample_notification['bt_signature'],
  sample_notification['bt_payload']
)

webhook_notification.subscription.id
# => "my_id"
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.

This method expects two arguments: the kind of webhook notification to be generated, and an ID of the object which triggered it.

note

The notification returned will contain a dummy object of the type specified, but this object is not a complete item from your gateway. It will not necessarily have everything you expect from a production webhook.

The webhook kind can be specified as any one of the following:

Braintree Auth

  • braintree.WebhookNotification.Kind.ConnectedMerchantStatusTransitioned
  • braintree.WebhookNotification.Kind.ConnectedMerchantPayPalStatusChanged

Disbursement

  • braintree.WebhookNotification.Kind.Disbursement
  • braintree.WebhookNotification.Kind.DisbursementException
  • braintree.WebhookNotification.Kind.TransactionDisbursed

Dispute

  • braintree.WebhookNotification.Kind.DisputeOpened
  • braintree.WebhookNotification.Kind.DisputeLost
  • braintree.WebhookNotification.Kind.DisputeWon

OAuth

  • braintree.WebhookNotification.Kind.OAuthAccessRevoked

Sub-merchant Account

  • braintree.WebhookNotification.Kind.SubMerchantAccountApproved
  • braintree.WebhookNotification.Kind.SubMerchantAccountDeclined

Subscription

  • braintree.WebhookNotification.Kind.SubscriptionCanceled
  • braintree.WebhookNotification.Kind.SubscriptionChargedSuccessfully
  • braintree.WebhookNotification.Kind.SubscriptionChargedUnsuccessfully
  • braintree.WebhookNotification.Kind.SubscriptionExpired
  • braintree.WebhookNotification.Kind.SubscriptionTrialEnded
  • braintree.WebhookNotification.Kind.SubscriptionWentActive
  • braintree.WebhookNotification.Kind.SubscriptionWentPastDue

Check

  • braintree.WebhookNotification.Kind.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 braintree.WebhookNotification.Kind.Check.

To test a webook notification:

  1. Log into the Control Panel
  2. Click on the gear icon in the top right corner
  3. Click API from the drop-down menu
  4. Click on the Webhooks tab
  5. 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.

Still have questions?

If you can’t find an answer, contact us