Skip to content

Commit 5874ca4

Browse files
authored

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

readthedocs/subscriptions/event_handlers.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
from django.contrib.humanize.templatetags import humanize
1111
from django.db.models import Sum
1212
from django.utils import timezone
13+
from djstripe import event_handlers
1314
from djstripe import models as djstripe
14-
from djstripe import webhooks
1515
from djstripe.enums import ChargeStatus
1616
from djstripe.enums import SubscriptionStatus
1717

@@ -26,24 +26,24 @@
2626
log = structlog.get_logger(__name__)
2727

2828

29-
def handler(*args, **kwargs):
29+
def djstripe_receiver(signal_names):
3030
"""
3131
Register handlers only if organizations are enabled.
3232
33-
Wrapper around the djstripe's webhooks.handler decorator,
33+
Wrapper around the djstripe's ``event_handlers.djstripe_receiver`` decorator,
3434
to register the handler only if organizations are enabled.
3535
"""
3636

3737
def decorator(func):
3838
if settings.RTD_ALLOW_ORGANIZATIONS:
39-
return webhooks.handler(*args, **kwargs)(func)
39+
return event_handlers.djstripe_receiver(signal_names)(func)
4040
return func
4141

4242
return decorator
4343

4444

45-
@handler("customer.subscription.created")
46-
def subscription_created_event(event):
45+
@djstripe_receiver("customer.subscription.created")
46+
def subscription_created_event(event, **kwargs):
4747
"""
4848
Handle the creation of a new subscription.
4949
@@ -82,8 +82,8 @@ def subscription_created_event(event):
8282
organization.save()
8383

8484

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):
8787
"""
8888
Handle subscription updates.
8989
@@ -155,8 +155,8 @@ def subscription_updated_event(event):
155155
organization.save()
156156

157157

158-
@handler("customer.subscription.deleted")
159-
def subscription_canceled(event):
158+
@djstripe_receiver("customer.subscription.deleted")
159+
def subscription_canceled(event, **kwargs):
160160
"""
161161
Send a notification to all owners if the subscription has ended.
162162
@@ -283,8 +283,8 @@ def subscription_canceled(event):
283283
log.warning("Timeout sending a message to Slack webhook")
284284

285285

286-
@handler("customer.updated")
287-
def customer_updated_event(event):
286+
@djstripe_receiver("customer.updated")
287+
def customer_updated_event(event, **kwargs):
288288
"""Update the organization with the new information from the stripe customer."""
289289
stripe_customer = event.data["object"]
290290
log.bind(stripe_customer_id=stripe_customer["id"])

0 commit comments

Comments
 (0)