|
10 | 10 | from django.contrib.humanize.templatetags import humanize
|
11 | 11 | from django.db.models import Sum
|
12 | 12 | from django.utils import timezone
|
| 13 | +from djstripe import event_handlers |
13 | 14 | from djstripe import models as djstripe
|
14 |
| -from djstripe import webhooks |
15 | 15 | from djstripe.enums import ChargeStatus
|
16 | 16 | from djstripe.enums import SubscriptionStatus
|
17 | 17 |
|
|
26 | 26 | log = structlog.get_logger(__name__)
|
27 | 27 |
|
28 | 28 |
|
29 |
| -def handler(*args, **kwargs): |
| 29 | +def djstripe_receiver(signal_names): |
30 | 30 | """
|
31 | 31 | Register handlers only if organizations are enabled.
|
32 | 32 |
|
33 |
| - Wrapper around the djstripe's webhooks.handler decorator, |
| 33 | + Wrapper around the djstripe's ``event_handlers.djstripe_receiver`` decorator, |
34 | 34 | to register the handler only if organizations are enabled.
|
35 | 35 | """
|
36 | 36 |
|
37 | 37 | def decorator(func):
|
38 | 38 | if settings.RTD_ALLOW_ORGANIZATIONS:
|
39 |
| - return webhooks.handler(*args, **kwargs)(func) |
| 39 | + return event_handlers.djstripe_receiver(signal_names)(func) |
40 | 40 | return func
|
41 | 41 |
|
42 | 42 | return decorator
|
43 | 43 |
|
44 | 44 |
|
45 |
| -@handler("customer.subscription.created") |
46 |
| -def subscription_created_event(event): |
| 45 | +@djstripe_receiver("customer.subscription.created") |
| 46 | +def subscription_created_event(event, **kwargs): |
47 | 47 | """
|
48 | 48 | Handle the creation of a new subscription.
|
49 | 49 |
|
@@ -82,8 +82,8 @@ def subscription_created_event(event):
|
82 | 82 | organization.save()
|
83 | 83 |
|
84 | 84 |
|
85 |
| -@handler("customer.subscription.updated", "customer.subscription.deleted") |
86 |
| -def subscription_updated_event(event): |
| 85 | +@djstripe_receiver(["customer.subscription.updated", "customer.subscription.deleted"]) |
| 86 | +def subscription_updated_event(event, **kwargs): |
87 | 87 | """
|
88 | 88 | Handle subscription updates.
|
89 | 89 |
|
@@ -155,8 +155,8 @@ def subscription_updated_event(event):
|
155 | 155 | organization.save()
|
156 | 156 |
|
157 | 157 |
|
158 |
| -@handler("customer.subscription.deleted") |
159 |
| -def subscription_canceled(event): |
| 158 | +@djstripe_receiver("customer.subscription.deleted") |
| 159 | +def subscription_canceled(event, **kwargs): |
160 | 160 | """
|
161 | 161 | Send a notification to all owners if the subscription has ended.
|
162 | 162 |
|
@@ -283,8 +283,8 @@ def subscription_canceled(event):
|
283 | 283 | log.warning("Timeout sending a message to Slack webhook")
|
284 | 284 |
|
285 | 285 |
|
286 |
| -@handler("customer.updated") |
287 |
| -def customer_updated_event(event): |
| 286 | +@djstripe_receiver("customer.updated") |
| 287 | +def customer_updated_event(event, **kwargs): |
288 | 288 | """Update the organization with the new information from the stripe customer."""
|
289 | 289 | stripe_customer = event.data["object"]
|
290 | 290 | log.bind(stripe_customer_id=stripe_customer["id"])
|
|
0 commit comments