getting webhook events into database 2

This commit is contained in:
rizwanisready
2024-04-19 16:05:47 +05:30
parent 2466736936
commit 9cd0b9ef7c
4 changed files with 22 additions and 1 deletions

View File

@@ -176,6 +176,7 @@ class StripeWebhookTest(APIView):
try:
event = stripe.Event.construct_from(json.loads(payload), stripe.api_key)
event_id = event["id"]
event_type = event["type"]
# Check if the event has been processed already
if WebhookEvent.objects.filter(event_id=event_id, status="processed").exists():
return ApiResponse.success(
@@ -186,6 +187,7 @@ class StripeWebhookTest(APIView):
# Log event processing
WebhookEvent.objects.create(
event_id=event_id,
event_type=event_type,
event_payload=json.loads(payload), # optional
)