getting webhook events into database 2
This commit is contained in:
@@ -285,7 +285,7 @@ class RegistrationPasswordView(APIView):
|
||||
token_data["type"] = str(principal.principal_type)
|
||||
|
||||
return ApiResponse.success(
|
||||
message=constants.REGISTRATION_SUCCESS, data=token_data
|
||||
message="Password updated successfully.", data=token_data
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.0.2 on 2024-04-19 10:28
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("manage_subscriptions", "0004_webhookevent"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="webhookevent",
|
||||
name="event_type",
|
||||
field=models.CharField(blank=True, max_length=255, null=True),
|
||||
),
|
||||
]
|
||||
@@ -78,6 +78,7 @@ class PrincipalSubscription(BaseModel):
|
||||
|
||||
class WebhookEvent(BaseModel):
|
||||
event_id = models.CharField(max_length=255, unique=True, db_index=True)
|
||||
event_type = models.CharField(max_length=255, null=True, blank=True)
|
||||
received_at = models.DateTimeField(auto_now_add=True)
|
||||
processed_at = models.DateTimeField(null=True, blank=True)
|
||||
status = models.CharField(
|
||||
|
||||
Reference in New Issue
Block a user