forked from CGM_Public/pretix_original
Fix issue on old-style webhook URLs (#1385)
* Fix issue on old-style webhook URLs * Fix test issue
This commit is contained in:
@@ -170,20 +170,24 @@ def webhook(request, *args, **kwargs):
|
|||||||
rso = ReferencedStripeObject.objects.select_related('order', 'order__event').get(reference=objid)
|
rso = ReferencedStripeObject.objects.select_related('order', 'order__event').get(reference=objid)
|
||||||
return func(rso.order.event, event_json, objid, rso)
|
return func(rso.order.event, event_json, objid, rso)
|
||||||
except ReferencedStripeObject.DoesNotExist:
|
except ReferencedStripeObject.DoesNotExist:
|
||||||
if hasattr(request, 'event'):
|
if event_json['data']['object']['object'] == "charge" and 'payment_intent' in event_json['data']['object']:
|
||||||
return func(request.event, event_json, objid, None)
|
|
||||||
else:
|
|
||||||
# If we receive a charge webhook *before* the payment intent webhook, we don't know the charge ID yet
|
# If we receive a charge webhook *before* the payment intent webhook, we don't know the charge ID yet
|
||||||
# and can't match it -- but we know the payment intent ID!
|
# and can't match it -- but we know the payment intent ID!
|
||||||
if event_json['data']['object']['object'] == "charge" and event_json['data']['object']['payment_intent']:
|
try:
|
||||||
try:
|
rso = ReferencedStripeObject.objects.select_related('order', 'order__event').get(
|
||||||
rso = ReferencedStripeObject.objects.select_related('order', 'order__event').get(
|
reference=event_json['data']['object']['payment_intent']
|
||||||
reference=event_json['data']['object']['payment_intent']
|
)
|
||||||
)
|
return func(rso.order.event, event_json, objid, rso)
|
||||||
return func(rso.order.event, event_json, objid, rso)
|
except ReferencedStripeObject.DoesNotExist:
|
||||||
except ReferencedStripeObject.DoesNotExist:
|
pass
|
||||||
pass
|
elif hasattr(request, 'event') and func != paymentintent_webhook:
|
||||||
|
# This is a legacy integration from back when didn't have ReferencedStripeObject. This can't happen for
|
||||||
|
# payment intents or charges connected with payment intents since they didn't exist back then. Our best
|
||||||
|
# hope is to go for request.event and see if we can find the order ID.
|
||||||
|
return func(request.event, event_json, objid, None)
|
||||||
|
else:
|
||||||
|
# Okay, this is probably not an event that concerns us, maybe other applications talk to the same stripe
|
||||||
|
# account
|
||||||
return HttpResponse("Unable to detect event", status=200)
|
return HttpResponse("Unable to detect event", status=200)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user