Package com.stripe.net
Class Webhook
java.lang.Object
com.stripe.net.Webhook
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic final class -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic EventconstructEvent(String payload, String sigHeader, String secret) Returns an Event instance using the provided JSON payload.static EventconstructEvent(String payload, String sigHeader, String secret, long tolerance) Returns an Event instance using the provided JSON payload.static EventconstructEvent(String payload, String sigHeader, String secret, long tolerance, Clock clock) Constructs a snapshot event from an incoming webhook after verifying its authenticity.static EventconstructEventWithoutVerification(String payload) Constructs a snapshot event from an incoming webhook without first verifying its authenticity.static com.google.gson.JsonObjectParses a JSON payload (or cloud provider envelope) and returns the inner Stripe event JSON object.
-
Field Details
-
DEFAULT_TOLERANCE
public static final long DEFAULT_TOLERANCE- See Also:
-
-
Constructor Details
-
Webhook
public Webhook()
-
-
Method Details
-
constructEvent
public static Event constructEvent(String payload, String sigHeader, String secret) throws SignatureVerificationException Returns an Event instance using the provided JSON payload. Throws a JsonSyntaxException if the payload is not valid JSON, and a SignatureVerificationException if the signature verification fails for any reason.- Parameters:
payload- the payload sent by Stripe.sigHeader- the contents of the signature header sent by Stripe.secret- secret used to generate the signature.- Returns:
- the Event instance
- Throws:
SignatureVerificationException- if the verification fails.
-
constructEvent
public static Event constructEvent(String payload, String sigHeader, String secret, long tolerance) throws SignatureVerificationException Returns an Event instance using the provided JSON payload. Throws a JsonSyntaxException if the payload is not valid JSON, and a SignatureVerificationException if the signature verification fails for any reason.- Parameters:
payload- the payload sent by Stripe.sigHeader- the contents of the signature header sent by Stripe.secret- secret used to generate the signature.tolerance- maximum difference in seconds allowed between the header's timestamp and the current time- Returns:
- the Event instance
- Throws:
SignatureVerificationException- if the verification fails.
-
constructEvent
public static Event constructEvent(String payload, String sigHeader, String secret, long tolerance, Clock clock) throws SignatureVerificationException Constructs a snapshot event from an incoming webhook after verifying its authenticity. To work with a webhook that has already been verified (i.e. one from a cloud provider, an asynchronous queue, or during testing), seeconstructEventWithoutVerification.- Parameters:
payload- the payload sent by Stripe.sigHeader- the contents of the signature header sent by Stripe.secret- secret used to generate the signature.tolerance- maximum difference in seconds allowed between the header's timestamp and the current timeclock- instance of clock if you want to use custom time instance- Returns:
- the Event instance
- Throws:
SignatureVerificationException- if the verification fails.
-
constructEventWithoutVerification
Constructs a snapshot event from an incoming webhook without first verifying its authenticity. Should be used after callingWebhook.Signature.verifyHeader(...)or with input from a trusted source (such as AWS EventBridge, or Azure Event Grid payload). Or, to verify & construct in a single call, useWebhook.constructEvent(...)instead.- Parameters:
payload- the payload sent by Stripe, or a cloud provider envelope wrapping it.- Returns:
- the Event instance
- Throws:
IllegalArgumentException- if the payload is a v2 thin event notification.
-
maybeExtractFromCloudProviderEnvelope
Parses a JSON payload (or cloud provider envelope) and returns the inner Stripe event JSON object. If the payload is already a raw Stripe event (object is "event" or "v2.core.event"), it is returned as-is. If it is an AWS EventBridge or Azure Event Grid envelope, the inner event is extracted. ThrowsIllegalArgumentExceptionfor unrecognized formats.- Parameters:
payload- the raw JSON string.- Returns:
- the inner event as a
JsonObject.
-