djstripe.models.webhooks
Module for dj-stripe Webhook models
WebhookEndpoint
Bases: StripeModel
api_version
attribute api_version
application
attribute application
djstripe_tolerance
attribute djstripe_tolerance
djstripe_uuid
attribute djstripe_uuid
djstripe_validation_method
attribute djstripe_validation_method
enabled_events
attribute enabled_events
secret
attribute secret
status
attribute status
stripe_class
attribute stripe_class
stripe_dashboard_item_name
attribute stripe_dashboard_item_name
url
attribute url
WebhookEventTrigger
Bases: models.Model
An instance of a request that reached the server endpoint for Stripe webhooks.
Webhook Events are initially UNTRUSTED, as it is possible for any web entity to post any data to our webhook url. Data posted may be valid Stripe information, garbage, or even malicious. The 'valid' flag in this model monitors this.
body
attribute body
created
attribute created
djstripe_version
attribute djstripe_version
event
attribute event
exception
attribute exception
headers
attribute headers
id
attribute id
processed
attribute processed
remote_ip
attribute remote_ip
stripe_trigger_account
attribute stripe_trigger_account
traceback
attribute traceback
updated
attribute updated
valid
attribute valid
webhook_endpoint
attribute webhook_endpoint
from_request
from_request(cls, request, *, webhook_endpoint: WebhookEndpoint)
Create, validate and process a WebhookEventTrigger given a Django request object.
The process is three-fold:
- Create a WebhookEventTrigger object from a Django request.
- Validate the WebhookEventTrigger as a Stripe event using the API.
- If valid, process it into an Event object (and child resource).
json_body
json_body(self)
process
process(self, save = True, api_key: str | None = None)
validate
validate(self, api_key: str, secret: str)
The original contents of the Event message must be confirmed by refetching it and comparing the fetched data with the original data.
This function makes an API call to Stripe to redownload the Event data and returns whether or not it matches the WebhookEventTrigger data.
verify_signature
verify_signature(self, secret: str, tolerance: int) -> bool
get_remote_ip
get_remote_ip(request)
Given the HTTPRequest object return the IP Address of the client
:param request: client request :type request: HTTPRequest
:Returns: the client ip address