mirror of
https://github.com/pretix/pretix.git
synced 2026-08-07 10:17:49 +00:00
Send refund webhooks correctly when refunds are created via API
This commit is contained in:
@@ -1610,6 +1610,17 @@ class RefundViewSet(CreateModelMixin, viewsets.ReadOnlyModelViewSet):
|
||||
user=request.user if request.user.is_authenticated else None,
|
||||
auth=request.auth
|
||||
)
|
||||
|
||||
if r.state in (OrderRefund.REFUND_STATE_DONE, OrderRefund.REFUND_STATE_CANCELED, OrderRefund.REFUND_STATE_FAILED):
|
||||
r.order.log_action(
|
||||
f'pretix.event.order.refund.{r.state}', {
|
||||
'local_id': r.local_id,
|
||||
'provider': r.provider,
|
||||
},
|
||||
user=request.user if request.user.is_authenticated else None,
|
||||
auth=request.auth
|
||||
)
|
||||
|
||||
if mark_refunded:
|
||||
try:
|
||||
mark_order_refunded(
|
||||
|
||||
@@ -1517,6 +1517,25 @@ def test_refund_create_mark_refunded(token_client, organizer, event, order):
|
||||
assert order.status == Order.STATUS_CANCELED
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_refund_create_webhook_sent(token_client, organizer, event, order):
|
||||
res = copy.deepcopy(REFUND_CREATE_PAYLOAD)
|
||||
res['state'] = "done"
|
||||
resp = token_client.post(
|
||||
'/api/v1/organizers/{}/events/{}/orders/{}/refunds/'.format(
|
||||
organizer.slug, event.slug, order.code
|
||||
), format='json', data=res
|
||||
)
|
||||
assert resp.status_code == 201
|
||||
with scopes_disabled():
|
||||
r = order.refunds.get(local_id=resp.data['local_id'])
|
||||
assert r.provider == "manual"
|
||||
assert r.amount == Decimal("23.00")
|
||||
assert r.state == "done"
|
||||
with scopes_disabled():
|
||||
assert order.all_logentries().get(action_type="pretix.event.order.refund.done")
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_refund_optional_fields(token_client, organizer, event, order):
|
||||
res = copy.deepcopy(REFUND_CREATE_PAYLOAD)
|
||||
|
||||
Reference in New Issue
Block a user