Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Pass order/checkout webhooks to pluginsManager (#16550)

Maciej Korycinskidca684d70d23
diff --git a/saleor/checkout/actions.py b/saleor/checkout/actions.py
index eee70bee99..9aa1492505 100644
--- a/saleor/checkout/actions.py
+++ b/saleor/checkout/actions.py
@@ -48,7 +48,7 @@ def call_checkout_event(
webhook_event_map = get_webhooks_for_multiple_events(
[event_name, *WebhookEventSyncType.CHECKOUT_EVENTS]
)
-
+ webhooks = webhook_event_map.get(event_name, set())
if not webhook_async_event_requires_sync_webhooks_to_trigger(
event_name,
webhook_event_map,
@@ -56,7 +56,7 @@ def call_checkout_event(
):
plugin_manager_method_name = CHECKOUT_WEBHOOK_EVENT_MAP[event_name]
event_func = getattr(manager, plugin_manager_method_name)
- call_event_including_protected_events(event_func, checkout)
+ call_event_including_protected_events(event_func, checkout, webhooks=webhooks)
return
lines_info, _ = fetch_checkout_lines(
@@ -93,6 +93,8 @@ def call_checkout_info_event(
if event_name not in CHECKOUT_WEBHOOK_EVENT_MAP:
raise ValueError(f"Event {event_name} not found in CHECKOUT_WEBHOOK_EVENT_MAP.")
+ webhooks = webhook_event_map.get(event_name, set())
+
plugin_manager_method_name = CHECKOUT_WEBHOOK_EVENT_MAP[event_name]
event_func = getattr(manager, plugin_manager_method_name)
@@ -103,7 +105,7 @@ def call_checkout_info_event(
webhook_event_map,
possible_sync_events=WebhookEventSyncType.CHECKOUT_EVENTS,
):
- call_event_including_protected_events(event_func, checkout)
+ call_event_including_protected_events(event_func, checkout, webhooks=webhooks)
return None
_ = checkout_info.all_shipping_methods
@@ -124,7 +126,7 @@ def call_checkout_info_event(
force_update=True,
)
- call_event_including_protected_events(event_func, checkout)
+ call_event_including_protected_events(event_func, checkout, webhooks=webhooks)
return None
diff --git a/saleor/checkout/tests/test_actions.py b/saleor/checkout/tests/test_actions.py
index ec6e5a0589..79d8e84425 100644
--- a/saleor/checkout/tests/test_actions.py
+++ b/saleor/checkout/tests/test_actions.py
@@ -9,6 +9,7 @@ from django.utils import timezone
from freezegun import freeze_time
from ...core.models import EventDelivery
+from ...core.utils.events import call_event_including_protected_events
from ...plugins.manager import get_plugins_manager
from ...tests.utils import flush_post_commit_hooks
from ...webhook.event_types import WebhookEventAsyncType, WebhookEventSyncType
@@ -43,7 +44,7 @@ def test_transaction_amounts_for_checkout_updated_fully_paid(
checkout.refresh_from_db()
assert checkout.charge_status == CheckoutChargeStatus.FULL
assert checkout.authorize_status == CheckoutAuthorizeStatus.FULL
- mocked_fully_paid.assert_called_with(checkout)
+ mocked_fully_paid.assert_called_with(checkout, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")
@@ -113,7 +114,7 @@ def test_transaction_amounts_for_checkout_updated_updates_last_transaction_modif
flush_post_commit_hooks()
checkout.refresh_from_db()
assert checkout.last_transaction_modified_at == transaction.modified_at
- mocked_fully_paid.assert_called_with(checkout)
+ mocked_fully_paid.assert_called_with(checkout, webhooks=set())
def test_get_checkout_refundable_with_transaction_and_last_refund_success(
@@ -343,8 +344,13 @@ def test_call_checkout_event_incorrect_webhook_event(
@patch(
"saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
)
+@patch(
+ "saleor.checkout.actions.call_event_including_protected_events",
+ wraps=call_event_including_protected_events,
+)
@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
def test_call_checkout_event_triggers_sync_webhook_when_needed(
+ mocked_call_event_including_protected_events,
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
checkout_with_items,
@@ -403,6 +409,11 @@ def test_call_checkout_event_triggers_sync_webhook_when_needed(
call(tax_delivery),
]
)
+ mocked_call_event_including_protected_events.assert_called_once_with(
+ plugins_manager.checkout_created,
+ checkout_with_items,
+ webhooks={checkout_created_webhook},
+ )
@freeze_time("2023-05-31 12:00:01")
@@ -410,8 +421,13 @@ def test_call_checkout_event_triggers_sync_webhook_when_needed(
@patch(
"saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
)
+@patch(
+ "saleor.checkout.actions.call_event_including_protected_events",
+ wraps=call_event_including_protected_events,
+)
@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
def test_call_checkout_event_skips_tax_webhook_when_not_expired(
+ mocked_call_event_including_protected_events,
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
checkout_with_items,
@@ -469,6 +485,11 @@ def test_call_checkout_event_skips_tax_webhook_when_not_expired(
call(filter_shipping_delivery, timeout=settings.WEBHOOK_SYNC_TIMEOUT),
]
)
+ mocked_call_event_including_protected_events.assert_called_once_with(
+ plugins_manager.checkout_created,
+ checkout_with_items,
+ webhooks={checkout_created_webhook},
+ )
@freeze_time("2023-05-31 12:00:01")
@@ -514,8 +535,13 @@ def test_call_checkout_event_skip_sync_webhooks_when_async_missing(
@patch(
"saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
)
+@patch(
+ "saleor.checkout.actions.call_event_including_protected_events",
+ wraps=call_event_including_protected_events,
+)
@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
def test_call_checkout_event_only_async_when_sync_missing(
+ mocked_call_event_including_protected_events,
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
checkout_with_items,
@@ -554,6 +580,9 @@ def test_call_checkout_event_only_async_when_sync_missing(
retry_kwargs={"max_retries": 5},
)
assert not mocked_send_webhook_request_sync.called
+ mocked_call_event_including_protected_events.assert_called_once_with(
+ plugins_manager.checkout_created, checkout_with_items, webhooks={webhook}
+ )
@freeze_time("2023-05-31 12:00:01")
@@ -610,8 +639,13 @@ def test_call_checkout_info_event_incorrect_webhook_event(
@patch(
"saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
)
+@patch(
+ "saleor.checkout.actions.call_event_including_protected_events",
+ wraps=call_event_including_protected_events,
+)
@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
def test_call_checkout_info_event_triggers_sync_webhook_when_needed(
+ mocked_call_event_including_protected_events,
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
checkout_with_items,
@@ -681,6 +715,11 @@ def test_call_checkout_info_event_triggers_sync_webhook_when_needed(
call(tax_delivery),
]
)
+ mocked_call_event_including_protected_events.assert_called_once_with(
+ plugins_manager.checkout_created,
+ checkout_with_items,
+ webhooks={checkout_created_webhook},
+ )
@freeze_time("2023-05-31 12:00:01")
@@ -688,8 +727,13 @@ def test_call_checkout_info_event_triggers_sync_webhook_when_needed(
@patch(
"saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
)
+@patch(
+ "saleor.checkout.actions.call_event_including_protected_events",
+ wraps=call_event_including_protected_events,
+)
@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
def test_call_checkout_info_event_skips_tax_webhook_when_not_expired(
+ mocked_call_event_including_protected_events,
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
checkout_with_items,
@@ -758,6 +802,11 @@ def test_call_checkout_info_event_skips_tax_webhook_when_not_expired(
call(filter_shipping_delivery, timeout=settings.WEBHOOK_SYNC_TIMEOUT),
]
)
+ mocked_call_event_including_protected_events.assert_called_once_with(
+ plugins_manager.checkout_created,
+ checkout_with_items,
+ webhooks={checkout_created_webhook},
+ )
@freeze_time("2023-05-31 12:00:01")
@@ -765,8 +814,13 @@ def test_call_checkout_info_event_skips_tax_webhook_when_not_expired(
@patch(
"saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
)
+@patch(
+ "saleor.checkout.actions.call_event_including_protected_events",
+ wraps=call_event_including_protected_events,
+)
@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
def test_call_checkout_info_event_only_async_when_sync_missing(
+ mocked_call_event_including_protected_events,
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
checkout_with_items,
@@ -815,6 +869,9 @@ def test_call_checkout_info_event_only_async_when_sync_missing(
retry_kwargs={"max_retries": 5},
)
assert not mocked_send_webhook_request_sync.called
+ mocked_call_event_including_protected_events.assert_called_once_with(
+ plugins_manager.checkout_created, checkout_with_items, webhooks={webhook}
+ )
@freeze_time("2023-05-31 12:00:01")
@@ -874,8 +931,13 @@ def test_call_checkout_info_event_skip_sync_webhooks_when_async_missing(
@patch(
"saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
)
+@patch(
+ "saleor.checkout.actions.call_event_including_protected_events",
+ wraps=call_event_including_protected_events,
+)
@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
def test_transaction_amounts_for_checkout_fully_paid_triggers_sync_webhook(
+ mocked_call_event_including_protected_events,
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
wrapped_call_checkout_info_event,
@@ -940,3 +1002,8 @@ def test_transaction_amounts_for_checkout_fully_paid_triggers_sync_webhook(
]
)
assert wrapped_call_checkout_info_event.called
+ mocked_call_event_including_protected_events.assert_called_once_with(
+ plugins_manager.checkout_fully_paid,
+ checkout_with_items,
+ webhooks={checkout_fully_paid_webhook},
+ )
diff --git a/saleor/core/utils/tests/test_events.py b/saleor/core/utils/tests/test_events.py
index cc43b317c2..a59380f948 100644
--- a/saleor/core/utils/tests/test_events.py
+++ b/saleor/core/utils/tests/test_events.py
@@ -1,8 +1,14 @@
+from unittest.mock import patch
+
import pytest
from ....webhook.event_types import WebhookEventAsyncType, WebhookEventSyncType
from ....webhook.utils import get_webhooks_for_multiple_events
-from ..events import call_event, webhook_async_event_requires_sync_webhooks_to_trigger
+from ..events import (
+ call_event,
+ call_event_including_protected_events,
+ webhook_async_event_requires_sync_webhooks_to_trigger,
+)
def test_call_event_cannot_be_used_with_checkout_info_object(
@@ -155,6 +161,26 @@ def test_webhook_async_event_requires_sync_webhooks_to_trigger_missing_event_in_
)
+@patch("saleor.plugins.manager.PluginsManager.checkout_created")
+def test_call_event_including_protected_events(
+ mocked_checkout_created,
+ checkout_with_items,
+ plugins_manager,
+ webhook,
+ django_capture_on_commit_callbacks,
+):
+ # when
+ with django_capture_on_commit_callbacks(execute=True):
+ call_event_including_protected_events(
+ plugins_manager.checkout_created, checkout_with_items, webhooks=[webhook]
+ )
+
+ # then
+ mocked_checkout_created.assert_called_once_with(
+ checkout_with_items, webhooks=[webhook]
+ )
+
+
@pytest.mark.parametrize("subscription_query", ["", None])
def test_webhook_async_event_requires_sync_webhooks_to_trigger_no_subscription_for_event(
setup_order_webhooks, subscription_query, webhook, permission_manage_orders
diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_complete.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_complete.py
index 1f26e86d00..9c23d2cb70 100644
--- a/saleor/graphql/checkout/tests/deprecated/test_checkout_complete.py
+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_complete.py
@@ -148,7 +148,7 @@ def test_checkout_complete(
assert not Checkout.objects.filter(
pk=checkout.pk
).exists(), "Checkout should have been deleted"
- order_confirmed_mock.assert_called_once_with(order)
+ order_confirmed_mock.assert_called_once_with(order, webhooks=set())
def test_checkout_complete_order_already_exists_neither_token_and_id_given(
@@ -312,4 +312,4 @@ def test_checkout_complete_for_token_as_input(
assert not Checkout.objects.filter(
pk=checkout.pk
).exists(), "Checkout should have been deleted"
- order_confirmed_mock.assert_called_once_with(order)
+ order_confirmed_mock.assert_called_once_with(order, webhooks=set())
diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_complete_with_payment.py b/saleor/graphql/checkout/tests/mutations/test_checkout_complete_with_payment.py
index 1b2518eb00..74cfde1323 100644
--- a/saleor/graphql/checkout/tests/mutations/test_checkout_complete_with_payment.py
+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_complete_with_payment.py
@@ -282,7 +282,7 @@ def test_checkout_complete(
assert not Checkout.objects.filter(
pk=checkout.pk
).exists(), "Checkout should have been deleted"
- order_confirmed_mock.assert_called_once_with(order)
+ order_confirmed_mock.assert_called_once_with(order, webhooks=set())
recalculate_with_plugins_mock.assert_not_called()
assert not len(Reservation.objects.all())
@@ -374,7 +374,7 @@ def test_checkout_complete_with_metadata(
assert not Checkout.objects.filter(
pk=checkout.pk
).exists(), "Checkout should have been deleted"
- order_confirmed_mock.assert_called_once_with(order)
+ order_confirmed_mock.assert_called_once_with(order, webhooks=set())
@pytest.mark.integration
@@ -513,7 +513,7 @@ def test_checkout_complete_with_metadata_checkout_without_metadata(
assert not Checkout.objects.filter(
pk=checkout.pk
).exists(), "Checkout should have been deleted"
- order_confirmed_mock.assert_called_once_with(order)
+ order_confirmed_mock.assert_called_once_with(order, webhooks=set())
@pytest.mark.integration
@@ -718,7 +718,7 @@ def test_checkout_complete_gift_card_bought(
checkout.channel.slug,
resending=False,
)
- order_confirmed_mock.assert_called_once_with(order)
+ order_confirmed_mock.assert_called_once_with(order, webhooks=set())
assert Fulfillment.objects.count() == 1
@@ -3873,7 +3873,7 @@ def test_checkout_complete_with_preorder_variant(
assert not Checkout.objects.filter(
pk=checkout.pk
).exists(), "Checkout should have been deleted"
- order_confirmed_mock.assert_called_once_with(order)
+ order_confirmed_mock.assert_called_once_with(order, webhooks=set())
def test_checkout_complete_with_click_collect_preorder_fails_for_disabled_warehouse(
diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_complete_with_transactions.py b/saleor/graphql/checkout/tests/mutations/test_checkout_complete_with_transactions.py
index dc295bf6c8..6b3bc3f934 100644
--- a/saleor/graphql/checkout/tests/mutations/test_checkout_complete_with_transactions.py
+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_complete_with_transactions.py
@@ -1295,7 +1295,7 @@ def test_checkout_complete(
assert not Checkout.objects.filter(
pk=checkout.pk
).exists(), "Checkout should have been deleted"
- order_confirmed_mock.assert_called_once_with(order)
+ order_confirmed_mock.assert_called_once_with(order, webhooks=set())
recalculate_with_plugins_mock.assert_not_called()
assert not len(Reservation.objects.all())
@@ -1375,7 +1375,7 @@ def test_checkout_complete_with_metadata(
assert not Checkout.objects.filter(
pk=checkout.pk
).exists(), "Checkout should have been deleted"
- order_confirmed_mock.assert_called_once_with(order)
+ order_confirmed_mock.assert_called_once_with(order, webhooks=set())
@pytest.mark.integration
@@ -1491,7 +1491,7 @@ def test_checkout_complete_with_metadata_checkout_without_metadata(
assert not Checkout.objects.filter(
pk=checkout.pk
).exists(), "Checkout should have been deleted"
- order_confirmed_mock.assert_called_once_with(order)
+ order_confirmed_mock.assert_called_once_with(order, webhooks=set())
@pytest.mark.integration
@@ -1671,7 +1671,7 @@ def test_checkout_complete_gift_card_bought(
checkout.channel.slug,
resending=False,
)
- order_confirmed_mock.assert_called_once_with(order)
+ order_confirmed_mock.assert_called_once_with(order, webhooks=set())
assert Fulfillment.objects.count() == 1
@@ -1795,7 +1795,7 @@ def test_checkout_complete_with_shipping_voucher_and_gift_card(
assert not Checkout.objects.filter(
pk=checkout.pk
).exists(), "Checkout should have been deleted"
- order_confirmed_mock.assert_called_once_with(order)
+ order_confirmed_mock.assert_called_once_with(order, webhooks=set())
assert not len(Reservation.objects.all())
@@ -2438,7 +2438,7 @@ def test_checkout_complete_with_shipping_voucher(
assert not Checkout.objects.filter(
pk=checkout.pk
).exists(), "Checkout should have been deleted"
- order_confirmed_mock.assert_called_once_with(order)
+ order_confirmed_mock.assert_called_once_with(order, webhooks=set())
assert not len(Reservation.objects.all())
@@ -3815,7 +3815,7 @@ def test_checkout_complete_with_preorder_variant(
assert not Checkout.objects.filter(
pk=checkout.pk
).exists(), "Checkout should have been deleted"
- order_confirmed_mock.assert_called_once_with(order)
+ order_confirmed_mock.assert_called_once_with(order, webhooks=set())
def test_checkout_complete_with_click_collect_preorder_fails_for_disabled_warehouse(
diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_create.py b/saleor/graphql/checkout/tests/mutations/test_checkout_create.py
index 69b4361dbb..edd6d6d0df 100644
--- a/saleor/graphql/checkout/tests/mutations/test_checkout_create.py
+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_create.py
@@ -66,12 +66,11 @@ MUTATION_CHECKOUT_CREATE = """
"""
[email protected]("saleor.plugins.webhook.plugin.get_webhooks_for_event")
@mock.patch("saleor.plugins.webhook.plugin.trigger_webhooks_async")
def test_checkout_create_triggers_async_webhooks(
mocked_webhook_trigger,
- mocked_get_webhooks_for_event,
- any_webhook,
+ webhook,
+ permission_manage_checkouts,
user_api_client,
stock,
graphql_address_data,
@@ -79,7 +78,9 @@ def test_checkout_create_triggers_async_webhooks(
channel_USD,
):
"""Create checkout object using GraphQL API."""
- mocked_get_webhooks_for_event.return_value = [any_webhook]
+ webhook.app.permissions.set([permission_manage_checkouts])
+ webhook.events.create(event_type=WebhookEventAsyncType.CHECKOUT_CREATED)
+
settings.PLUGINS = ["saleor.plugins.webhook.plugin.WebhookPlugin"]
variant = stock.product_variant
variant_id = graphene.Node.to_global_id("ProductVariant", variant.id)
diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_remove_promo_code.py b/saleor/graphql/checkout/tests/mutations/test_checkout_remove_promo_code.py
index 264e413683..a6ea000341 100644
--- a/saleor/graphql/checkout/tests/mutations/test_checkout_remove_promo_code.py
+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_remove_promo_code.py
@@ -86,7 +86,9 @@ def test_checkout_remove_voucher_code(
assert data["checkout"]["voucherCode"] is None
assert checkout_with_voucher.voucher_code is None
assert checkout_with_voucher.last_change != previous_checkout_last_change
- checkout_updated_webhook_mock.assert_called_once_with(checkout_with_voucher)
+ checkout_updated_webhook_mock.assert_called_once_with(
+ checkout_with_voucher, webhooks=set()
+ )
@patch("saleor.plugins.manager.PluginsManager.checkout_updated")
@@ -117,7 +119,9 @@ def test_checkout_remove_voucher_code_from_voucher_with_multiple_codes(
assert data["checkout"]["voucherCode"] is None
assert checkout_with_voucher.voucher_code is None
assert checkout_with_voucher.last_change != previous_checkout_last_change
- checkout_updated_webhook_mock.assert_called_once_with(checkout_with_voucher)
+ checkout_updated_webhook_mock.assert_called_once_with(
+ checkout_with_voucher, webhooks=set()
+ )
@patch("saleor.plugins.manager.PluginsManager.checkout_updated")
@@ -228,7 +232,9 @@ def test_checkout_remove_gift_card_code(
assert not checkout_with_gift_card.gift_cards.all().exists()
checkout_with_gift_card.refresh_from_db()
assert checkout_with_gift_card.last_change != previous_checkout_last_change
- checkout_updated_webhook_mock.assert_called_once_with(checkout_with_gift_card)
+ checkout_updated_webhook_mock.assert_called_once_with(
+ checkout_with_gift_card, webhooks=set()
+ )
@patch("saleor.plugins.manager.PluginsManager.checkout_updated")
@@ -293,7 +299,9 @@ def test_checkout_remove_one_of_gift_cards(
assert not checkout_gift_cards.filter(code=gift_card_first.code).exists()
checkout_with_gift_card.refresh_from_db()
assert checkout_with_gift_card.last_change != previous_checkout_last_change
- checkout_updated_webhook_mock.assert_called_once_with(checkout_with_gift_card)
+ checkout_updated_webhook_mock.assert_called_once_with(
+ checkout_with_gift_card, webhooks=set()
+ )
@patch("saleor.plugins.manager.PluginsManager.checkout_updated")
@@ -362,7 +370,9 @@ def test_checkout_remove_voucher_code_by_id(
assert data["checkout"]["voucherCode"] is None
assert len(data["checkout"]["giftCards"]) == 1
assert checkout_with_voucher.voucher_code is None
- checkout_updated_webhook_mock.assert_called_once_with(checkout_with_voucher)
+ checkout_updated_webhook_mock.assert_called_once_with(
+ checkout_with_voucher, webhooks=set()
+ )
@patch("saleor.plugins.manager.PluginsManager.checkout_updated")
@@ -440,7 +450,9 @@ def test_checkout_remove_voucher_with_multiple_codes_by_id(
assert data["checkout"]["voucherCode"] is None
assert len(data["checkout"]["giftCards"]) == 1
assert checkout_with_voucher.voucher_code is None
- checkout_updated_webhook_mock.assert_called_once_with(checkout_with_voucher)
+ checkout_updated_webhook_mock.assert_called_once_with(
+ checkout_with_voucher, webhooks=set()
+ )
@patch("saleor.plugins.manager.PluginsManager.checkout_updated")
@@ -473,7 +485,9 @@ def test_checkout_remove_gift_card_by_id(
assert gift_cards[0]["id"] == graphene.Node.to_global_id(
"GiftCard", gift_card_expiry_date.pk
)
- checkout_updated_webhook_mock.assert_called_once_with(checkout_with_voucher)
+ checkout_updated_webhook_mock.assert_called_once_with(
+ checkout_with_voucher, webhooks=set()
+ )
@patch("saleor.plugins.manager.PluginsManager.checkout_updated")
@@ -591,7 +605,9 @@ def test_checkout_remove_voucher_code_invalidates_price(
assert not data["errors"]
assert data["checkout"]["subtotalPrice"]["gross"]["amount"] == subtotal.amount
assert data["checkout"]["totalPrice"]["gross"]["amount"] == expected_total
- checkout_updated_webhook_mock.assert_called_once_with(checkout_with_item)
+ checkout_updated_webhook_mock.assert_called_once_with(
+ checkout_with_item, webhooks=set()
+ )
@patch("saleor.plugins.manager.PluginsManager.checkout_updated")
@@ -629,7 +645,9 @@ def test_checkout_remove_voucher_code_order_promotion_discount_applied(
assert checkout.discount_amount == reward_value
assert checkout.last_change != previous_checkout_last_change
assert checkout.discounts.count() == 1
- checkout_updated_webhook_mock.assert_called_once_with(checkout_with_voucher)
+ checkout_updated_webhook_mock.assert_called_once_with(
+ checkout_with_voucher, webhooks=set()
+ )
@patch("saleor.plugins.manager.PluginsManager.checkout_updated")
@@ -668,7 +686,9 @@ def test_checkout_remove_voucher_code_gift_reward_applied(
assert checkout.lines.count() == lines_count + 1 == len(data["checkout"]["lines"])
gift_line = checkout.lines.get(is_gift=True)
assert gift_line.discounts.count() == 1
- checkout_updated_webhook_mock.assert_called_once_with(checkout_with_voucher)
+ checkout_updated_webhook_mock.assert_called_once_with(
+ checkout_with_voucher, webhooks=set()
+ )
@patch("saleor.plugins.manager.PluginsManager.checkout_updated")
@@ -704,7 +724,9 @@ def test_with_active_problems_flow(
# then
assert not content["data"]["checkoutRemovePromoCode"]["errors"]
- checkout_updated_webhook_mock.assert_called_once_with(checkout_with_problems)
+ checkout_updated_webhook_mock.assert_called_once_with(
+ checkout_with_problems, webhooks=set()
+ )
@patch(
diff --git a/saleor/graphql/checkout/tests/mutations/test_order_create_from_checkout.py b/saleor/graphql/checkout/tests/mutations/test_order_create_from_checkout.py
index e73557d94f..f548fd08cd 100644
--- a/saleor/graphql/checkout/tests/mutations/test_order_create_from_checkout.py
+++ b/saleor/graphql/checkout/tests/mutations/test_order_create_from_checkout.py
@@ -206,7 +206,7 @@ def test_order_from_checkout(
gift_card=gift_card, type=GiftCardEvents.USED_IN_ORDER
)
- order_confirmed_mock.assert_called_once_with(order)
+ order_confirmed_mock.assert_called_once_with(order, webhooks=set())
recalculate_with_plugins_mock.assert_not_called()
@@ -369,7 +369,7 @@ def test_order_from_checkout_with_metadata(
**checkout.metadata_storage.private_metadata,
metadata_key: metadata_value,
}
- order_confirmed_mock.assert_called_once_with(order)
+ order_confirmed_mock.assert_called_once_with(order, webhooks=set())
@pytest.mark.integration
@@ -442,7 +442,7 @@ def test_order_from_checkout_with_metadata_checkout_without_metadata(
**checkout.metadata_storage.private_metadata,
metadata_key: metadata_value,
}
- order_confirmed_mock.assert_called_once_with(order)
+ order_confirmed_mock.assert_called_once_with(order, webhooks=set())
def test_order_from_checkout_by_app_with_missing_permission(
@@ -555,7 +555,7 @@ def test_order_from_checkout_gift_card_bought(
checkout.channel.slug,
resending=False,
)
- order_confirmed_mock.assert_called_once_with(order)
+ order_confirmed_mock.assert_called_once_with(order, webhooks=set())
assert Fulfillment.objects.count() == 1
@@ -2077,7 +2077,7 @@ def test_order_from_draft_create_with_preorder_variant(
assert not Checkout.objects.filter(
pk=checkout.pk
).exists(), "Checkout should have been deleted"
- order_confirmed_mock.assert_called_once_with(order)
+ order_confirmed_mock.assert_called_once_with(order, webhooks=set())
def test_order_from_draft_create_click_collect_preorder_fails_for_disabled_warehouse(
diff --git a/saleor/graphql/order/tests/deprecated/test_order.py b/saleor/graphql/order/tests/deprecated/test_order.py
index 8fa07e0b49..4539eb7ca6 100644
--- a/saleor/graphql/order/tests/deprecated/test_order.py
+++ b/saleor/graphql/order/tests/deprecated/test_order.py
@@ -24,11 +24,11 @@ from ....tests.utils import get_graphql_content
def assert_proper_webhook_called_once(order, status, draft_mock, order_mock):
if status == OrderStatus.DRAFT:
- draft_mock.assert_called_once_with(order)
+ draft_mock.assert_called_once_with(order, webhooks=set())
order_mock.assert_not_called()
else:
draft_mock.assert_not_called()
- order_mock.assert_called_once_with(order)
+ order_mock.assert_called_once_with(order, webhooks=set())
QUERY_ORDER_TOTAL = """
diff --git a/saleor/graphql/order/tests/mutations/test_order_note_add.py b/saleor/graphql/order/tests/mutations/test_order_note_add.py
index 3caa1c8eb3..3ce36ec207 100644
--- a/saleor/graphql/order/tests/mutations/test_order_note_add.py
+++ b/saleor/graphql/order/tests/mutations/test_order_note_add.py
@@ -64,7 +64,7 @@ def test_order_note_add_as_staff_user(
assert data["order"]["id"] == order_id
assert data["event"]["user"]["email"] == staff_user.email
assert data["event"]["message"] == message
- order_updated_webhook_mock.assert_called_once_with(order)
+ order_updated_webhook_mock.assert_called_once_with(order, webhooks=set())
order.refresh_from_db()
assert order.status == OrderStatus.UNFULFILLED
@@ -161,7 +161,7 @@ def test_order_add_note_by_app(
assert data["event"]["user"] is None
assert data["event"]["app"]["name"] == app_api_client.app.name
assert data["event"]["message"] == message
- order_updated_webhook_mock.assert_called_once_with(order)
+ order_updated_webhook_mock.assert_called_once_with(order, webhooks=set())
def test_order_note_add_fail_on_missing_permission(staff_api_client, order):
diff --git a/saleor/graphql/order/tests/mutations/test_order_note_update.py b/saleor/graphql/order/tests/mutations/test_order_note_update.py
index 721bb1ce40..8998b06a46 100644
--- a/saleor/graphql/order/tests/mutations/test_order_note_update.py
+++ b/saleor/graphql/order/tests/mutations/test_order_note_update.py
@@ -75,7 +75,7 @@ def test_order_note_update_as_staff_user(
assert data["event"]["user"]["email"] == staff_user.email
assert data["event"]["message"] == message
assert data["event"]["related"]["id"] == note_id
- order_updated_webhook_mock.assert_called_once_with(order)
+ order_updated_webhook_mock.assert_called_once_with(order, webhooks=set())
order.refresh_from_db()
assert order.status == OrderStatus.UNFULFILLED
@@ -123,7 +123,7 @@ def test_order_note_update_as_app(
assert data["order"]["id"] == order_id
assert data["event"]["user"] is None
assert data["event"]["related"]["id"] == note_id
- order_updated_webhook_mock.assert_called_once_with(order)
+ order_updated_webhook_mock.assert_called_once_with(order, webhooks=set())
new_note = OrderEvent.objects.filter(order=order).exclude(pk=note.pk).get()
assert new_note.type == OrderEvents.NOTE_UPDATED
diff --git a/saleor/graphql/order/tests/mutations/test_order_refund.py b/saleor/graphql/order/tests/mutations/test_order_refund.py
index 73dde641a2..ba9798aeac 100644
--- a/saleor/graphql/order/tests/mutations/test_order_refund.py
+++ b/saleor/graphql/order/tests/mutations/test_order_refund.py
@@ -76,8 +76,8 @@ def test_order_refund(
assert refunded_fulfillment.shipping_refund_amount is None
flush_post_commit_hooks()
- mock_order_updated.assert_called_once_with(order)
- mock_order_refunded.assert_called_once_with(order)
+ mock_order_updated.assert_called_once_with(order, webhooks=set())
+ mock_order_refunded.assert_called_once_with(order, webhooks=set())
assert amount < order.total.gross.amount
assert not mock_order_fully_refunded.called
@@ -131,9 +131,9 @@ def test_order_fully_refunded(
assert refunded_fulfillment.shipping_refund_amount is None
flush_post_commit_hooks()
- mock_order_updated.assert_called_once_with(order)
- mock_order_refunded.assert_called_once_with(order)
- mock_order_fully_refunded.assert_called_once_with(order)
+ mock_order_updated.assert_called_once_with(order, webhooks=set())
+ mock_order_refunded.assert_called_once_with(order, webhooks=set())
+ mock_order_fully_refunded.assert_called_once_with(order, webhooks=set())
def test_order_refund_by_user_no_channel_access(
@@ -206,9 +206,9 @@ def test_order_refund_by_app(
assert refunded_fulfillment.shipping_refund_amount is None
flush_post_commit_hooks()
- mock_order_updated.assert_called_once_with(order)
- mock_order_refunded.assert_called_once_with(order)
- mock_order_fully_refunded.assert_called_once_with(order)
+ mock_order_updated.assert_called_once_with(order, webhooks=set())
+ mock_order_refunded.assert_called_once_with(order, webhooks=set())
+ mock_order_fully_refunded.assert_called_once_with(order, webhooks=set())
def test_order_refund_with_gift_card_lines(
diff --git a/saleor/graphql/order/tests/mutations/test_order_update.py b/saleor/graphql/order/tests/mutations/test_order_update.py
index be446cbaec..60866a383c 100644
--- a/saleor/graphql/order/tests/mutations/test_order_update.py
+++ b/saleor/graphql/order/tests/mutations/test_order_update.py
@@ -85,7 +85,7 @@ def test_order_update(
assert order.user is None
assert order.status == OrderStatus.UNFULFILLED
assert order.external_reference == external_reference
- order_updated_webhook_mock.assert_called_once_with(order)
+ order_updated_webhook_mock.assert_called_once_with(order, webhooks=set())
def test_order_update_by_user_no_channel_access(
@@ -171,7 +171,7 @@ def test_order_update_by_app(
assert order.user is None
assert order.status == OrderStatus.UNFULFILLED
assert order.external_reference == external_reference
- order_updated_webhook_mock.assert_called_once_with(order)
+ order_updated_webhook_mock.assert_called_once_with(order, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_updated")
diff --git a/saleor/graphql/order/tests/utils.py b/saleor/graphql/order/tests/utils.py
index 04ee2042cf..da7c9fbb34 100644
--- a/saleor/graphql/order/tests/utils.py
+++ b/saleor/graphql/order/tests/utils.py
@@ -14,8 +14,8 @@ def assert_order_and_payment_ids(content, payment):
def assert_proper_webhook_called_once(order, status, draft_mock, order_mock):
if status == OrderStatus.DRAFT:
- draft_mock.assert_called_once_with(order)
+ draft_mock.assert_called_once_with(order, webhooks=set())
order_mock.assert_not_called()
else:
draft_mock.assert_not_called()
- order_mock.assert_called_once_with(order)
+ order_mock.assert_called_once_with(order, webhooks=set())
diff --git a/saleor/graphql/payment/tests/mutations/test_payment_refund.py b/saleor/graphql/payment/tests/mutations/test_payment_refund.py
index 48d0bfa894..5fed9f73ec 100644
--- a/saleor/graphql/payment/tests/mutations/test_payment_refund.py
+++ b/saleor/graphql/payment/tests/mutations/test_payment_refund.py
@@ -62,9 +62,9 @@ def test_payment_refund_success(
assert txn.kind == TransactionKind.REFUND
flush_post_commit_hooks()
- mock_order_updated.assert_called_once_with(payment.order)
- mock_order_refunded.assert_called_once_with(payment.order)
- mock_order_fully_refunded.assert_called_once_with(payment.order)
+ mock_order_updated.assert_called_once_with(payment.order, webhooks=set())
+ mock_order_refunded.assert_called_once_with(payment.order, webhooks=set())
+ mock_order_fully_refunded.assert_called_once_with(payment.order, webhooks=set())
def test_payment_refund_success_by_user_no_channel_access(
@@ -131,9 +131,9 @@ def test_payment_refund_success_by_app(
assert txn.kind == TransactionKind.REFUND
flush_post_commit_hooks()
- mock_order_updated.assert_called_once_with(payment.order)
- mock_order_refunded.assert_called_once_with(payment.order)
- mock_order_fully_refunded.assert_called_once_with(payment.order)
+ mock_order_updated.assert_called_once_with(payment.order, webhooks=set())
+ mock_order_refunded.assert_called_once_with(payment.order, webhooks=set())
+ mock_order_fully_refunded.assert_called_once_with(payment.order, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_updated")
diff --git a/saleor/graphql/payment/tests/mutations/test_transaction_create.py b/saleor/graphql/payment/tests/mutations/test_transaction_create.py
index dad77b8f2b..42e58b47f5 100644
--- a/saleor/graphql/payment/tests/mutations/test_transaction_create.py
+++ b/saleor/graphql/payment/tests/mutations/test_transaction_create.py
@@ -1221,7 +1221,7 @@ def test_transaction_create_for_checkout_fully_paid(
assert checkout.charge_status == CheckoutChargeStatus.FULL
assert checkout.authorize_status == CheckoutAuthorizeStatus.FULL
- mocked_checkout_fully_paid.assert_called_once_with(checkout)
+ mocked_checkout_fully_paid.assert_called_once_with(checkout, webhooks=set())
@pytest.mark.parametrize(
@@ -1888,9 +1888,9 @@ def test_transaction_create_for_order_triggers_webhooks_when_fully_paid(
assert order.status == excpected_order_status
assert order.charge_status == OrderChargeStatus.FULL
- mock_order_fully_paid.assert_called_once_with(order)
- mock_order_updated.assert_called_once_with(order)
- mock_order_paid.assert_called_once_with(order)
+ mock_order_fully_paid.assert_called_once_with(order, webhooks=set())
+ mock_order_updated.assert_called_once_with(order, webhooks=set())
+ mock_order_paid.assert_called_once_with(order, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_paid")
@@ -1931,8 +1931,8 @@ def test_transaction_create_for_order_triggers_webhook_when_partially_paid(
assert order_with_lines.charge_status == OrderChargeStatus.PARTIAL
assert not mock_order_fully_paid.called
- mock_order_updated.assert_called_once_with(order_with_lines)
- mock_order_paid.assert_called_once_with(order_with_lines)
+ mock_order_updated.assert_called_once_with(order_with_lines, webhooks=set())
+ mock_order_paid.assert_called_once_with(order_with_lines, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_updated")
@@ -1971,7 +1971,7 @@ def test_transaction_create_for_order_triggers_webhook_when_authorized(
assert order_with_lines.authorize_status == OrderAuthorizeStatus.PARTIAL
assert not mock_order_fully_paid.called
- mock_order_updated.assert_called_once_with(order_with_lines)
+ mock_order_updated.assert_called_once_with(order_with_lines, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_updated")
@@ -2010,9 +2010,9 @@ def test_transaction_create_for_order_triggers_webhooks_when_fully_refunded(
order_with_lines.refresh_from_db()
get_graphql_content(response)
- mock_order_fully_refunded.assert_called_once_with(order_with_lines)
- mock_order_refunded.assert_called_once_with(order_with_lines)
- mock_order_updated.assert_called_once_with(order_with_lines)
+ mock_order_fully_refunded.assert_called_once_with(order_with_lines, webhooks=set())
+ mock_order_refunded.assert_called_once_with(order_with_lines, webhooks=set())
+ mock_order_updated.assert_called_once_with(order_with_lines, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_updated")
@@ -2052,8 +2052,8 @@ def test_transaction_create_for_order_triggers_webhook_when_partially_refunded(
get_graphql_content(response)
assert not mock_order_fully_refunded.called
- mock_order_updated.assert_called_once_with(order_with_lines)
- mock_order_refunded.assert_called_once_with(order_with_lines)
+ mock_order_updated.assert_called_once_with(order_with_lines, webhooks=set())
+ mock_order_refunded.assert_called_once_with(order_with_lines, webhooks=set())
@freeze_time("2018-05-31 12:00:01")
diff --git a/saleor/graphql/payment/tests/mutations/test_transaction_event_report.py b/saleor/graphql/payment/tests/mutations/test_transaction_event_report.py
index facf6a6476..f78e0d2caf 100644
--- a/saleor/graphql/payment/tests/mutations/test_transaction_event_report.py
+++ b/saleor/graphql/payment/tests/mutations/test_transaction_event_report.py
@@ -1408,7 +1408,7 @@ def test_transaction_event_updates_checkout_full_paid_with_charged_amount(
assert checkout.charge_status == CheckoutChargeStatus.FULL
assert checkout.authorize_status == CheckoutAuthorizeStatus.FULL
- mocked_fully_paid.assert_called_once_with(checkout)
+ mocked_fully_paid.assert_called_once_with(checkout, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")
@@ -1472,7 +1472,7 @@ def test_transaction_event_updates_checkout_full_paid_with_pending_charge_amount
assert checkout.charge_status == CheckoutChargeStatus.FULL
assert checkout.authorize_status == CheckoutAuthorizeStatus.FULL
- mocked_fully_paid.assert_called_once_with(checkout)
+ mocked_fully_paid.assert_called_once_with(checkout, webhooks=set())
def test_transaction_event_report_with_info_event(
@@ -1763,9 +1763,9 @@ def test_transaction_event_report_for_order_triggers_webhooks_when_fully_paid(
assert order.status == excpected_order_status
assert order.charge_status == OrderChargeStatusEnum.FULL.value
- mock_order_fully_paid.assert_called_once_with(order)
- mock_order_updated.assert_called_once_with(order)
- mock_order_paid.assert_called_once_with(order)
+ mock_order_fully_paid.assert_called_once_with(order, webhooks=set())
+ mock_order_updated.assert_called_once_with(order, webhooks=set())
+ mock_order_paid.assert_called_once_with(order, webhooks=set())
@pytest.mark.parametrize(
@@ -1829,9 +1829,9 @@ def test_transaction_event_report_for_draft_order_triggers_webhooks_when_fully_p
assert order.status == OrderStatus.DRAFT
assert order.charge_status == OrderChargeStatusEnum.FULL.value
- mock_order_fully_paid.assert_called_once_with(order)
- mock_order_updated.assert_called_once_with(order)
- mock_order_paid.assert_called_once_with(order)
+ mock_order_fully_paid.assert_called_once_with(order, webhooks=set())
+ mock_order_updated.assert_called_once_with(order, webhooks=set())
+ mock_order_paid.assert_called_once_with(order, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_updated")
@@ -1886,7 +1886,7 @@ def test_transaction_event_report_for_order_triggers_webhooks_when_partially_pai
assert order.charge_status == OrderChargeStatusEnum.PARTIAL.value
assert not mock_order_fully_paid.called
- mock_order_updated.assert_called_once_with(order)
+ mock_order_updated.assert_called_once_with(order, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_updated")
@@ -1941,7 +1941,7 @@ def test_transaction_event_report_for_order_triggers_webhooks_when_partially_aut
assert order.authorize_status == OrderAuthorizeStatusEnum.PARTIAL.value
assert not mock_order_fully_paid.called
- mock_order_updated.assert_called_once_with(order)
+ mock_order_updated.assert_called_once_with(order, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_updated")
@@ -1996,7 +1996,7 @@ def test_transaction_event_report_for_order_triggers_webhooks_when_fully_authori
assert order.authorize_status == OrderAuthorizeStatusEnum.FULL.value
assert not mock_order_fully_paid.called
- mock_order_updated.assert_called_once_with(order)
+ mock_order_updated.assert_called_once_with(order, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_refunded")
@@ -2051,9 +2051,9 @@ def test_transaction_event_report_for_order_triggers_webhooks_when_fully_refunde
get_graphql_content(response)
order.refresh_from_db()
- mock_order_fully_refunded.assert_called_once_with(order)
- mock_order_updated.assert_called_once_with(order)
- mock_order_refunded.assert_called_once_with(order)
+ mock_order_fully_refunded.assert_called_once_with(order, webhooks=set())
+ mock_order_updated.assert_called_once_with(order, webhooks=set())
+ mock_order_refunded.assert_called_once_with(order, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_refunded")
@@ -2109,8 +2109,8 @@ def test_transaction_event_report_for_order_triggers_webhooks_when_partially_ref
order.refresh_from_db()
assert not mock_order_fully_refunded.called
- mock_order_refunded.assert_called_once_with(order)
- mock_order_updated.assert_called_once_with(order)
+ mock_order_refunded.assert_called_once_with(order, webhooks=set())
+ mock_order_updated.assert_called_once_with(order, webhooks=set())
def test_transaction_event_report_by_app_assign_app_owner(
diff --git a/saleor/graphql/payment/tests/mutations/test_transaction_initialize.py b/saleor/graphql/payment/tests/mutations/test_transaction_initialize.py
index a4b3e03400..343a7456da 100644
--- a/saleor/graphql/payment/tests/mutations/test_transaction_initialize.py
+++ b/saleor/graphql/payment/tests/mutations/test_transaction_initialize.py
@@ -1858,7 +1858,7 @@ def test_checkout_fully_paid(
content = get_graphql_content(response)
assert not content["data"]["transactionInitialize"]["errors"]
checkout.refresh_from_db()
- mocked_fully_paid.assert_called_once_with(checkout)
+ mocked_fully_paid.assert_called_once_with(checkout, webhooks=set())
assert checkout.charge_status == CheckoutChargeStatus.FULL
assert checkout.authorize_status == CheckoutAuthorizeStatus.FULL
diff --git a/saleor/graphql/payment/tests/mutations/test_transaction_process.py b/saleor/graphql/payment/tests/mutations/test_transaction_process.py
index b8fd9d153c..d9780289cd 100644
--- a/saleor/graphql/payment/tests/mutations/test_transaction_process.py
+++ b/saleor/graphql/payment/tests/mutations/test_transaction_process.py
@@ -1167,7 +1167,7 @@ def test_checkout_fully_paid(
assert not content["data"]["transactionProcess"]["errors"]
checkout.refresh_from_db()
- mocked_fully_paid.assert_called_once_with(checkout)
+ mocked_fully_paid.assert_called_once_with(checkout, webhooks=set())
assert checkout.charge_status == CheckoutChargeStatus.FULL
assert checkout.authorize_status == CheckoutAuthorizeStatus.FULL
diff --git a/saleor/graphql/payment/tests/mutations/test_transaction_update.py b/saleor/graphql/payment/tests/mutations/test_transaction_update.py
index ed9ebfd438..d4a2f07c40 100644
--- a/saleor/graphql/payment/tests/mutations/test_transaction_update.py
+++ b/saleor/graphql/payment/tests/mutations/test_transaction_update.py
@@ -2629,7 +2629,7 @@ def test_transaction_update_for_checkout_fully_paid(
assert checkout.charge_status == CheckoutChargeStatus.FULL
assert checkout.authorize_status == CheckoutAuthorizeStatus.FULL
- mocked_checkout_fully_paid.assert_called_once_with(checkout)
+ mocked_checkout_fully_paid.assert_called_once_with(checkout, webhooks=set())
def test_transaction_update_accepts_old_id_for_old_transaction(
@@ -2744,9 +2744,9 @@ def test_transaction_update_for_order_triggers_webhooks_when_fully_paid(
assert order.status == excpected_order_status
assert order.charge_status == OrderChargeStatus.FULL
- mock_order_fully_paid.assert_called_once_with(order)
- mock_order_updated.assert_called_once_with(order)
- mock_order_paid.assert_called_once_with(order)
+ mock_order_fully_paid.assert_called_once_with(order, webhooks=set())
+ mock_order_updated.assert_called_once_with(order, webhooks=set())
+ mock_order_paid.assert_called_once_with(order, webhooks=set())
@pytest.mark.parametrize(
@@ -2801,9 +2801,9 @@ def test_transaction_update_for_draft_order_triggers_webhooks_when_fully_paid(
assert order.status == OrderStatus.DRAFT
assert order.charge_status == OrderChargeStatus.FULL
- mock_order_fully_paid.assert_called_once_with(order)
- mock_order_updated.assert_called_once_with(order)
- mock_order_paid.assert_called_once_with(order)
+ mock_order_fully_paid.assert_called_once_with(order, webhooks=set())
+ mock_order_updated.assert_called_once_with(order, webhooks=set())
+ mock_order_paid.assert_called_once_with(order, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_paid")
@@ -2851,8 +2851,8 @@ def test_transaction_update_for_order_triggers_webhook_when_partially_paid(
assert order_with_lines.charge_status == OrderChargeStatus.PARTIAL
assert not mock_order_fully_paid.called
- mock_order_updated.assert_called_once_with(order_with_lines)
- mock_order_paid.assert_called_once_with(order_with_lines)
+ mock_order_updated.assert_called_once_with(order_with_lines, webhooks=set())
+ mock_order_paid.assert_called_once_with(order_with_lines, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_updated")
@@ -2898,7 +2898,7 @@ def test_transaction_update_for_order_triggers_webhook_when_authorized(
assert order_with_lines.authorize_status == OrderAuthorizeStatus.PARTIAL
assert not mock_order_fully_paid.called
- mock_order_updated.assert_called_once_with(order_with_lines)
+ mock_order_updated.assert_called_once_with(order_with_lines, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_updated")
@@ -2942,9 +2942,9 @@ def test_transaction_update_for_order_triggers_webhooks_when_fully_refunded(
get_graphql_content(response)
- mock_order_refunded.assert_called_once_with(order_with_lines)
- mock_order_fully_refunded.assert_called_once_with(order_with_lines)
- mock_order_updated.assert_called_once_with(order_with_lines)
+ mock_order_refunded.assert_called_once_with(order_with_lines, webhooks=set())
+ mock_order_fully_refunded.assert_called_once_with(order_with_lines, webhooks=set())
+ mock_order_updated.assert_called_once_with(order_with_lines, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_updated")
@@ -2989,8 +2989,8 @@ def test_transaction_update_for_order_triggers_webhook_when_partially_refunded(
get_graphql_content(response)
assert not mock_order_fully_refunded.called
- mock_order_updated.assert_called_once_with(order_with_lines)
- mock_order_refunded.assert_called_once_with(order_with_lines)
+ mock_order_updated.assert_called_once_with(order_with_lines, webhooks=set())
+ mock_order_refunded.assert_called_once_with(order_with_lines, webhooks=set())
def test_transaction_update_by_app_assign_app_owner(
diff --git a/saleor/order/actions.py b/saleor/order/actions.py
index 03a6c4786f..fc63a9145f 100644
--- a/saleor/order/actions.py
+++ b/saleor/order/actions.py
@@ -164,7 +164,6 @@ def call_order_event(
order: "Order",
database_connection_name: str = settings.DATABASE_CONNECTION_DEFAULT_NAME,
webhook_event_map: Optional[dict[str, set["Webhook"]]] = None,
- **event_kwargs,
):
if event_name not in ORDER_WEBHOOK_EVENT_MAP:
raise ValueError(f"Event {event_name} not found in ORDER_WEBHOOK_EVENT_MAP.")
@@ -172,21 +171,24 @@ def call_order_event(
plugin_manager_method_name = ORDER_WEBHOOK_EVENT_MAP[event_name]
event_func = getattr(manager, plugin_manager_method_name)
+ if webhook_event_map is None:
+ webhook_event_map = get_webhooks_for_multiple_events(
+ [event_name, *WebhookEventSyncType.ORDER_EVENTS]
+ )
+
+ webhooks = webhook_event_map.get(event_name, set())
+
if order.status not in ORDER_EDITABLE_STATUS:
- call_event_including_protected_events(event_func, order, **event_kwargs)
+ call_event_including_protected_events(event_func, order, webhooks=webhooks)
return
if event_name == WebhookEventAsyncType.DRAFT_ORDER_DELETED:
- call_event_including_protected_events(event_func, order, **event_kwargs)
+ call_event_including_protected_events(event_func, order, webhooks=webhooks)
return
- if webhook_event_map is None:
- webhook_event_map = get_webhooks_for_multiple_events(
- [event_name, *WebhookEventSyncType.ORDER_EVENTS]
- )
if not webhook_async_event_requires_sync_webhooks_to_trigger(
event_name, webhook_event_map, WebhookEventSyncType.ORDER_EVENTS
):
- call_event_including_protected_events(event_func, order, **event_kwargs)
+ call_event_including_protected_events(event_func, order, webhooks=webhooks)
return
if (
@@ -209,7 +211,7 @@ def call_order_event(
database_connection_name=database_connection_name,
)
- call_event_including_protected_events(event_func, order, **event_kwargs)
+ call_event_including_protected_events(event_func, order, webhooks=webhooks)
return
@@ -356,16 +358,12 @@ def cancel_order(
WebhookEventAsyncType.ORDER_CANCELLED,
order,
webhook_event_map=webhook_event_map,
- webhooks=webhook_event_map.get(
- WebhookEventAsyncType.ORDER_CANCELLED, set()
- ),
)
call_order_event(
manager,
WebhookEventAsyncType.ORDER_UPDATED,
order,
webhook_event_map=webhook_event_map,
- webhooks=webhook_event_map.get(WebhookEventAsyncType.ORDER_UPDATED, set()),
)
call_event(send_order_canceled_confirmation, order, user, app, manager)
diff --git a/saleor/order/tests/test_order_actions.py b/saleor/order/tests/test_order_actions.py
index e10b54aecb..f465f7e921 100644
--- a/saleor/order/tests/test_order_actions.py
+++ b/saleor/order/tests/test_order_actions.py
@@ -1,5 +1,5 @@
from decimal import Decimal
-from unittest.mock import call, patch
+from unittest.mock import ANY, call, patch
import pytest
from django.test import override_settings
@@ -7,6 +7,7 @@ from prices import Money, TaxedMoney
from ...channel import MarkAsPaidStrategy
from ...core.models import EventDelivery
+from ...core.utils.events import call_event_including_protected_events
from ...giftcard import GiftCardEvents
from ...giftcard.models import GiftCard, GiftCardEvent
from ...order.fetch import OrderLineInfo, fetch_order_info
@@ -751,18 +752,12 @@ def test_cancel_order_dont_trigger_webhooks(
WebhookEventAsyncType.ORDER_UPDATED,
order,
webhook_event_map=webhook_event_map,
- webhooks=webhook_event_map.get(
- WebhookEventAsyncType.ORDER_UPDATED, set()
- ),
),
call(
plugins_manager,
WebhookEventAsyncType.ORDER_CANCELLED,
order,
webhook_event_map=webhook_event_map,
- webhooks=webhook_event_map.get(
- WebhookEventAsyncType.ORDER_CANCELLED, set()
- ),
),
],
any_order=True,
@@ -798,8 +793,8 @@ def test_order_refunded_by_user(
send_order_refunded_confirmation_mock.assert_called_once_with(
order, order.user, None, amount, order.currency, manager
)
- order_fully_refunded_mock.assert_called_once_with(order)
- order_refunded_mock.assert_called_once_with(order)
+ order_fully_refunded_mock.assert_called_once_with(order, webhooks=set())
+ order_refunded_mock.assert_called_once_with(order, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_refunded")
@@ -831,8 +826,8 @@ def test_order_refunded_by_app(
send_order_refunded_confirmation_mock.assert_called_once_with(
order, None, app, amount, order.currency, manager
)
- order_fully_refunded_mock.assert_called_once_with(order)
- order_refunded_mock.assert_called_once_with(order)
+ order_fully_refunded_mock.assert_called_once_with(order, webhooks=set())
+ order_refunded_mock.assert_called_once_with(order, webhooks=set())
@patch(
@@ -1681,8 +1676,8 @@ def test_order_transaction_updated_order_fully_paid(
# then
flush_post_commit_hooks()
- order_fully_paid.assert_called_once_with(order_with_lines)
- order_updated.assert_called_once_with(order_with_lines)
+ order_fully_paid.assert_called_once_with(order_with_lines, webhooks=set())
+ order_updated.assert_called_once_with(order_with_lines, webhooks=set())
@patch(
@@ -2086,7 +2081,7 @@ def test_order_transaction_updated_order_partially_paid(
# then
flush_post_commit_hooks()
assert not order_fully_paid.called
- order_updated.assert_called_once_with(order_with_lines)
+ order_updated.assert_called_once_with(order_with_lines, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_updated")
@@ -2122,7 +2117,7 @@ def test_order_transaction_updated_order_partially_paid_and_multiple_transaction
# then
flush_post_commit_hooks()
assert not order_fully_paid.called
- order_updated.assert_called_once_with(order_with_lines)
+ order_updated.assert_called_once_with(order_with_lines, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_updated")
@@ -2191,7 +2186,7 @@ def test_order_transaction_updated_order_authorized(
# then
flush_post_commit_hooks()
assert not order_fully_paid.called
- order_updated.assert_called_once_with(order_with_lines)
+ order_updated.assert_called_once_with(order_with_lines, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_updated")
@@ -2227,7 +2222,7 @@ def test_order_transaction_updated_order_partially_authorized_and_multiple_trans
# then
flush_post_commit_hooks()
assert not order_fully_paid.called
- order_updated.assert_called_once_with(order_with_lines)
+ order_updated.assert_called_once_with(order_with_lines, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_updated")
@@ -2294,8 +2289,8 @@ def test_order_transaction_updated_order_fully_refunded(
# then
flush_post_commit_hooks()
- order_fully_refunded.assert_called_once_with(order_with_lines)
- order_refunded.assert_called_once_with(order_with_lines)
+ order_fully_refunded.assert_called_once_with(order_with_lines, webhooks=set())
+ order_refunded.assert_called_once_with(order_with_lines, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_refunded")
@@ -2328,7 +2323,7 @@ def test_order_transaction_updated_order_partially_refunded(
# then
flush_post_commit_hooks()
assert not order_fully_refunded.called
- order_refunded.assert_called_once_with(order_with_lines)
+ order_refunded.assert_called_once_with(order_with_lines, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_refunded")
@@ -2364,8 +2359,8 @@ def test_order_transaction_updated_order_fully_refunded_and_multiple_transaction
# then
flush_post_commit_hooks()
- order_fully_refunded.assert_called_once_with(order_with_lines)
- order_refunded.assert_called_once_with(order_with_lines)
+ order_fully_refunded.assert_called_once_with(order_with_lines, webhooks=set())
+ order_refunded.assert_called_once_with(order_with_lines, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_refunded")
@@ -2417,8 +2412,8 @@ def test_order_transaction_updated_order_fully_refunded_with_transaction_and_pay
# then
flush_post_commit_hooks()
- order_refunded.assert_called_once_with(order_with_lines)
- order_fully_refunded.assert_called_once_with(order_with_lines)
+ order_refunded.assert_called_once_with(order_with_lines, webhooks=set())
+ order_fully_refunded.assert_called_once_with(order_with_lines, webhooks=set())
@pytest.mark.parametrize(
@@ -2441,8 +2436,13 @@ def test_order_transaction_updated_order_fully_refunded_with_transaction_and_pay
@patch(
"saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
)
+@patch(
+ "saleor.order.actions.call_event_including_protected_events",
+ wraps=call_event_including_protected_events,
+)
@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
def test_call_order_event_for_order_event_triggers_sync_webhook(
+ mocked_call_event_including_protected_events,
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
setup_order_webhooks,
@@ -2494,6 +2494,9 @@ def test_call_order_event_for_order_event_triggers_sync_webhook(
call(filter_shipping_delivery, timeout=settings.WEBHOOK_SYNC_TIMEOUT),
]
)
+ mocked_call_event_including_protected_events.assert_called_once_with(
+ ANY, order_with_lines, webhooks={order_webhook}
+ )
@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
@@ -2557,8 +2560,13 @@ def test_call_order_event_incorrect_webhook_event(
@patch(
"saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
)
+@patch(
+ "saleor.order.actions.call_event_including_protected_events",
+ wraps=call_event_including_protected_events,
+)
@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
def test_call_order_event_for_order_event_missing_filter_shipping_method_webhook(
+ mocked_call_event_including_protected_events,
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
setup_order_webhooks,
@@ -2609,6 +2617,9 @@ def test_call_order_event_for_order_event_missing_filter_shipping_method_webhook
retry_kwargs={"max_retries": 5},
)
mocked_send_webhook_request_sync.assert_called_once_with(tax_delivery)
+ mocked_call_event_including_protected_events.assert_called_once_with(
+ ANY, order_with_lines, webhooks={order_webhook}
+ )
@pytest.mark.parametrize(
@@ -2633,8 +2644,13 @@ def test_call_order_event_for_order_event_missing_filter_shipping_method_webhook
@patch(
"saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
)
+@patch(
+ "saleor.order.actions.call_event_including_protected_events",
+ wraps=call_event_including_protected_events,
+)
@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
def test_call_order_event_for_order_event_skips_tax_webhook_when_prices_are_valid(
+ mocked_call_event_including_protected_events,
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
setup_order_webhooks,
@@ -2686,6 +2702,9 @@ def test_call_order_event_for_order_event_skips_tax_webhook_when_prices_are_vali
mocked_send_webhook_request_sync.assert_called_once_with(
filter_shipping_delivery, timeout=settings.WEBHOOK_SYNC_TIMEOUT
)
+ mocked_call_event_including_protected_events.assert_called_once_with(
+ ANY, order_with_lines, webhooks={order_webhook}
+ )
@pytest.mark.parametrize(
@@ -2710,8 +2729,13 @@ def test_call_order_event_for_order_event_skips_tax_webhook_when_prices_are_vali
@patch(
"saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
)
+@patch(
+ "saleor.order.actions.call_event_including_protected_events",
+ wraps=call_event_including_protected_events,
+)
@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
def test_call_order_event_for_order_event_skips_sync_webhooks_when_order_not_editable(
+ mocked_call_event_including_protected_events,
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
setup_order_webhooks,
@@ -2762,14 +2786,22 @@ def test_call_order_event_for_order_event_skips_sync_webhooks_when_order_not_edi
retry_kwargs={"max_retries": 5},
)
assert not mocked_send_webhook_request_sync.called
+ mocked_call_event_including_protected_events.assert_called_once_with(
+ ANY, order_with_lines, webhooks={order_webhook}
+ )
@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
@patch(
"saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
)
+@patch(
+ "saleor.order.actions.call_event_including_protected_events",
+ wraps=call_event_including_protected_events,
+)
@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
def test_call_order_event_for_order_event_skips_sync_webhooks_when_draft_order_deleted(
+ mocked_call_event_including_protected_events,
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
setup_order_webhooks,
@@ -2815,6 +2847,9 @@ def test_call_order_event_for_order_event_skips_sync_webhooks_when_draft_order_d
retry_kwargs={"max_retries": 5},
)
assert not mocked_send_webhook_request_sync.called
+ mocked_call_event_including_protected_events.assert_called_once_with(
+ ANY, order_with_lines, webhooks={order_webhook}
+ )
@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
@@ -2868,8 +2903,13 @@ def test_call_order_event_for_order_event_skips_when_async_webhooks_missing(
@patch(
"saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
)
+@patch(
+ "saleor.order.actions.call_event_including_protected_events",
+ wraps=call_event_including_protected_events,
+)
@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
def test_call_order_event_for_order_event_skips_when_sync_webhooks_missing(
+ mocked_call_event_including_protected_events,
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
order_with_lines,
@@ -2907,6 +2947,9 @@ def test_call_order_event_for_order_event_skips_when_sync_webhooks_missing(
retry_kwargs={"max_retries": 5},
)
assert not mocked_send_webhook_request_sync.called
+ mocked_call_event_including_protected_events.assert_called_once_with(
+ plugins_manager.order_created, order_with_lines, webhooks={webhook}
+ )
@patch(
diff --git a/saleor/order/tests/test_order_actions_create_fulfillments_for_returned_products.py b/saleor/order/tests/test_order_actions_create_fulfillments_for_returned_products.py
index 421d1b0cdb..c37441f557 100644
--- a/saleor/order/tests/test_order_actions_create_fulfillments_for_returned_products.py
+++ b/saleor/order/tests/test_order_actions_create_fulfillments_for_returned_products.py
@@ -84,7 +84,7 @@ def test_create_return_fulfillment_only_order_lines(
assert order_lines_to_return.filter(id=event_lines[1]["line_pk"]).exists()
assert event_lines[1]["quantity"] == 2
- mocked_order_updated.assert_called_once_with(order_with_lines)
+ mocked_order_updated.assert_called_once_with(order_with_lines, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_updated")
@@ -160,7 +160,7 @@ def test_create_return_fulfillment_only_order_lines_with_refund(
assert returned_fulfillment.total_refund_amount == amount
assert returned_fulfillment.shipping_refund_amount is None
- mocked_order_updated.assert_called_once_with(order_with_lines)
+ mocked_order_updated.assert_called_once_with(order_with_lines, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_updated")
@@ -242,7 +242,7 @@ def test_create_return_fulfillment_only_order_lines_included_shipping_costs(
== order_with_lines.shipping_price_gross_amount
)
- mocked_order_updated.assert_called_once_with(order_with_lines)
+ mocked_order_updated.assert_called_once_with(order_with_lines, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_updated")
@@ -373,7 +373,7 @@ def test_create_return_fulfillment_only_order_lines_with_replace_request(
)
assert replaced_line.tax_rate == expected_replaced_line.tax_rate
- mocked_order_updated.assert_called_once_with(order_with_lines)
+ mocked_order_updated.assert_called_once_with(order_with_lines, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_updated")
@@ -421,7 +421,7 @@ def test_create_return_fulfillment_only_fulfillment_lines(
assert not mocked_refund.called
assert not replace_order
- mocked_order_updated.assert_called_once_with(fulfilled_order)
+ mocked_order_updated.assert_called_once_with(fulfilled_order, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_updated")
@@ -528,7 +528,7 @@ def test_create_return_fulfillment_only_fulfillment_lines_replace_order(
)
assert replaced_line.tax_rate == expected_replaced_line.tax_rate
- mocked_order_updated.assert_called_once_with(fulfilled_order)
+ mocked_order_updated.assert_called_once_with(fulfilled_order, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_updated")
@@ -636,7 +636,7 @@ def test_create_return_fulfillment_with_lines_already_refunded(
assert returned_and_refunded_fulfillment.total_refund_amount == amount
assert returned_and_refunded_fulfillment.shipping_refund_amount is None
- mocked_order_updated.assert_called_once_with(fulfilled_order)
+ mocked_order_updated.assert_called_once_with(fulfilled_order, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_updated")
@@ -712,4 +712,4 @@ def test_create_return_fulfillment_only_order_lines_with_old_ids(
assert order_lines_to_return.filter(id=event_lines[1]["line_pk"]).exists()
assert event_lines[1]["quantity"] == 2
- mocked_order_updated.assert_called_once_with(order_with_lines)
+ mocked_order_updated.assert_called_once_with(order_with_lines, webhooks=set())
diff --git a/saleor/order/tests/test_order_actions_refund_products.py b/saleor/order/tests/test_order_actions_refund_products.py
index 91763f3361..0059e1f0c8 100644
--- a/saleor/order/tests/test_order_actions_refund_products.py
+++ b/saleor/order/tests/test_order_actions_refund_products.py
@@ -79,7 +79,7 @@ def test_create_refund_fulfillment_only_order_lines(
order_lines_to_refund=order_refund_lines,
),
)
- mocked_order_updated.assert_called_once_with(order_with_lines)
+ mocked_order_updated.assert_called_once_with(order_with_lines, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_updated")
@@ -141,7 +141,7 @@ def test_create_refund_fulfillment_included_shipping_costs(
refund_shipping_costs=True,
),
)
- mocked_order_updated.assert_called_once_with(order_with_lines)
+ mocked_order_updated.assert_called_once_with(order_with_lines, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_updated")
@@ -195,7 +195,7 @@ def test_create_refund_fulfillment_only_fulfillment_lines(
fulfillment_lines_to_refund=fulfillment_refund_lines,
),
)
- mocked_order_updated.assert_called_once_with(fulfilled_order)
+ mocked_order_updated.assert_called_once_with(fulfilled_order, webhooks=set())
assert returned_fulfillemnt.total_refund_amount == amount
assert returned_fulfillemnt.shipping_refund_amount is None
@@ -252,7 +252,7 @@ def test_create_refund_fulfillment_custom_amount(
refund_amount_is_automatically_calculated=False,
),
)
- mocked_order_updated.assert_called_once_with(fulfilled_order)
+ mocked_order_updated.assert_called_once_with(fulfilled_order, webhooks=set())
assert returned_fulfillemnt.total_refund_amount == amount
assert returned_fulfillemnt.shipping_refund_amount is None
diff --git a/saleor/payment/tests/test_utils.py b/saleor/payment/tests/test_utils.py
index 49e0901334..4ba3bc690e 100644
--- a/saleor/payment/tests/test_utils.py
+++ b/saleor/payment/tests/test_utils.py
@@ -707,9 +707,9 @@ def test_create_transaction_event_from_request_triggers_webhooks_when_fully_paid
flush_post_commit_hooks()
order.refresh_from_db()
assert order.charge_status == OrderChargeStatus.FULL
- mock_order_fully_paid.assert_called_once_with(order)
- mock_order_updated.assert_called_once_with(order)
- mock_order_paid.assert_called_once_with(order)
+ mock_order_fully_paid.assert_called_once_with(order, webhooks=set())
+ mock_order_updated.assert_called_once_with(order, webhooks=set())
+ mock_order_paid.assert_called_once_with(order, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_paid")
@@ -755,8 +755,8 @@ def test_create_transaction_event_from_request_triggers_webhooks_when_partially_
order.refresh_from_db()
assert order_with_lines.charge_status == OrderChargeStatus.PARTIAL
assert not mock_order_fully_paid.called
- mock_order_updated.assert_called_once_with(order_with_lines)
- mock_order_paid.assert_called_once_with(order)
+ mock_order_updated.assert_called_once_with(order_with_lines, webhooks=set())
+ mock_order_paid.assert_called_once_with(order, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_refunded")
@@ -801,9 +801,9 @@ def test_create_transaction_event_from_request_triggers_webhooks_when_fully_refu
flush_post_commit_hooks()
order.refresh_from_db()
- mock_order_fully_refunded.assert_called_once_with(order)
- mock_order_updated.assert_called_once_with(order)
- mock_order_refunded.assert_called_once_with(order)
+ mock_order_fully_refunded.assert_called_once_with(order, webhooks=set())
+ mock_order_updated.assert_called_once_with(order, webhooks=set())
+ mock_order_refunded.assert_called_once_with(order, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_refunded")
@@ -849,8 +849,8 @@ def test_create_transaction_event_from_request_triggers_webhooks_partially_refun
order.refresh_from_db()
assert not mock_order_fully_refunded.called
- mock_order_updated.assert_called_once_with(order_with_lines)
- mock_order_refunded.assert_called_once_with(order)
+ mock_order_updated.assert_called_once_with(order_with_lines, webhooks=set())
+ mock_order_refunded.assert_called_once_with(order, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_updated")
@@ -894,7 +894,7 @@ def test_create_transaction_event_from_request_triggers_webhooks_when_authorized
order.refresh_from_db()
assert order_with_lines.authorize_status == OrderAuthorizeStatus.FULL
assert not mock_order_fully_paid.called
- mock_order_updated.assert_called_once_with(order_with_lines)
+ mock_order_updated.assert_called_once_with(order_with_lines, webhooks=set())
@freeze_time("2018-05-31 12:00:01")
@@ -1958,7 +1958,7 @@ def test_create_transaction_event_for_transaction_session_call_webhook_order_upd
order_with_lines.refresh_from_db()
flush_post_commit_hooks()
assert not mock_order_fully_paid.called
- mock_order_updated.assert_called_once_with(order_with_lines)
+ mock_order_updated.assert_called_once_with(order_with_lines, webhooks=set())
@patch("saleor.plugins.manager.PluginsManager.order_updated")
@@ -1992,8 +1992,8 @@ def test_create_transaction_event_for_transaction_session_call_webhook_for_fully
# then
order_with_lines.refresh_from_db()
flush_post_commit_hooks()
- mock_order_fully_paid.assert_called_once_with(order_with_lines)
- mock_order_updated.assert_called_once_with(order_with_lines)
+ mock_order_fully_paid.assert_called_once_with(order_with_lines, webhooks=set())
+ mock_order_updated.assert_called_once_with(order_with_lines, webhooks=set())
@pytest.mark.parametrize(
diff --git a/saleor/plugins/avatax/plugin.py b/saleor/plugins/avatax/plugin.py
index 1989a939d1..1f2ffc0ae1 100644
--- a/saleor/plugins/avatax/plugin.py
+++ b/saleor/plugins/avatax/plugin.py
@@ -365,7 +365,9 @@ class AvataxPlugin(BasePlugin):
raise TaxError(customer_msg)
return previous_value
- def order_confirmed(self, order: "Order", previous_value: Any) -> Any:
+ def order_confirmed(
+ self, order: "Order", previous_value: Any, webhooks=None
+ ) -> Any:
if not self.active:
return previous_value
tax_strategy = get_tax_calculation_strategy_for_order(order)
diff --git a/saleor/plugins/base_plugin.py b/saleor/plugins/base_plugin.py
index 4658e0146a..161f0c98ef 100644
--- a/saleor/plugins/base_plugin.py
+++ b/saleor/plugins/base_plugin.py
@@ -3,13 +3,7 @@ from collections.abc import Iterable
from copy import copy
from dataclasses import dataclass
from decimal import Decimal
-from typing import (
- TYPE_CHECKING,
- Any,
- Callable,
- Optional,
- Union,
-)
+from typing import TYPE_CHECKING, Any, Callable, Optional, Union
from django.core.handlers.wsgi import WSGIRequest
from django.http import HttpResponse
@@ -451,25 +445,25 @@ class BasePlugin:
#
# Overwrite this method if you need to trigger specific logic when a checkout is
# created.
- checkout_created: Callable[["Checkout", Any], Any]
+ checkout_created: Callable[["Checkout", Any, None], Any]
# Trigger when checkout is updated.
#
# Overwrite this method if you need to trigger specific logic when a checkout is
# updated.
- checkout_updated: Callable[["Checkout", Any], Any]
+ checkout_updated: Callable[["Checkout", Any, None], Any]
# Trigger when checkout is fully paid with transactions.
#
# Overwrite this method if you need to trigger specific logic when a checkout is
# updated.
- checkout_fully_paid: Callable[["Checkout", Any], Any]
+ checkout_fully_paid: Callable[["Checkout", Any, None], Any]
# Trigger when checkout metadata is updated.
#
# Overwrite this method if you need to trigger specific logic when a checkout
# metadata is updated.
- checkout_metadata_updated: Callable[["Checkout", Any], Any]
+ checkout_metadata_updated: Callable[["Checkout", Any, None], Any]
# Trigger when collection is created.
#
@@ -675,6 +669,24 @@ class BasePlugin:
# export is completed.
gift_card_export_completed: Callable[["ExportFile", None], None]
+ # Trigger when draft order is created.
+ #
+ # Overwrite this method if you need to trigger specific logic after an order is
+ # created.
+ draft_order_created: Callable[["Order", Any, None], Any]
+
+ # Trigger when draft order is updated.
+ #
+ # Overwrite this method if you need to trigger specific logic when an order is
+ # changed.
+ draft_order_updated: Callable[["Order", Any, None], Any]
+
+ # Trigger when draft order is deleted.
+ #
+ # Overwrite this method if you need to trigger specific logic when an order is
+ # changed.
+ draft_order_deleted: Callable[["Order", Any, None], Any]
+
initialize_payment: Callable[
[dict, Optional[InitializedPaymentResponse]], InitializedPaymentResponse
]
@@ -785,49 +797,49 @@ class BasePlugin:
#
# Overwrite this method if you need to trigger specific logic when an order is
# expired.
- order_expired: Callable[["Order", Any], Any]
+ order_expired: Callable[["Order", Any, None], Any]
# Trigger when order is confirmed by staff.
#
# Overwrite this method if you need to trigger specific logic after an order is
# confirmed.
- order_confirmed: Callable[["Order", Any], Any]
+ order_confirmed: Callable[["Order", Any, None], Any]
# Trigger when order is created.
#
# Overwrite this method if you need to trigger specific logic after an order is
# created.
- order_created: Callable[["Order", Any], Any]
+ order_created: Callable[["Order", Any, None], Any]
# Trigger when order is fulfilled.
#
# Overwrite this method if you need to trigger specific logic when an order is
# fulfilled.
- order_fulfilled: Callable[["Order", Any], Any]
+ order_fulfilled: Callable[["Order", Any, None], Any]
# Trigger when order is fully paid.
#
# Overwrite this method if you need to trigger specific logic when an order is
# fully paid.
- order_fully_paid: Callable[["Order", Any], Any]
+ order_fully_paid: Callable[["Order", Any, None], Any]
# Trigger when order is paid.
#
# Overwrite this method if you need to trigger specific logic when an order is
# received the payment.
- order_paid: Callable[["Order", Any], Any]
+ order_paid: Callable[["Order", Any, None], Any]
# Trigger when order is refunded.
#
# Overwrite this method if you need to trigger specific logic when an order is
# refunded.
- order_refunded: Callable[["Order", Any], Any]
+ order_refunded: Callable[["Order", Any, None], Any]
# Trigger when order is fully refunded.
#
# Overwrite this method if you need to trigger specific logic when an order is
# fully refunded.
- order_fully_refunded: Callable[["Order", Any], Any]
+ order_fully_refunded: Callable[["Order", Any, None], Any]
# Trigger when order is updated.
#
@@ -839,7 +851,7 @@ class BasePlugin:
#
# Overwrite this method if you need to trigger specific logic when an order
# metadata is changed.
- order_metadata_updated: Callable[["Order", Any], Any]
+ order_metadata_updated: Callable[["Order", Any, None], Any]
# Trigger when orders are imported.
#
diff --git a/saleor/plugins/manager.py b/saleor/plugins/manager.py
index 9e57a3809d..faaf4cc9c9 100644
--- a/saleor/plugins/manager.py
+++ b/saleor/plugins/manager.py
@@ -885,10 +885,14 @@ class PluginsManager(PaymentInterface):
"product_export_completed", default_value, export, channel_slug=None
)
- def order_created(self, order: "Order"):
+ def order_created(self, order: "Order", webhooks=None):
default_value = None
return self.__run_method_on_plugins(
- "order_created", default_value, order, channel_slug=order.channel.slug
+ "order_created",
+ default_value,
+ order,
+ channel_slug=order.channel.slug,
+ webhooks=webhooks,
)
def event_delivery_retry(self, event_delivery: "EventDelivery"):
@@ -897,28 +901,44 @@ class PluginsManager(PaymentInterface):
"event_delivery_retry", default_value, event_delivery, channel_slug=None
)
- def order_confirmed(self, order: "Order"):
+ def order_confirmed(self, order: "Order", webhooks=None):
default_value = None
return self.__run_method_on_plugins(
- "order_confirmed", default_value, order, channel_slug=order.channel.slug
+ "order_confirmed",
+ default_value,
+ order,
+ channel_slug=order.channel.slug,
+ webhooks=webhooks,
)
- def draft_order_created(self, order: "Order"):
+ def draft_order_created(self, order: "Order", webhooks=None):
default_value = None
return self.__run_method_on_plugins(
- "draft_order_created", default_value, order, channel_slug=order.channel.slug
+ "draft_order_created",
+ default_value,
+ order,
+ channel_slug=order.channel.slug,
+ webhooks=webhooks,
)
- def draft_order_updated(self, order: "Order"):
+ def draft_order_updated(self, order: "Order", webhooks=None):
default_value = None
return self.__run_method_on_plugins(
- "draft_order_updated", default_value, order, channel_slug=order.channel.slug
+ "draft_order_updated",
+ default_value,
+ order,
+ channel_slug=order.channel.slug,
+ webhooks=webhooks,
)
- def draft_order_deleted(self, order: "Order"):
+ def draft_order_deleted(self, order: "Order", webhooks=None):
default_value = None
return self.__run_method_on_plugins(
- "draft_order_deleted", default_value, order, channel_slug=order.channel.slug
+ "draft_order_deleted",
+ default_value,
+ order,
+ channel_slug=order.channel.slug,
+ webhooks=webhooks,
)
def sale_created(self, sale: "Promotion", current_catalogue):
@@ -1054,31 +1074,44 @@ class PluginsManager(PaymentInterface):
channel_slug=channel_slug,
)
- def order_fully_paid(self, order: "Order"):
+ def order_fully_paid(self, order: "Order", webhooks=None):
default_value = None
return self.__run_method_on_plugins(
- "order_fully_paid", default_value, order, channel_slug=order.channel.slug
+ "order_fully_paid",
+ default_value,
+ order,
+ channel_slug=order.channel.slug,
+ webhooks=webhooks,
)
- def order_paid(self, order: "Order"):
+ def order_paid(self, order: "Order", webhooks=None):
default_value = None
return self.__run_method_on_plugins(
- "order_paid", default_value, order, channel_slug=order.channel.slug
+ "order_paid",
+ default_value,
+ order,
+ channel_slug=order.channel.slug,
+ webhooks=webhooks,
)
- def order_fully_refunded(self, order: "Order"):
+ def order_fully_refunded(self, order: "Order", webhooks=None):
default_value = None
return self.__run_method_on_plugins(
"order_fully_refunded",
default_value,
order,
channel_slug=order.channel.slug,
+ webhooks=webhooks,
)
- def order_refunded(self, order: "Order"):
+ def order_refunded(self, order: "Order", webhooks=None):
default_value = None
return self.__run_method_on_plugins(
- "order_refunded", default_value, order, channel_slug=order.channel.slug
+ "order_refunded",
+ default_value,
+ order,
+ channel_slug=order.channel.slug,
+ webhooks=webhooks,
)
def order_updated(self, order: "Order", webhooks=None):
@@ -1111,19 +1144,24 @@ class PluginsManager(PaymentInterface):
webhooks=webhooks,
)
- def order_fulfilled(self, order: "Order"):
+ def order_fulfilled(self, order: "Order", webhooks=None):
default_value = None
return self.__run_method_on_plugins(
- "order_fulfilled", default_value, order, channel_slug=order.channel.slug
+ "order_fulfilled",
+ default_value,
+ order,
+ channel_slug=order.channel.slug,
+ webhooks=webhooks,
)
- def order_metadata_updated(self, order: "Order"):
+ def order_metadata_updated(self, order: "Order", webhooks=None):
default_value = None
return self.__run_method_on_plugins(
"order_metadata_updated",
default_value,
order,
channel_slug=order.channel.slug,
+ webhooks=webhooks,
)
def order_bulk_created(self, orders: list["Order"]):
@@ -1183,40 +1221,44 @@ class PluginsManager(PaymentInterface):
channel_slug=fulfillment.order.channel.slug,
)
- def checkout_created(self, checkout: "Checkout"):
+ def checkout_created(self, checkout: "Checkout", webhooks=None):
default_value = None
return self.__run_method_on_plugins(
"checkout_created",
default_value,
checkout,
channel_slug=checkout.channel.slug,
+ webhooks=webhooks,
)
- def checkout_updated(self, checkout: "Checkout"):
+ def checkout_updated(self, checkout: "Checkout", webhooks=None):
default_value = None
return self.__run_method_on_plugins(
"checkout_updated",
default_value,
checkout,
channel_slug=checkout.channel.slug,
+ webhooks=webhooks,
)
- def checkout_fully_paid(self, checkout: "Checkout"):
+ def checkout_fully_paid(self, checkout: "Checkout", webhooks=None):
default_value = None
return self.__run_method_on_plugins(
"checkout_fully_paid",
default_value,
checkout,
channel_slug=checkout.channel.slug,
+ webhooks=webhooks,
)
- def checkout_metadata_updated(self, checkout: "Checkout"):
+ def checkout_metadata_updated(self, checkout: "Checkout", webhooks=None):
default_value = None
return self.__run_method_on_plugins(
"checkout_metadata_updated",
default_value,
checkout,
channel_slug=checkout.channel.slug,
+ webhooks=webhooks,
)
def page_created(self, page: "Page"):
diff --git a/saleor/plugins/tests/sample_plugins.py b/saleor/plugins/tests/sample_plugins.py
index 8a5b100e61..defbe10777 100644
--- a/saleor/plugins/tests/sample_plugins.py
+++ b/saleor/plugins/tests/sample_plugins.py
@@ -1,12 +1,7 @@
from collections import defaultdict
from collections.abc import Iterable
from decimal import Decimal
-from typing import (
- TYPE_CHECKING,
- Any,
- Optional,
- Union,
-)
+from typing import TYPE_CHECKING, Any, Optional, Union
from django.core.handlers.wsgi import WSGIRequest
from django.http import HttpResponse, HttpResponseNotFound, JsonResponse
@@ -337,16 +332,16 @@ class PluginSample(BasePlugin):
app_identifier="321", response=None, error="Some error"
)
- def checkout_fully_paid(self, checkout, previous_value):
+ def checkout_fully_paid(self, checkout, previous_value, webhooks):
return None
- def order_fully_refunded(self, order, previous_value):
+ def order_fully_refunded(self, order, previous_value, webhooks):
return None
def order_paid(self, order, previous_value):
return None
- def order_refunded(self, order, previous_value):
+ def order_refunded(self, order, previous_value, webhooks):
return None
def list_stored_payment_methods(
diff --git a/saleor/plugins/tests/test_manager.py b/saleor/plugins/tests/test_manager.py
index 5f19af9c65..be0542cbfa 100644
--- a/saleor/plugins/tests/test_manager.py
+++ b/saleor/plugins/tests/test_manager.py
@@ -1303,7 +1303,7 @@ def test_manager_transaction_process_session(
@patch("saleor.plugins.tests.sample_plugins.PluginSample.checkout_fully_paid")
-def test_checkout_fully_paid(mocked_sample_method, checkout):
+def test_checkout_fully_paid(mocked_sample_method, checkout, webhook):
# given
plugins = [
"saleor.plugins.tests.sample_plugins.PluginSample",
@@ -1311,16 +1311,19 @@ def test_checkout_fully_paid(mocked_sample_method, checkout):
]
manager = PluginsManager(plugins=plugins)
+ webhooks = {webhook}
# when
- manager.checkout_fully_paid(checkout)
+ manager.checkout_fully_paid(checkout, webhooks=webhooks)
# then
- mocked_sample_method.assert_called_once_with(checkout, previous_value=None)
+ mocked_sample_method.assert_called_once_with(
+ checkout, previous_value=None, webhooks=webhooks
+ )
@patch("saleor.plugins.tests.sample_plugins.PluginSample.order_fully_refunded")
-def test_order_fully_refunded(mocked_sample_method, order):
+def test_order_fully_refunded(mocked_sample_method, order, webhook):
# given
plugins = [
"saleor.plugins.tests.sample_plugins.PluginSample",
@@ -1328,16 +1331,18 @@ def test_order_fully_refunded(mocked_sample_method, order):
]
manager = PluginsManager(plugins=plugins)
-
+ webhooks = {webhook}
# when
- manager.order_fully_refunded(order)
+ manager.order_fully_refunded(order, webhooks=webhooks)
# then
- mocked_sample_method.assert_called_once_with(order, previous_value=None)
+ mocked_sample_method.assert_called_once_with(
+ order, previous_value=None, webhooks=webhooks
+ )
@patch("saleor.plugins.tests.sample_plugins.PluginSample.order_refunded")
-def test_order_refunded(mocked_sample_method, order):
+def test_order_refunded(mocked_sample_method, order, webhook):
# given
plugins = [
"saleor.plugins.tests.sample_plugins.PluginSample",
@@ -1345,16 +1350,19 @@ def test_order_refunded(mocked_sample_method, order):
]
manager = PluginsManager(plugins=plugins)
+ webhooks = {webhook}
# when
- manager.order_refunded(order)
+ manager.order_refunded(order, webhooks=webhooks)
# then
- mocked_sample_method.assert_called_once_with(order, previous_value=None)
+ mocked_sample_method.assert_called_once_with(
+ order, previous_value=None, webhooks=webhooks
+ )
@patch("saleor.plugins.tests.sample_plugins.PluginSample.order_paid")
-def test_order_paid(mocked_sample_method, order):
+def test_order_paid(mocked_sample_method, order, webhook):
# given
plugins = [
"saleor.plugins.tests.sample_plugins.PluginSample",
@@ -1362,12 +1370,15 @@ def test_order_paid(mocked_sample_method, order):
]
manager = PluginsManager(plugins=plugins)
+ webhooks = {webhook}
# when
- manager.order_paid(order)
+ manager.order_paid(order, webhooks=webhooks)
# then
- mocked_sample_method.assert_called_once_with(order, previous_value=None)
+ mocked_sample_method.assert_called_once_with(
+ order, previous_value=None, webhooks=webhooks
+ )
@patch("saleor.plugins.tests.sample_plugins.PluginSample.list_stored_payment_methods")
diff --git a/saleor/plugins/webhook/plugin.py b/saleor/plugins/webhook/plugin.py
index 23e1186a32..3938160c3e 100644
--- a/saleor/plugins/webhook/plugin.py
+++ b/saleor/plugins/webhook/plugin.py
@@ -728,11 +728,11 @@ class WebhookPlugin(BasePlugin):
export,
)
- def order_created(self, order: "Order", previous_value: Any) -> Any:
+ def order_created(self, order: "Order", previous_value: Any, webhooks=None) -> Any:
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.ORDER_CREATED
- if webhooks := get_webhooks_for_event(event_type):
+ if webhooks := self._get_webhooks_for_event(event_type, webhooks):
order_data_generator = partial(
generate_order_payload, order, self.requestor
)
@@ -819,11 +819,13 @@ class WebhookPlugin(BasePlugin):
WebhookEventAsyncType.MENU_ITEM_DELETED, menu_item, webhooks=webhooks
)
- def order_confirmed(self, order: "Order", previous_value: Any) -> Any:
+ def order_confirmed(
+ self, order: "Order", previous_value: Any, webhooks=None
+ ) -> Any:
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.ORDER_CONFIRMED
- if webhooks := get_webhooks_for_event(event_type):
+ if webhooks := self._get_webhooks_for_event(event_type, webhooks):
order_data_generator = partial(
generate_order_payload, order, self.requestor
)
@@ -837,11 +839,13 @@ class WebhookPlugin(BasePlugin):
queue=settings.ORDER_WEBHOOK_EVENTS_CELERY_QUEUE_NAME,
)
- def order_fully_paid(self, order: "Order", previous_value: Any) -> Any:
+ def order_fully_paid(
+ self, order: "Order", previous_value: Any, webhooks=None
+ ) -> Any:
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.ORDER_FULLY_PAID
- if webhooks := get_webhooks_for_event(event_type):
+ if webhooks := self._get_webhooks_for_event(event_type, webhooks):
order_data_generator = partial(
generate_order_payload, order, self.requestor
)
@@ -855,11 +859,11 @@ class WebhookPlugin(BasePlugin):
queue=settings.ORDER_WEBHOOK_EVENTS_CELERY_QUEUE_NAME,
)
- def order_paid(self, order: "Order", previous_value: Any) -> Any:
+ def order_paid(self, order: "Order", previous_value: Any, webhooks=None) -> Any:
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.ORDER_PAID
- if webhooks := get_webhooks_for_event(event_type):
+ if webhooks := self._get_webhooks_for_event(event_type, webhooks):
order_data_generator = partial(
generate_order_payload, order, self.requestor
)
@@ -873,11 +877,11 @@ class WebhookPlugin(BasePlugin):
queue=settings.ORDER_WEBHOOK_EVENTS_CELERY_QUEUE_NAME,
)
- def order_refunded(self, order: "Order", previous_value: Any) -> Any:
+ def order_refunded(self, order: "Order", previous_value: Any, webhooks=None) -> Any:
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.ORDER_REFUNDED
- if webhooks := get_webhooks_for_event(event_type):
+ if webhooks := self._get_webhooks_for_event(event_type, webhooks):
order_data_generator = partial(
generate_order_payload, order, self.requestor
)
@@ -891,11 +895,13 @@ class WebhookPlugin(BasePlugin):
queue=settings.ORDER_WEBHOOK_EVENTS_CELERY_QUEUE_NAME,
)
- def order_fully_refunded(self, order: "Order", previous_value: Any) -> Any:
+ def order_fully_refunded(
+ self, order: "Order", previous_value: Any, webhooks=None
+ ) -> Any:
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.ORDER_FULLY_REFUNDED
- if webhooks := get_webhooks_for_event(event_type):
+ if webhooks := self._get_webhooks_for_event(event_type, webhooks):
order_data_generator = partial(
generate_order_payload, order, self.requestor
)
@@ -1247,11 +1253,13 @@ class WebhookPlugin(BasePlugin):
queue=settings.ORDER_WEBHOOK_EVENTS_CELERY_QUEUE_NAME,
)
- def order_fulfilled(self, order: "Order", previous_value: Any) -> Any:
+ def order_fulfilled(
+ self, order: "Order", previous_value: Any, webhooks=None
+ ) -> Any:
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.ORDER_FULFILLED
- if webhooks := get_webhooks_for_event(event_type):
+ if webhooks := self._get_webhooks_for_event(event_type, webhooks):
order_data_generator = partial(
generate_order_payload, order, self.requestor
)
@@ -1265,12 +1273,15 @@ class WebhookPlugin(BasePlugin):
queue=settings.ORDER_WEBHOOK_EVENTS_CELERY_QUEUE_NAME,
)
- def order_metadata_updated(self, order: "Order", previous_value: Any) -> Any:
+ def order_metadata_updated(
+ self, order: "Order", previous_value: Any, webhooks=None
+ ) -> Any:
if not self.active:
return previous_value
self._trigger_metadata_updated_event(
WebhookEventAsyncType.ORDER_METADATA_UPDATED,
order,
+ webhooks=webhooks,
queue=settings.ORDER_WEBHOOK_EVENTS_CELERY_QUEUE_NAME,
)
@@ -1295,11 +1306,13 @@ class WebhookPlugin(BasePlugin):
queue=settings.ORDER_WEBHOOK_EVENTS_CELERY_QUEUE_NAME,
)
- def draft_order_created(self, order: "Order", previous_value: Any) -> Any:
+ def draft_order_created(
+ self, order: "Order", previous_value: Any, webhooks=None
+ ) -> Any:
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.DRAFT_ORDER_CREATED
- if webhooks := get_webhooks_for_event(event_type):
+ if webhooks := self._get_webhooks_for_event(event_type, webhooks):
order_data_generator = partial(
generate_order_payload, order, self.requestor
)
@@ -1313,11 +1326,13 @@ class WebhookPlugin(BasePlugin):
queue=settings.ORDER_WEBHOOK_EVENTS_CELERY_QUEUE_NAME,
)
- def draft_order_updated(self, order: "Order", previous_value: Any) -> Any:
+ def draft_order_updated(
+ self, order: "Order", previous_value: Any, webhooks=None
+ ) -> Any:
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.DRAFT_ORDER_UPDATED
- if webhooks := get_webhooks_for_event(event_type):
+ if webhooks := self._get_webhooks_for_event(event_type, webhooks):
order_data_generator = partial(
generate_order_payload, order, self.requestor
)
@@ -1331,11 +1346,13 @@ class WebhookPlugin(BasePlugin):
queue=settings.ORDER_WEBHOOK_EVENTS_CELERY_QUEUE_NAME,
)
- def draft_order_deleted(self, order: "Order", previous_value: Any) -> Any:
+ def draft_order_deleted(
+ self, order: "Order", previous_value: Any, webhooks=None
+ ) -> Any:
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.DRAFT_ORDER_DELETED
- if webhooks := get_webhooks_for_event(event_type):
+ if webhooks := self._get_webhooks_for_event(event_type, webhooks):
order_data_generator = partial(
generate_order_payload, order, self.requestor
)
@@ -1815,11 +1832,13 @@ class WebhookPlugin(BasePlugin):
legacy_data_generator=product_variant_data_generator,
)
- def checkout_created(self, checkout: "Checkout", previous_value: Any) -> Any:
+ def checkout_created(
+ self, checkout: "Checkout", previous_value: Any, webhooks=None
+ ) -> Any:
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.CHECKOUT_CREATED
- if webhooks := get_webhooks_for_event(event_type):
+ if webhooks := self._get_webhooks_for_event(event_type, webhooks):
checkout_data_generator = partial(
generate_checkout_payload, checkout, self.requestor
)
@@ -1833,11 +1852,13 @@ class WebhookPlugin(BasePlugin):
queue=settings.CHECKOUT_WEBHOOK_EVENTS_CELERY_QUEUE_NAME,
)
- def checkout_updated(self, checkout: "Checkout", previous_value: Any) -> Any:
+ def checkout_updated(
+ self, checkout: "Checkout", previous_value: Any, webhooks=None
+ ) -> Any:
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.CHECKOUT_UPDATED
- if webhooks := get_webhooks_for_event(event_type):
+ if webhooks := self._get_webhooks_for_event(event_type, webhooks):
checkout_data_generator = partial(
generate_checkout_payload, checkout, self.requestor
)
@@ -1851,11 +1872,13 @@ class WebhookPlugin(BasePlugin):
queue=settings.CHECKOUT_WEBHOOK_EVENTS_CELERY_QUEUE_NAME,
)
- def checkout_fully_paid(self, checkout: "Checkout", previous_value: Any) -> Any:
+ def checkout_fully_paid(
+ self, checkout: "Checkout", previous_value: Any, webhooks=None
+ ) -> Any:
if not self.active:
return previous_value
event_type = WebhookEventAsyncType.CHECKOUT_FULLY_PAID
- if webhooks := get_webhooks_for_event(event_type):
+ if webhooks := self._get_webhooks_for_event(event_type, webhooks):
checkout_data_generator = partial(
generate_checkout_payload, checkout, self.requestor
)
@@ -1870,12 +1893,12 @@ class WebhookPlugin(BasePlugin):
)
def checkout_metadata_updated(
- self, checkout: "Checkout", previous_value: Any
+ self, checkout: "Checkout", previous_value: Any, webhooks=None
) -> Any:
if not self.active:
return previous_value
self._trigger_metadata_updated_event(
- WebhookEventAsyncType.CHECKOUT_METADATA_UPDATED, checkout
+ WebhookEventAsyncType.CHECKOUT_METADATA_UPDATED, checkout, webhooks=webhooks
)
def notify(