django_program.registration.webhooks¶
Stripe webhook handling for the registration app.
Provides a registry-based dispatch system for processing Stripe webhook events.
Each event kind (e.g. payment_intent.succeeded) maps to a handler class that
encapsulates idempotent processing, signal dispatch, and error capture.
The stripe_webhook view verifies event signatures per-conference, deduplicates
by Stripe event ID, and delegates to the appropriate handler.
Usage in URL configuration:
from django_program.registration.webhooks import stripe_webhook
urlpatterns = [
path("webhooks/stripe/", stripe_webhook),
]
Functions
|
Receive and process Stripe webhook events for a specific conference. |
Classes
Handles |
|
Handles |
|
Handles |
|
Handles |
|
Abstract base class for Stripe webhook event handlers. |
|
Singleton registry mapping Stripe event kinds to handler classes. |
- class django_program.registration.webhooks.WebhookRegistry[source]¶
Bases:
objectSingleton registry mapping Stripe event kinds to handler classes.
Handlers are registered at module load time and looked up by the webhook view when an event arrives.
- class django_program.registration.webhooks.Webhook[source]¶
Bases:
objectAbstract base class for Stripe webhook event handlers.
Subclasses must set
nameto the Stripe event kind they handle and implementprocess_webhook()with the actual business logic. The baseprocess()method wraps execution in idempotency checks and exception capture.- name¶
The Stripe event kind this handler processes.
- event¶
The
StripeEventmodel instance being handled.
- Parameters:
event (
StripeEvent)
- __init__(event)[source]¶
Bind the handler to a specific Stripe event record.
- Parameters:
event (
StripeEvent) – The persistedStripeEventto process.
- process()[source]¶
Run the handler with idempotency and error capture.
Skips events that have already been processed. On success, marks the event as processed and fires any associated Django signal. On failure, captures the traceback to
EventProcessingExceptionand re-raises.- Return type:
- process_webhook()[source]¶
Implement event-specific processing logic.
- Raises:
NotImplementedError – Subclasses must override this method.
- Return type:
- class django_program.registration.webhooks.PaymentIntentSucceededWebhook[source]¶
Bases:
WebhookHandles
payment_intent.succeededevents.Creates a Payment record, transitions the Order from PENDING to PAID, clears the inventory hold, and fires the
order_paidsignal.- Parameters:
event (
StripeEvent)
- class django_program.registration.webhooks.PaymentIntentPaymentFailedWebhook[source]¶
Bases:
WebhookHandles
payment_intent.payment_failedevents.Locates the PENDING payment record for the failed intent and updates its status to FAILED with the error reason from Stripe.
- Parameters:
event (
StripeEvent)
- class django_program.registration.webhooks.ChargeRefundedWebhook[source]¶
Bases:
WebhookHandles
charge.refundedevents.Determines whether the refund is full or partial by comparing
amount_refundedtoamount, then updates Payment and Order statuses accordingly.- Parameters:
event (
StripeEvent)
- class django_program.registration.webhooks.ChargeDisputeCreatedWebhook[source]¶
Bases:
WebhookHandles
charge.dispute.createdevents.Logs the dispute for manual review. No automated actions are taken; the event is simply recorded and marked as processed.
- Parameters:
event (
StripeEvent)
- django_program.registration.webhooks.stripe_webhook(request, conference_slug)[source]¶
Receive and process Stripe webhook events for a specific conference.
Verifies the event signature against the conference’s webhook secret, deduplicates by Stripe event ID, persists the raw event, and dispatches to the registered handler.
Always returns HTTP 200 to acknowledge receipt, even when processing fails. Errors are logged and captured to
EventProcessingException.- Parameters:
request (
HttpRequest) – The incoming HTTP request from Stripe.conference_slug (
str) – URL slug identifying which conference this webhook is for.
- Return type:
HttpResponse- Returns:
An
HttpResponsewith status 200.