Class Webhooks

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class Webhooks
    extends java.lang.Object
    implements java.io.Closeable
    Utility class for verifying and parsing webhook events.

    This class provides methods to verify webhook signatures, parse webhook bodies, and handle signed URL payloads.

    Basic Usage

    
     Webhooks webhooks = new Webhooks();
    
     // Verify and parse a webhook (throws if signed URL received)
     WebhookEvent event = webhooks.verifyAndParse(body, headers, signingSecret);
     event.visit(new WebhookEvent.Visitor<Void>() { ... });
     

    Handling Signed URLs

    
     RawWebhookEvent raw = webhooks.verifyAndParseWithOptions(body, headers, signingSecret,
         VerifyAndParseOptions.builder().allowSignedUrl(true).build());
     if (raw.isSignedUrlEvent()) {
         WebhookEvent fullEvent = webhooks.fetchSignedPayload(raw.getSignedUrlEvent());
     } else {
         WebhookEvent event = raw.getEvent();
     }
     
    • Constructor Summary

      Constructors 
      Constructor Description
      Webhooks()  
      Webhooks​(okhttp3.OkHttpClient httpClient)
      Creates a new Webhooks instance with a custom OkHttpClient.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the underlying HTTP client if it was created by this instance.
      WebhookEvent fetchSignedPayload​(WebhookEventWithSignedUrl event)
      Fetches the full payload from a signed URL event.
      RawWebhookEvent parse​(java.lang.String body)
      Parses the webhook body without verification.
      boolean verify​(java.lang.String body, java.util.Map<java.lang.String,​java.lang.String> headers, java.lang.String signingSecret)
      Verifies the webhook signature without parsing.
      boolean verify​(java.lang.String body, java.util.Map<java.lang.String,​java.lang.String> headers, java.lang.String signingSecret, VerifyOptions options)
      Verifies the webhook signature without parsing.
      WebhookEvent verifyAndParse​(java.lang.String body, java.util.Map<java.lang.String,​java.lang.String> headers, java.lang.String signingSecret)
      Verifies the webhook signature and parses the event.
      RawWebhookEvent verifyAndParseWithOptions​(java.lang.String body, java.util.Map<java.lang.String,​java.lang.String> headers, java.lang.String signingSecret, VerifyAndParseOptions options)
      Verifies the webhook signature and parses the event with options.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Webhooks

        public Webhooks()
      • Webhooks

        public Webhooks​(okhttp3.OkHttpClient httpClient)
        Creates a new Webhooks instance with a custom OkHttpClient.

        Use this constructor to customize timeouts, proxy settings, or connection pool configuration. The provided client will not be closed when close() is called.

        Parameters:
        httpClient - The OkHttpClient to use for fetching signed URL payloads