Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions shopify_webhook/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def wrapper(request, *args, **kwargs):
domain = request.META['HTTP_X_SHOPIFY_SHOP_DOMAIN']
hmac = request.META['HTTP_X_SHOPIFY_HMAC_SHA256'] if 'HTTP_X_SHOPIFY_HMAC_SHA256' in request.META else None
webhook_id = request.META['HTTP_X_SHOPIFY_WEBHOOK_ID']
triggered_at = request.META['HTTP_X_SHOPIFY_TRIGGERED_AT']
data = json.loads(request.body.decode('utf-8'))
except (KeyError, ValueError) as e:
return HttpResponseBadRequest()
Expand All @@ -44,10 +45,11 @@ def wrapper(request, *args, **kwargs):
return HttpResponseUnauthorized()

# Otherwise, set properties on the request object and return.
request.webhook_topic = topic
request.webhook_data = data
request.webhook_domain = domain
request.webhook_id = webhook_id
request.webhook_topic = topic
request.webhook_data = data
request.webhook_domain = domain
request.webhook_id = webhook_id
request.webhook_triggered_at = triggered_at
return f(request, *args, **kwargs)

return wrapper
Expand Down
1 change: 1 addition & 0 deletions shopify_webhook/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class WebhookSignal(Signal):
* topic
* data
* webhook_id
* triggered_at
"""
pass

Expand Down
1 change: 1 addition & 0 deletions shopify_webhook/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def post_shopify_webhook(self, topic = None, domain = None, data = None, webhook
# Add required headers.
headers['HTTP_X_SHOPIFY_TEST'] = 'true'
headers['HTTP_X_SHOPIFY_SHOP_DOMAIN'] = domain
headers['HTTP_X_SHOPIFY_TRIGGERED_AT'] = '2025-01-22T13:54:50.415605767Z'

# Add optional headers.
if topic:
Expand Down
4 changes: 2 additions & 2 deletions shopify_webhook/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def post(self, request, *args, **kwargs):
# Convert the topic to a signal name and trigger it.
signal_name = get_signal_name_for_topic(request.webhook_topic)
try:
signals.webhook_received.send_robust(self, domain = request.webhook_domain, topic = request.webhook_topic, webhook_id = request.webhook_id, data = request.webhook_data)
getattr(signals, signal_name).send_robust(self, domain = request.webhook_domain, topic = request.webhook_topic, webhook_id = request.webhook_id, data = request.webhook_data)
signals.webhook_received.send_robust(self, domain = request.webhook_domain, topic = request.webhook_topic, webhook_id = request.webhook_id, data = request.webhook_data, triggered_at = request.webhook_triggered_at)
getattr(signals, signal_name).send_robust(self, domain = request.webhook_domain, topic = request.webhook_topic, webhook_id = request.webhook_id, data = request.webhook_data, triggered_at = request.webhook_triggered_at)
except AttributeError:
return HttpResponseBadRequest()

Expand Down