Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shore up check for already received webhook #329

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Changes from 1 commit
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
12 changes: 8 additions & 4 deletions registration/views/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,21 @@ def square_webhook(request):
event_id = request_body["event_id"]
event_type = request_body.get("type")

# Check to see if webhook was already stored:
existing = PaymentWebhookNotification.objects.filter(
event_id=event_id, event_type=event_type
)
if existing.count() > 0:
return common.abort(409, f"Conflict: event_id {event_id} already_exists")

# Store the verified event notification
notification = PaymentWebhookNotification(
event_id=event_id,
event_type=event_type,
body=request_body,
headers=dict(request.headers),
)
try:
process_webhook(notification)
except IntegrityError:
return common.abort(409, f"Conflict: event_id {event_id} already exists")
process_webhook(notification)

return common.success(200)

Expand Down
Loading