Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
GraphQL subscription support for synchronous webhook events (#9763)
Jakub8201efcde2d7
diff --git a/saleor/checkout/fetch.py b/saleor/checkout/fetch.pyindex 9eaf6836d6..249003d6ff 100644--- a/saleor/checkout/fetch.py+++ b/saleor/checkout/fetch.py@@ -374,6 +374,7 @@ def fetch_checkout_info(shipping_channel_listings: Optional[Iterable["ShippingMethodChannelListing"]] = None,+ fetch_delivery_methods=True,) -> CheckoutInfo:"""Fetch checkout as CheckoutInfo object."""from .utils import get_voucher_for_checkout@@ -396,16 +397,17 @@ def fetch_checkout_info(valid_pick_up_points=[],voucher=voucher,)- update_delivery_method_lists_for_checkout_info(- checkout_info,- checkout.shipping_method,- checkout.collection_point,- shipping_address,- lines,- discounts,- manager,- shipping_channel_listings,- )+ if fetch_delivery_methods:+ update_delivery_method_lists_for_checkout_info(+ checkout_info,+ checkout.shipping_method,+ checkout.collection_point,+ shipping_address,+ lines,+ discounts,+ manager,+ shipping_channel_listings,+ )return checkout_info@@ -532,6 +534,30 @@ def get_valid_external_shipping_method_list_for_checkout_info()+def get_all_shipping_methods_list(+ checkout_info,+ shipping_address,+ lines,+ discounts,+ shipping_channel_listings,+ manager,+):+ return list(+ itertools.chain(+ get_valid_internal_shipping_method_list_for_checkout_info(+ checkout_info,+ shipping_address,+ lines,+ discounts,+ shipping_channel_listings,+ ),+ get_valid_external_shipping_method_list_for_checkout_info(+ checkout_info, shipping_address, lines, discounts, manager+ ),+ )+ )++def update_delivery_method_lists_for_checkout_info(checkout_info: "CheckoutInfo",shipping_method: Optional["ShippingMethod"],@@ -553,19 +579,13 @@ def update_delivery_method_lists_for_checkout_info(def _resolve_all_shipping_methods():# Fetch all shipping method from all sources, including sync webhooks- all_methods = list(- itertools.chain(- get_valid_internal_shipping_method_list_for_checkout_info(- checkout_info,- shipping_address,- lines,- discounts,- shipping_channel_listings,- ),- get_valid_external_shipping_method_list_for_checkout_info(- checkout_info, shipping_address, lines, discounts, manager- ),- )+ all_methods = get_all_shipping_methods_list(+ checkout_info,+ shipping_address,+ lines,+ discounts,+ shipping_channel_listings,+ manager,)# Filter shipping methods using sync webhooksexcluded_methods = manager.excluded_shipping_methods_for_checkout(diff --git a/saleor/core/exceptions.py b/saleor/core/exceptions.pyindex a2585e1734..95b8b86980 100644--- a/saleor/core/exceptions.py+++ b/saleor/core/exceptions.py@@ -2,6 +2,8 @@ from dataclasses import dataclassfrom enum import Enumfrom typing import TYPE_CHECKING, List, Optional, Sequence, Union+from graphql import GraphQLError+from ..checkout.error_codes import CheckoutErrorCodeif TYPE_CHECKING:@@ -73,3 +75,17 @@ class GiftCardNotApplicable(Exception):super().__init__(message)self.message = messageself.code = CheckoutErrorCode.GIFT_CARD_NOT_APPLICABLE.value+++class CircularSubscriptionSyncEvent(GraphQLError):+ pass+++class SyncEventError(Exception):+ def __init__(self, message, code=None):+ super(SyncEventError, self).__init__(message, code)+ self.message = message+ self.code = code++ def __str__(self):+ return self.messagediff --git a/saleor/graphql/checkout/types.py b/saleor/graphql/checkout/types.pyindex 46e4425ef9..4d4f2d8aa5 100644--- a/saleor/graphql/checkout/types.py+++ b/saleor/graphql/checkout/types.py@@ -54,6 +54,7 @@ from .dataloaders import (CheckoutLinesInfoByCheckoutTokenLoader,TransactionItemsByCheckoutIDLoader,)+from .utils import prevent_sync_event_circular_queryclass GatewayConfigLine(graphene.ObjectType):@@ -493,6 +494,7 @@ class Checkout(ModelObjectType):@classmethod@traced_resolver+ @prevent_sync_event_circular_querydef resolve_shipping_methods(cls, root: models.Checkout, info):return (CheckoutInfoByCheckoutTokenLoader(info.context)@@ -610,6 +612,7 @@ class Checkout(ModelObjectType):@staticmethod@traced_resolver+ @prevent_sync_event_circular_querydef resolve_available_shipping_methods(root: models.Checkout, info):return (CheckoutInfoByCheckoutTokenLoader(info.context)@@ -630,6 +633,7 @@ class Checkout(ModelObjectType):)@staticmethod+ @prevent_sync_event_circular_querydef resolve_available_payment_gateways(root: models.Checkout, info):return info.context.plugins.list_payment_gateways(currency=root.currency, checkout=root, channel_slug=root.channel.slugdiff --git a/saleor/graphql/checkout/utils.py b/saleor/graphql/checkout/utils.pyindex 179c80847a..78b99036ee 100644--- a/saleor/graphql/checkout/utils.py+++ b/saleor/graphql/checkout/utils.py@@ -1,5 +1,8 @@import graphenefrom django.core.exceptions import ValidationError+from graphql import ResolveInfo++from ...core.exceptions import CircularSubscriptionSyncEventdef prepare_insufficient_stock_checkout_validation_error(exc):@@ -13,3 +16,25 @@ def prepare_insufficient_stock_checkout_validation_error(exc):code=exc.code.value,params={"variants": variant_ids},)+++def prevent_sync_event_circular_query(func):+ """Prevent circular dependencies in synchronous events resolvers.++ Synchronous events are not allowed to request fields that are resolved using other+ synchronous events, which would lead to circular calls of the webhook.+ Using this decorator prevents such circular events resolution.++ :raises CircularSubscriptionSyncEvent: When a field being resolved from a+ synchronous webhook's payload uses another synchronous webhook internally.+ """++ def wrapper(*args, **kwargs):+ info = next(arg for arg in args if isinstance(arg, ResolveInfo))+ if getattr(info.context, "sync_event", False):+ raise CircularSubscriptionSyncEvent(+ "Resolving this field is not allowed in synchronous events."+ )+ return func(*args, **kwargs)++ return wrapperdiff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.pyindex 5139199e0d..94709fb7b3 100644--- a/saleor/graphql/order/types.py+++ b/saleor/graphql/order/types.py@@ -58,6 +58,7 @@ from ..app.types import Appfrom ..channel import ChannelContextfrom ..channel.dataloaders import ChannelByIdLoader, ChannelByOrderLineIdLoaderfrom ..channel.types import Channel+from ..checkout.utils import prevent_sync_event_circular_queryfrom ..core.connection import CountableConnectionfrom ..core.descriptions import (ADDED_IN_31,@@ -1508,6 +1509,7 @@ class Order(ModelObjectType):@classmethod@traced_resolver+ @prevent_sync_event_circular_query# TODO: We should optimize it in/after PR#5819def resolve_shipping_methods(cls, root: models.Order, info):def with_channel(channel):@@ -1526,6 +1528,7 @@ class Order(ModelObjectType):@classmethod@traced_resolver+ @prevent_sync_event_circular_query# TODO: We should optimize it in/after PR#5819def resolve_available_shipping_methods(cls, root: models.Order, info):return cls.resolve_shipping_methods(root, info).then(diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex b90e5f6801..ac6a8cc42b 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -23656,6 +23656,273 @@ type WarehouseDeleted implements Event {warehouse: Warehouse}+"""+Authorize payment.++Added in Saleor 3.6.++Note: this API is currently in Feature Preview and can be subject to changes at later point.+"""+type PaymentAuthorize implements Event {+ """Time of the event."""+ issuedAt: DateTime++ """Saleor version that triggered the event."""+ version: String++ """The user or application that triggered the event."""+ issuingPrincipal: IssuingPrincipal++ """The application receiving the webhook."""+ recipient: App++ """Look up a payment."""+ payment: Payment+}++"""+Capture payment.++Added in Saleor 3.6.++Note: this API is currently in Feature Preview and can be subject to changes at later point.+"""+type PaymentCaptureEvent implements Event {+ """Time of the event."""+ issuedAt: DateTime++ """Saleor version that triggered the event."""+ version: String++ """The user or application that triggered the event."""+ issuingPrincipal: IssuingPrincipal++ """The application receiving the webhook."""+ recipient: App++ """Look up a payment."""+ payment: Payment+}++"""+Refund payment.++Added in Saleor 3.6.++Note: this API is currently in Feature Preview and can be subject to changes at later point.+"""+type PaymentRefundEvent implements Event {+ """Time of the event."""+ issuedAt: DateTime++ """Saleor version that triggered the event."""+ version: String++ """The user or application that triggered the event."""+ issuingPrincipal: IssuingPrincipal++ """The application receiving the webhook."""+ recipient: App++ """Look up a payment."""+ payment: Payment+}++"""+Void payment.++Added in Saleor 3.6.++Note: this API is currently in Feature Preview and can be subject to changes at later point.+"""+type PaymentVoidEvent implements Event {+ """Time of the event."""+ issuedAt: DateTime++ """Saleor version that triggered the event."""+ version: String++ """The user or application that triggered the event."""+ issuingPrincipal: IssuingPrincipal++ """The application receiving the webhook."""+ recipient: App++ """Look up a payment."""+ payment: Payment+}++"""+Confirm payment.++Added in Saleor 3.6.++Note: this API is currently in Feature Preview and can be subject to changes at later point.+"""+type PaymentConfirmEvent implements Event {+ """Time of the event."""+ issuedAt: DateTime++ """Saleor version that triggered the event."""+ version: String++ """The user or application that triggered the event."""+ issuingPrincipal: IssuingPrincipal++ """The application receiving the webhook."""+ recipient: App++ """Look up a payment."""+ payment: Payment+}++"""+Process payment.++Added in Saleor 3.6.++Note: this API is currently in Feature Preview and can be subject to changes at later point.+"""+type PaymentProcessEvent implements Event {+ """Time of the event."""+ issuedAt: DateTime++ """Saleor version that triggered the event."""+ version: String++ """The user or application that triggered the event."""+ issuingPrincipal: IssuingPrincipal++ """The application receiving the webhook."""+ recipient: App++ """Look up a payment."""+ payment: Payment+}++"""+List payment gateways.++Added in Saleor 3.6.++Note: this API is currently in Feature Preview and can be subject to changes at later point.+"""+type PaymentListGateways implements Event {+ """Time of the event."""+ issuedAt: DateTime++ """Saleor version that triggered the event."""+ version: String++ """The user or application that triggered the event."""+ issuingPrincipal: IssuingPrincipal++ """The application receiving the webhook."""+ recipient: App++ """The checkout the event relates to."""+ checkout: Checkout+}++"""+Filter shipping methods for order.++Added in Saleor 3.6.++Note: this API is currently in Feature Preview and can be subject to changes at later point.+"""+type OrderFilterShippingMethods implements Event {+ """Time of the event."""+ issuedAt: DateTime++ """Saleor version that triggered the event."""+ version: String++ """The user or application that triggered the event."""+ issuingPrincipal: IssuingPrincipal++ """The application receiving the webhook."""+ recipient: App++ """The order the event relates to."""+ order: Order++ """+ Shipping methods that can be used with this checkout.++ Added in Saleor 3.6.++ Note: this API is currently in Feature Preview and can be subject to changes at later point.+ """+ shippingMethods: [ShippingMethod!]+}++"""+Filter shipping methods for checkout.++Added in Saleor 3.6.++Note: this API is currently in Feature Preview and can be subject to changes at later point.+"""+type CheckoutFilterShippingMethods implements Event {+ """Time of the event."""+ issuedAt: DateTime++ """Saleor version that triggered the event."""+ version: String++ """The user or application that triggered the event."""+ issuingPrincipal: IssuingPrincipal++ """The application receiving the webhook."""+ recipient: App++ """The checkout the event relates to."""+ checkout: Checkout++ """+ Shipping methods that can be used with this checkout.++ Added in Saleor 3.6.++ Note: this API is currently in Feature Preview and can be subject to changes at later point.+ """+ shippingMethods: [ShippingMethod!]+}++"""+List shipping methods for checkout.++Added in Saleor 3.6.++Note: this API is currently in Feature Preview and can be subject to changes at later point.+"""+type ShippingListMethodsForCheckout implements Event {+ """Time of the event."""+ issuedAt: DateTime++ """Saleor version that triggered the event."""+ version: String++ """The user or application that triggered the event."""+ issuingPrincipal: IssuingPrincipal++ """The application receiving the webhook."""+ recipient: App++ """The checkout the event relates to."""+ checkout: Checkout++ """+ Shipping methods that can be used with this checkout.++ Added in Saleor 3.6.++ Note: this API is currently in Feature Preview and can be subject to changes at later point.+ """+ shippingMethods: [ShippingMethod!]+}+"""_Any value scalar as defined by Federation spec."""scalar _Anydiff --git a/saleor/graphql/tests/queries/fragments.py b/saleor/graphql/tests/queries/fragments.pyindex 9856f6ce29..0cff870b85 100644--- a/saleor/graphql/tests/queries/fragments.py+++ b/saleor/graphql/tests/queries/fragments.py@@ -414,3 +414,15 @@ fragment AttributeValueDetails on AttributeValue {value}"""++PAYMENT_DETAILS = """+fragment PaymentDetails on Payment {+ id+ total {+ amount+ currency+ }+ isActive+ gateway+}+"""diff --git a/saleor/graphql/webhook/resolvers.py b/saleor/graphql/webhook/resolvers.pyindex c1db3c221e..589c0d35fc 100644--- a/saleor/graphql/webhook/resolvers.py+++ b/saleor/graphql/webhook/resolvers.py@@ -1,3 +1,8 @@+from ...checkout.fetch import (+ fetch_checkout_info,+ fetch_checkout_lines,+ get_all_shipping_methods_list,+)from ...core.exceptions import PermissionDeniedfrom ...core.permissions import AppPermissionfrom ...core.tracing import traced_resolver@@ -38,3 +43,27 @@ def resolve_sample_payload(info, event_name):if info.context.user.has_perm(required_permission):return payloads.generate_sample_payload(event_name)raise PermissionDenied(permissions=[required_permission])+++def resolve_shipping_methods_for_checkout(info, checkout):+ manager = info.context.plugins+ discounts = info.context.discounts+ lines, _ = fetch_checkout_lines(checkout)+ shipping_channel_listings = checkout.channel.shipping_method_listings.all()+ checkout_info = fetch_checkout_info(+ checkout,+ lines,+ discounts,+ manager,+ shipping_channel_listings,+ fetch_delivery_methods=False,+ )+ all_shipping_methods = get_all_shipping_methods_list(+ checkout_info,+ checkout.shipping_address,+ lines,+ info.context.discounts,+ shipping_channel_listings,+ manager,+ )+ return all_shipping_methodsdiff --git a/saleor/graphql/webhook/subscription_payload.py b/saleor/graphql/webhook/subscription_payload.pyindex 8bfa8b6460..a82166a434 100644--- a/saleor/graphql/webhook/subscription_payload.py+++ b/saleor/graphql/webhook/subscription_payload.py@@ -58,6 +58,8 @@ def check_document_is_single_subscription(document: GraphQLDocument) -> bool:"""subscriptions = []for definition in document.document_ast.definitions:+ if len(definition.selection_set.selections) != 1:+ return Falseif isinstance(definition, FragmentDefinition):passelif isinstance(definition, OperationDefinition):@@ -70,7 +72,7 @@ def check_document_is_single_subscription(document: GraphQLDocument) -> bool:return len(subscriptions) == 1-def initialize_request(requestor=None) -> HttpRequest:+def initialize_request(requestor=None, sync_event=False) -> HttpRequest:"""Prepare a request object for webhook subscription.It creates a dummy request object.@@ -92,6 +94,7 @@ def initialize_request(requestor=None) -> HttpRequest:request.META["HTTP_X_FORWARDED_PROTO"] = "https"request.META["SERVER_PORT"] = "443"+ request.sync_event = sync_event # type: ignorerequest.requestor = requestor # type: ignorerequest.request_time = request_time # type: ignorerequest.site = SimpleLazyObject(lambda: Site.objects.get_current()) # type: ignorediff --git a/saleor/graphql/webhook/subscription_types.py b/saleor/graphql/webhook/subscription_types.pyindex f8d447f0da..b661a6c637 100644--- a/saleor/graphql/webhook/subscription_types.py+++ b/saleor/graphql/webhook/subscription_types.py@@ -10,6 +10,7 @@ from ...attribute.models import AttributeTranslation, AttributeValueTranslationfrom ...core.prices import quantize_pricefrom ...discount.models import SaleTranslation, VoucherTranslationfrom ...menu.models import MenuItemTranslation+from ...order.utils import get_all_shipping_methods_for_orderfrom ...page.models import PageTranslationfrom ...payment.interface import TransactionActionDatafrom ...product.models import (@@ -19,10 +20,11 @@ from ...product.models import (ProductVariantTranslation,)from ...shipping.models import ShippingMethodTranslation-from ...webhook.event_types import WebhookEventAsyncType+from ...webhook.event_types import WebhookEventAsyncType, WebhookEventSyncTypefrom ..account.types import User as UserTypefrom ..app.types import App as AppTypefrom ..channel import ChannelContext+from ..channel.dataloaders import ChannelByIdLoaderfrom ..core.descriptions import (ADDED_IN_32,ADDED_IN_34,@@ -31,9 +33,13 @@ from ..core.descriptions import (PREVIEW_FEATURE,)from ..core.scalars import PositiveDecimal+from ..core.types import NonNullListfrom ..payment.enums import TransactionActionEnumfrom ..payment.types import TransactionItem+from ..shipping.dataloaders import ShippingMethodChannelListingByChannelSlugLoader+from ..shipping.types import ShippingMethodfrom ..translations import types as translation_types+from .resolvers import resolve_shipping_methods_for_checkoutTRANSLATIONS_TYPES_MAP = {ProductTranslation: translation_types.ProductTranslation,@@ -170,6 +176,22 @@ class Event(graphene.Interface):WebhookEventAsyncType.WAREHOUSE_CREATED: WarehouseCreated,WebhookEventAsyncType.WAREHOUSE_UPDATED: WarehouseUpdated,WebhookEventAsyncType.WAREHOUSE_DELETED: WarehouseDeleted,+ WebhookEventSyncType.PAYMENT_AUTHORIZE: PaymentAuthorize,+ WebhookEventSyncType.PAYMENT_CAPTURE: PaymentCaptureEvent,+ WebhookEventSyncType.PAYMENT_REFUND: PaymentRefundEvent,+ WebhookEventSyncType.PAYMENT_VOID: PaymentVoidEvent,+ WebhookEventSyncType.PAYMENT_CONFIRM: PaymentConfirmEvent,+ WebhookEventSyncType.PAYMENT_PROCESS: PaymentProcessEvent,+ WebhookEventSyncType.PAYMENT_LIST_GATEWAYS: PaymentListGateways,+ WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS: (+ OrderFilterShippingMethods+ ),+ WebhookEventSyncType.CHECKOUT_FILTER_SHIPPING_METHODS: (+ CheckoutFilterShippingMethods+ ),+ WebhookEventSyncType.SHIPPING_LIST_METHODS_FOR_CHECKOUT: (+ ShippingListMethodsForCheckout+ ),}return types.get(object_type)@@ -1374,6 +1396,131 @@ class WarehouseBase(AbstractType):return warehouse+class PaymentBase(AbstractType):+ payment = graphene.Field(+ "saleor.graphql.payment.types.Payment",+ description="Look up a payment.",+ )++ @staticmethod+ def resolve_payment(root, _info):+ _, payment = root+ return payment+++class PaymentAuthorize(ObjectType, PaymentBase):+ class Meta:+ interfaces = (Event,)+ description = "Authorize payment." + ADDED_IN_36 + PREVIEW_FEATURE+++class PaymentCaptureEvent(ObjectType, PaymentBase):+ class Meta:+ interfaces = (Event,)+ description = "Capture payment." + ADDED_IN_36 + PREVIEW_FEATURE+++class PaymentRefundEvent(ObjectType, PaymentBase):+ class Meta:+ interfaces = (Event,)+ description = "Refund payment." + ADDED_IN_36 + PREVIEW_FEATURE+++class PaymentVoidEvent(ObjectType, PaymentBase):+ class Meta:+ interfaces = (Event,)+ description = "Void payment." + ADDED_IN_36 + PREVIEW_FEATURE+++class PaymentConfirmEvent(ObjectType, PaymentBase):+ class Meta:+ interfaces = (Event,)+ description = "Confirm payment." + ADDED_IN_36 + PREVIEW_FEATURE+++class PaymentProcessEvent(ObjectType, PaymentBase):+ class Meta:+ interfaces = (Event,)+ description = "Process payment." + ADDED_IN_36 + PREVIEW_FEATURE+++class PaymentListGateways(ObjectType, CheckoutBase):+ class Meta:+ interfaces = (Event,)+ description = "List payment gateways." + ADDED_IN_36 + PREVIEW_FEATURE+++class ShippingListMethodsForCheckout(ObjectType, CheckoutBase):+ shipping_methods = NonNullList(+ ShippingMethod,+ description="Shipping methods that can be used with this checkout."+ + ADDED_IN_36+ + PREVIEW_FEATURE,+ )++ @staticmethod+ def resolve_shipping_methods(root, info):+ _, checkout = root+ return resolve_shipping_methods_for_checkout(info, checkout)++ class Meta:+ interfaces = (Event,)+ description = (+ "List shipping methods for checkout." + ADDED_IN_36 + PREVIEW_FEATURE+ )+++class CheckoutFilterShippingMethods(ObjectType, CheckoutBase):+ shipping_methods = NonNullList(+ ShippingMethod,+ description="Shipping methods that can be used with this checkout."+ + ADDED_IN_36+ + PREVIEW_FEATURE,+ )++ @staticmethod+ def resolve_shipping_methods(root, info):+ _, checkout = root+ return resolve_shipping_methods_for_checkout(info, checkout)++ class Meta:+ interfaces = (Event,)+ description = (+ "Filter shipping methods for checkout." + ADDED_IN_36 + PREVIEW_FEATURE+ )+++class OrderFilterShippingMethods(ObjectType, OrderBase):+ shipping_methods = NonNullList(+ ShippingMethod,+ description="Shipping methods that can be used with this checkout."+ + ADDED_IN_36+ + PREVIEW_FEATURE,+ )++ @staticmethod+ def resolve_shipping_methods(root, info):+ _, order = root++ def with_channel(channel):+ def with_listings(channel_listings):+ return get_all_shipping_methods_for_order(order, channel_listings)++ return (+ ShippingMethodChannelListingByChannelSlugLoader(info.context)+ .load(channel.slug)+ .then(with_listings)+ )++ return ChannelByIdLoader(info.context).load(order.channel_id).then(with_channel)++ class Meta:+ interfaces = (Event,)+ description = (+ "Filter shipping methods for order." + ADDED_IN_36 + PREVIEW_FEATURE+ )++class WarehouseCreated(ObjectType, WarehouseBase):class Meta:interfaces = (Event,)@@ -1503,4 +1650,14 @@ SUBSCRIPTION_EVENTS_TYPES = [WarehouseCreated,WarehouseUpdated,WarehouseDeleted,+ PaymentAuthorize,+ PaymentCaptureEvent,+ PaymentRefundEvent,+ PaymentVoidEvent,+ PaymentConfirmEvent,+ PaymentProcessEvent,+ PaymentListGateways,+ OrderFilterShippingMethods,+ CheckoutFilterShippingMethods,+ ShippingListMethodsForCheckout,]diff --git a/saleor/graphql/webhook/tests/test_webhook.py b/saleor/graphql/webhook/tests/test_webhook.pyindex aee0fb1446..dfda57a974 100644--- a/saleor/graphql/webhook/tests/test_webhook.py+++ b/saleor/graphql/webhook/tests/test_webhook.py@@ -195,6 +195,54 @@ def test_webhook_create_by_staff_invalid_query(assert content["errors"] == expected_errors+SUBSCRIPTION_QUERY_WITH_MULTIPLE_LVL_FIELDS = """+subscription {+ event {+ ... on PaymentListGateways {+ checkout {+ id+ }+ }+ }+ ... on CheckoutFilterShippingMethods {+ checkout {+ id+ }+ shippingMethods {+ name+ id+ }+ }+}"""+++def test_webhook_create_by_staff_invalid_query_multiple_level_fields(+ app_api_client, permission_manage_orders+):+ query = WEBHOOK_CREATE+ variables = {+ "input": {+ "name": "New integration",+ "targetUrl": "https://www.example.com",+ "asyncEvents": [+ WebhookEventTypeAsyncEnum.ORDER_CREATED.name,+ ],+ "query": SUBSCRIPTION_QUERY_WITH_MULTIPLE_LVL_FIELDS,+ }+ }+ response = app_api_client.post_graphql(+ query,+ variables=variables,+ permissions=[permission_manage_orders],+ check_no_permissions=False,+ )+ content = get_graphql_content(response)+ expected_errors = [{"field": "query", "message": "Subscription query is not valid"}]+ content = content["data"]["webhookCreate"]+ assert not content["webhook"]+ assert content["errors"] == expected_errors++WEBHOOK_DELETE_BY_APP = """mutation webhookDelete($id: ID!) {webhookDelete(id: $id) {diff --git a/saleor/order/utils.py b/saleor/order/utils.pyindex 7031a9f626..a027b34122 100644--- a/saleor/order/utils.py+++ b/saleor/order/utils.py@@ -510,22 +510,17 @@ def sum_order_totals(qs, currency_code):return sum([order.total for order in qs], taxed_zero)-def get_valid_shipping_methods_for_order(+def get_all_shipping_methods_for_order(order: Order,shipping_channel_listings: Iterable["ShippingMethodChannelListing"],- manager: "PluginsManager",) -> List[ShippingMethodData]:- """Return a list of shipping methods according to Saleor's own business logic.-- The resulting methods are not yet filtered by plugins.- """if not order.is_shipping_required():return []if not order.shipping_address:return []- valid_methods = []+ all_methods = []shipping_methods = ShippingMethod.objects.applicable_shipping_methods_for_instance(order,@@ -542,7 +537,19 @@ def get_valid_shipping_methods_for_order(listing = listing_map.get(method.id)shipping_method_data = convert_to_shipping_method_data(method, listing)if shipping_method_data:- valid_methods.append(shipping_method_data)+ all_methods.append(shipping_method_data)+ return all_methods+++def get_valid_shipping_methods_for_order(+ order: Order,+ shipping_channel_listings: Iterable["ShippingMethodChannelListing"],+ manager: "PluginsManager",+) -> List[ShippingMethodData]:+ """Return a list of shipping methods according to Saleor's own business logic."""+ valid_methods = get_all_shipping_methods_for_order(order, shipping_channel_listings)+ if not valid_methods:+ return []excluded_methods = manager.excluded_shipping_methods_for_order(order, valid_methods)initialize_shipping_method_active_status(valid_methods, excluded_methods)diff --git a/saleor/plugins/webhook/plugin.py b/saleor/plugins/webhook/plugin.pyindex ec62e6a17f..8252efb052 100644--- a/saleor/plugins/webhook/plugin.py+++ b/saleor/plugins/webhook/plugin.py@@ -11,6 +11,7 @@ from ...core.notify_events import NotifyEventTypefrom ...core.taxes import TaxData, TaxTypefrom ...core.utils.json_serializer import CustomJsonEncoderfrom ...payment import PaymentError, TransactionKind+from ...payment.models import Paymentfrom ...webhook.event_types import WebhookEventAsyncType, WebhookEventSyncTypefrom ...webhook.payloads import (generate_checkout_payload,@@ -1162,7 +1163,14 @@ class WebhookPlugin(BasePlugin):)webhook_payload = generate_payment_payload(payment_information)- response_data = trigger_webhook_sync(event_type, webhook_payload, app)+ payment = Payment.objects.filter(id=payment_information.payment_id).first()+ if not payment:+ raise PaymentError(+ f"Payment with id: {payment_information.payment_id} not found."+ )+ response_data = trigger_webhook_sync(+ event_type, webhook_payload, app, subscribable_object=payment+ )if response_data is None:raise PaymentError(f"Payment method {payment_information.gateway} is not available: "@@ -1192,6 +1200,7 @@ class WebhookPlugin(BasePlugin):event_type=WebhookEventSyncType.PAYMENT_LIST_GATEWAYS,data=generate_list_gateways_payload(currency, checkout),app=app,+ subscribable_object=checkout,)if response_data:app_gateways = parse_list_payment_gateways_response(response_data, app)@@ -1297,12 +1306,14 @@ class WebhookPlugin(BasePlugin):WebhookEventSyncType.SHIPPING_LIST_METHODS_FOR_CHECKOUT).prefetch_related("webhooks")if apps:+ # consider lazy loadingpayload = generate_checkout_payload(checkout, self.requestor)for app in apps:response_data = trigger_webhook_sync(event_type=WebhookEventSyncType.SHIPPING_LIST_METHODS_FOR_CHECKOUT,data=payload,app=app,+ subscribable_object=checkout,)if response_data:shipping_methods = parse_list_shipping_methods_response(@@ -1356,6 +1367,7 @@ class WebhookPlugin(BasePlugin):previous_value=previous_value,payload_fun=payload_fun,cache_key=cache_key,+ subscribable_object=order,)def excluded_shipping_methods_for_checkout(@@ -1375,6 +1387,7 @@ class WebhookPlugin(BasePlugin):previous_value=previous_value,payload_fun=payload_function,cache_key=cache_key,+ subscribable_object=checkout,)def is_event_active(self, event: str, channel=Optional[str]):diff --git a/saleor/plugins/webhook/shipping.py b/saleor/plugins/webhook/shipping.pyindex 1428569b05..d5910ba1bc 100644--- a/saleor/plugins/webhook/shipping.py+++ b/saleor/plugins/webhook/shipping.py@@ -2,15 +2,17 @@ import base64import jsonimport loggingfrom collections import defaultdict-from typing import TYPE_CHECKING, Any, Callable, Dict, List+from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Unionfrom django.core.cache import cachefrom django.db.models import QuerySetfrom graphql import GraphQLErrorfrom prices import Money+from ...checkout.models import Checkoutfrom ...graphql.core.utils import from_global_id_or_errorfrom ...graphql.shipping.types import ShippingMethod+from ...order.models import Orderfrom ...shipping.interface import ShippingMethodDatafrom ...webhook.utils import get_webhooks_for_eventfrom ..base_plugin import ExcludedShippingMethod@@ -67,7 +69,11 @@ def _compare_order_payloads(payload: str, cached_payload: str) -> bool:def get_excluded_shipping_methods_or_fetch(- webhooks: QuerySet, event_type: str, payload: str, cache_key: str+ webhooks: QuerySet,+ event_type: str,+ payload: str,+ cache_key: str,+ subscribable_object: Optional[Union["Order", "Checkout"]],) -> Dict[str, List[ExcludedShippingMethod]]:"""Return data of all excluded shipping methods.@@ -89,7 +95,8 @@ def get_excluded_shipping_methods_or_fetch(event_type,payload,webhook.app,- EXCLUDED_SHIPPING_REQUEST_TIMEOUT,+ subscribable_object=subscribable_object,+ timeout=EXCLUDED_SHIPPING_REQUEST_TIMEOUT,)if response_data:excluded_methods.extend(@@ -104,6 +111,7 @@ def get_excluded_shipping_data(previous_value: List[ExcludedShippingMethod],payload_fun: Callable[[], str],cache_key: str,+ subscribable_object: Optional[Union["Order", "Checkout"]],) -> List[ExcludedShippingMethod]:"""Exclude not allowed shipping methods by sync webhook.@@ -123,7 +131,7 @@ def get_excluded_shipping_data(payload = payload_fun()excluded_methods_map = get_excluded_shipping_methods_or_fetch(- webhooks, event_type, payload, cache_key+ webhooks, event_type, payload, cache_key, subscribable_object)# Gather responses for previous pluginsdiff --git a/saleor/plugins/webhook/tasks.py b/saleor/plugins/webhook/tasks.pyindex 5fa2b41481..ecc0c14d2f 100644--- a/saleor/plugins/webhook/tasks.py+++ b/saleor/plugins/webhook/tasks.py@@ -27,7 +27,11 @@ from ...graphql.webhook.subscription_payload import (from ...payment import PaymentErrorfrom ...site.models import Sitefrom ...webhook import observability-from ...webhook.event_types import SUBSCRIBABLE_EVENTS, WebhookEventAsyncType+from ...webhook.event_types import (+ SUBSCRIBABLE_EVENTS,+ WebhookEventAsyncType,+ WebhookEventSyncType,+)from ...webhook.observability import WebhookDatafrom ...webhook.utils import get_webhooks_for_eventfrom . import signature_for_payload@@ -67,9 +71,9 @@ class WebhookResponse:def create_deliveries_for_subscriptions(event_type, subscribable_object, webhooks, requestor=None) -> List[EventDelivery]:- """Create webhook payload based on subscription query.+ """Create a list of event deliveries with payloads based on subscription query.- It uses a defined subscription query, defined for webhook to explicitly determine+ It uses a subscription query, defined for webhook to explicitly determinewhat fields should be included in the payload.:param event_type: event type which should be triggered.@@ -90,7 +94,9 @@ def create_deliveries_for_subscriptions(event_type=event_type,subscribable_object=subscribable_object,subscription_query=webhook.subscription_query,- request=initialize_request(requestor),+ request=initialize_request(+ requestor, event_type in WebhookEventSyncType.ALL+ ),app=webhook.app,)if not data:@@ -114,6 +120,50 @@ def create_deliveries_for_subscriptions(return EventDelivery.objects.bulk_create(event_deliveries)+def create_delivery_for_subscription_sync_event(+ event_type, subscribable_object, webhook, requestor=None+) -> Optional[EventDelivery]:+ """Generate webhook payload based on subscription query and create delivery object.++ It uses a defined subscription query, defined for webhook to explicitly determine+ what fields should be included in the payload.++ :param event_type: event type which should be triggered.+ :param subscribable_object: subscribable object to process via subscription query.+ :param webhook: webhook object for which delivery will be created.+ :param requestor: used in subscription webhooks to generate meta data for payload.+ :return: List of event deliveries to send via webhook tasks.+ """+ if event_type not in SUBSCRIBABLE_EVENTS:+ logger.info(+ "Skipping subscription webhook. Event %s is not subscribable.", event_type+ )+ return None++ data = generate_payload_from_subscription(+ event_type=event_type,+ subscribable_object=subscribable_object,+ subscription_query=webhook.subscription_query,+ request=initialize_request(requestor, event_type in WebhookEventSyncType.ALL),+ app=webhook.app,+ )+ if not data:+ # PaymentError is a temporary exception type. New type will be implemented+ # in separate PR to ensure proper handling for all sync events.+ # It was implemented when sync webhooks were handling payment events only.+ raise PaymentError(+ "No payload was generated with subscription for event: %s" % event_type+ )+ event_payload = EventPayload.objects.create(payload=json.dumps({**data}))+ event_delivery = EventDelivery.objects.create(+ status=EventDeliveryStatus.PENDING,+ event_type=event_type,+ payload=event_payload,+ webhook=webhook,+ )+ return event_delivery++def trigger_webhooks_async(data, event_type, webhooks, subscribable_object=None, requestor=None):@@ -159,20 +209,34 @@ def group_webhooks_by_subscription(webhooks):def trigger_webhook_sync(- event_type: str, data: str, app: "App", timeout=None+ event_type: str,+ data: str,+ app: "App",+ subscribable_object=None,+ timeout=None,) -> Optional[Dict[Any, Any]]:"""Send a synchronous webhook request."""webhooks = get_webhooks_for_event(event_type, app.webhooks.all())webhook = webhooks.first()if not webhook:raise PaymentError(f"No payment webhook found for event: {event_type}.")- event_payload = EventPayload.objects.create(payload=data)- delivery = EventDelivery.objects.create(- status=EventDeliveryStatus.PENDING,- event_type=event_type,- payload=event_payload,- webhook=webhook,- )+ if webhook.subscription_query:+ delivery = create_delivery_for_subscription_sync_event(+ event_type=event_type,+ subscribable_object=subscribable_object,+ webhook=webhook,+ )+ if not delivery:+ return None++ else:+ event_payload = EventPayload.objects.create(payload=data)+ delivery = EventDelivery.objects.create(+ status=EventDeliveryStatus.PENDING,+ event_type=event_type,+ payload=event_payload,+ webhook=webhook,+ )kwargs = {}if timeout:kwargs = {"timeout": timeout}diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/fixtures.py b/saleor/plugins/webhook/tests/subscription_webhooks/fixtures.pyindex 6b4091afb3..8e854f65ff 100644--- a/saleor/plugins/webhook/tests/subscription_webhooks/fixtures.py+++ b/saleor/plugins/webhook/tests/subscription_webhooks/fixtures.py@@ -1,8 +1,8 @@import pytest-from .....webhook.event_types import WebhookEventAsyncType+from .....webhook.event_types import WebhookEventAsyncType, WebhookEventSyncTypefrom .....webhook.models import Webhook-from . import subscription_queries+from . import subscription_queries as queries@pytest.fixture@@ -23,49 +23,45 @@ def subscription_webhook(webhook_app):@pytest.fixturedef subscription_address_created_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.ADDRESS_CREATED, WebhookEventAsyncType.ADDRESS_CREATED+ queries.ADDRESS_CREATED, WebhookEventAsyncType.ADDRESS_CREATED)@pytest.fixturedef subscription_address_updated_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.ADDRESS_UPDATED, WebhookEventAsyncType.ADDRESS_UPDATED+ queries.ADDRESS_UPDATED, WebhookEventAsyncType.ADDRESS_UPDATED)@pytest.fixturedef subscription_address_deleted_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.ADDRESS_DELETED, WebhookEventAsyncType.ADDRESS_DELETED+ queries.ADDRESS_DELETED, WebhookEventAsyncType.ADDRESS_DELETED)@pytest.fixturedef subscription_app_installed_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.APP_INSTALLED, WebhookEventAsyncType.APP_INSTALLED+ queries.APP_INSTALLED, WebhookEventAsyncType.APP_INSTALLED)@pytest.fixturedef subscription_app_updated_webhook(subscription_webhook):- return subscription_webhook(- subscription_queries.APP_UPDATED, WebhookEventAsyncType.APP_UPDATED- )+ return subscription_webhook(queries.APP_UPDATED, WebhookEventAsyncType.APP_UPDATED)@pytest.fixturedef subscription_app_deleted_webhook(subscription_webhook):- return subscription_webhook(- subscription_queries.APP_DELETED, WebhookEventAsyncType.APP_DELETED- )+ return subscription_webhook(queries.APP_DELETED, WebhookEventAsyncType.APP_DELETED)@pytest.fixturedef subscription_app_status_changed_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.APP_STATUS_CHANGED,+ queries.APP_STATUS_CHANGED,WebhookEventAsyncType.APP_STATUS_CHANGED,)@@ -73,28 +69,28 @@ def subscription_app_status_changed_webhook(subscription_webhook):@pytest.fixturedef subscription_attribute_created_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.ATTRIBUTE_CREATED, WebhookEventAsyncType.ATTRIBUTE_CREATED+ queries.ATTRIBUTE_CREATED, WebhookEventAsyncType.ATTRIBUTE_CREATED)@pytest.fixturedef subscription_attribute_updated_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.ATTRIBUTE_UPDATED, WebhookEventAsyncType.ATTRIBUTE_UPDATED+ queries.ATTRIBUTE_UPDATED, WebhookEventAsyncType.ATTRIBUTE_UPDATED)@pytest.fixturedef subscription_attribute_deleted_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.ATTRIBUTE_DELETED, WebhookEventAsyncType.ATTRIBUTE_DELETED+ queries.ATTRIBUTE_DELETED, WebhookEventAsyncType.ATTRIBUTE_DELETED)@pytest.fixturedef subscription_attribute_value_created_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.ATTRIBUTE_VALUE_CREATED,+ queries.ATTRIBUTE_VALUE_CREATED,WebhookEventAsyncType.ATTRIBUTE_VALUE_CREATED,)@@ -102,7 +98,7 @@ def subscription_attribute_value_created_webhook(subscription_webhook):@pytest.fixturedef subscription_attribute_value_updated_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.ATTRIBUTE_VALUE_UPDATED,+ queries.ATTRIBUTE_VALUE_UPDATED,WebhookEventAsyncType.ATTRIBUTE_VALUE_UPDATED,)@@ -110,7 +106,7 @@ def subscription_attribute_value_updated_webhook(subscription_webhook):@pytest.fixturedef subscription_attribute_value_deleted_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.ATTRIBUTE_VALUE_DELETED,+ queries.ATTRIBUTE_VALUE_DELETED,WebhookEventAsyncType.ATTRIBUTE_VALUE_DELETED,)@@ -118,49 +114,49 @@ def subscription_attribute_value_deleted_webhook(subscription_webhook):@pytest.fixturedef subscription_category_created_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.CATEGORY_CREATED, WebhookEventAsyncType.CATEGORY_CREATED+ queries.CATEGORY_CREATED, WebhookEventAsyncType.CATEGORY_CREATED)@pytest.fixturedef subscription_category_updated_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.CATEGORY_UPDATED, WebhookEventAsyncType.CATEGORY_UPDATED+ queries.CATEGORY_UPDATED, WebhookEventAsyncType.CATEGORY_UPDATED)@pytest.fixturedef subscription_category_deleted_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.CATEGORY_DELETED, WebhookEventAsyncType.CATEGORY_DELETED+ queries.CATEGORY_DELETED, WebhookEventAsyncType.CATEGORY_DELETED)@pytest.fixturedef subscription_channel_created_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.CHANNEL_CREATED, WebhookEventAsyncType.CHANNEL_CREATED+ queries.CHANNEL_CREATED, WebhookEventAsyncType.CHANNEL_CREATED)@pytest.fixturedef subscription_channel_updated_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.CHANNEL_UPDATED, WebhookEventAsyncType.CHANNEL_UPDATED+ queries.CHANNEL_UPDATED, WebhookEventAsyncType.CHANNEL_UPDATED)@pytest.fixturedef subscription_channel_deleted_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.CHANNEL_DELETED, WebhookEventAsyncType.CHANNEL_DELETED+ queries.CHANNEL_DELETED, WebhookEventAsyncType.CHANNEL_DELETED)@pytest.fixturedef subscription_channel_status_changed_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.CHANNEL_STATUS_CHANGED,+ queries.CHANNEL_STATUS_CHANGED,WebhookEventAsyncType.CHANNEL_STATUS_CHANGED,)@@ -168,28 +164,28 @@ def subscription_channel_status_changed_webhook(subscription_webhook):@pytest.fixturedef subscription_gift_card_created_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.GIFT_CARD_CREATED, WebhookEventAsyncType.GIFT_CARD_CREATED+ queries.GIFT_CARD_CREATED, WebhookEventAsyncType.GIFT_CARD_CREATED)@pytest.fixturedef subscription_gift_card_updated_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.GIFT_CARD_UPDATED, WebhookEventAsyncType.GIFT_CARD_UPDATED+ queries.GIFT_CARD_UPDATED, WebhookEventAsyncType.GIFT_CARD_UPDATED)@pytest.fixturedef subscription_gift_card_deleted_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.GIFT_CARD_DELETED, WebhookEventAsyncType.GIFT_CARD_DELETED+ queries.GIFT_CARD_DELETED, WebhookEventAsyncType.GIFT_CARD_DELETED)@pytest.fixturedef subscription_gift_card_status_changed_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.GIFT_CARD_STATUS_CHANGED,+ queries.GIFT_CARD_STATUS_CHANGED,WebhookEventAsyncType.GIFT_CARD_STATUS_CHANGED,)@@ -197,49 +193,49 @@ def subscription_gift_card_status_changed_webhook(subscription_webhook):@pytest.fixturedef subscription_menu_created_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.MENU_CREATED, WebhookEventAsyncType.MENU_CREATED+ queries.MENU_CREATED, WebhookEventAsyncType.MENU_CREATED)@pytest.fixturedef subscription_menu_updated_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.MENU_UPDATED, WebhookEventAsyncType.MENU_UPDATED+ queries.MENU_UPDATED, WebhookEventAsyncType.MENU_UPDATED)@pytest.fixturedef subscription_menu_deleted_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.MENU_DELETED, WebhookEventAsyncType.MENU_DELETED+ queries.MENU_DELETED, WebhookEventAsyncType.MENU_DELETED)@pytest.fixturedef subscription_menu_item_created_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.MENU_ITEM_CREATED, WebhookEventAsyncType.MENU_ITEM_CREATED+ queries.MENU_ITEM_CREATED, WebhookEventAsyncType.MENU_ITEM_CREATED)@pytest.fixturedef subscription_menu_item_updated_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.MENU_ITEM_UPDATED, WebhookEventAsyncType.MENU_ITEM_UPDATED+ queries.MENU_ITEM_UPDATED, WebhookEventAsyncType.MENU_ITEM_UPDATED)@pytest.fixturedef subscription_menu_item_deleted_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.MENU_ITEM_DELETED, WebhookEventAsyncType.MENU_ITEM_DELETED+ queries.MENU_ITEM_DELETED, WebhookEventAsyncType.MENU_ITEM_DELETED)@pytest.fixturedef subscription_shipping_price_created_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.SHIPPING_PRICE_CREATED,+ queries.SHIPPING_PRICE_CREATED,WebhookEventAsyncType.SHIPPING_PRICE_CREATED,)@@ -247,7 +243,7 @@ def subscription_shipping_price_created_webhook(subscription_webhook):@pytest.fixturedef subscription_shipping_price_updated_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.SHIPPING_PRICE_UPDATED_UPDATED,+ queries.SHIPPING_PRICE_UPDATED_UPDATED,WebhookEventAsyncType.SHIPPING_PRICE_UPDATED,)@@ -255,7 +251,7 @@ def subscription_shipping_price_updated_webhook(subscription_webhook):@pytest.fixturedef subscription_shipping_price_deleted_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.SHIPPING_PRICE_DELETED,+ queries.SHIPPING_PRICE_DELETED,WebhookEventAsyncType.SHIPPING_PRICE_DELETED,)@@ -263,7 +259,7 @@ def subscription_shipping_price_deleted_webhook(subscription_webhook):@pytest.fixturedef subscription_shipping_zone_created_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.SHIPPING_ZONE_CREATED,+ queries.SHIPPING_ZONE_CREATED,WebhookEventAsyncType.SHIPPING_ZONE_CREATED,)@@ -271,7 +267,7 @@ def subscription_shipping_zone_created_webhook(subscription_webhook):@pytest.fixturedef subscription_shipping_zone_updated_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.SHIPPING_ZONE_UPDATED_UPDATED,+ queries.SHIPPING_ZONE_UPDATED_UPDATED,WebhookEventAsyncType.SHIPPING_ZONE_UPDATED,)@@ -279,7 +275,7 @@ def subscription_shipping_zone_updated_webhook(subscription_webhook):@pytest.fixturedef subscription_shipping_zone_deleted_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.SHIPPING_ZONE_DELETED,+ queries.SHIPPING_ZONE_DELETED,WebhookEventAsyncType.SHIPPING_ZONE_DELETED,)@@ -287,28 +283,28 @@ def subscription_shipping_zone_deleted_webhook(subscription_webhook):@pytest.fixturedef subscription_product_updated_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.PRODUCT_UPDATED, WebhookEventAsyncType.PRODUCT_UPDATED+ queries.PRODUCT_UPDATED, WebhookEventAsyncType.PRODUCT_UPDATED)@pytest.fixturedef subscription_product_created_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.PRODUCT_CREATED, WebhookEventAsyncType.PRODUCT_CREATED+ queries.PRODUCT_CREATED, WebhookEventAsyncType.PRODUCT_CREATED)@pytest.fixturedef subscription_product_deleted_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.PRODUCT_DELETED, WebhookEventAsyncType.PRODUCT_DELETED+ queries.PRODUCT_DELETED, WebhookEventAsyncType.PRODUCT_DELETED)@pytest.fixturedef subscription_product_variant_created_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.PRODUCT_VARIANT_CREATED,+ queries.PRODUCT_VARIANT_CREATED,WebhookEventAsyncType.PRODUCT_VARIANT_CREATED,)@@ -316,7 +312,7 @@ def subscription_product_variant_created_webhook(subscription_webhook):@pytest.fixturedef subscription_product_variant_updated_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.PRODUCT_VARIANT_UPDATED,+ queries.PRODUCT_VARIANT_UPDATED,WebhookEventAsyncType.PRODUCT_VARIANT_UPDATED,)@@ -324,7 +320,7 @@ def subscription_product_variant_updated_webhook(subscription_webhook):@pytest.fixturedef subscription_product_variant_deleted_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.PRODUCT_VARIANT_DELETED,+ queries.PRODUCT_VARIANT_DELETED,WebhookEventAsyncType.PRODUCT_VARIANT_DELETED,)@@ -332,7 +328,7 @@ def subscription_product_variant_deleted_webhook(subscription_webhook):@pytest.fixturedef subscription_product_variant_out_of_stock_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.PRODUCT_VARIANT_OUT_OF_STOCK,+ queries.PRODUCT_VARIANT_OUT_OF_STOCK,WebhookEventAsyncType.PRODUCT_VARIANT_OUT_OF_STOCK,)@@ -340,7 +336,7 @@ def subscription_product_variant_out_of_stock_webhook(subscription_webhook):@pytest.fixturedef subscription_product_variant_back_in_stock_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.PRODUCT_VARIANT_BACK_IN_STOCK,+ queries.PRODUCT_VARIANT_BACK_IN_STOCK,WebhookEventAsyncType.PRODUCT_VARIANT_BACK_IN_STOCK,)@@ -348,49 +344,49 @@ def subscription_product_variant_back_in_stock_webhook(subscription_webhook):@pytest.fixturedef subscription_order_created_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.ORDER_CREATED, WebhookEventAsyncType.ORDER_CREATED+ queries.ORDER_CREATED, WebhookEventAsyncType.ORDER_CREATED)@pytest.fixturedef subscription_order_updated_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.ORDER_UPDATED, WebhookEventAsyncType.ORDER_UPDATED+ queries.ORDER_UPDATED, WebhookEventAsyncType.ORDER_UPDATED)@pytest.fixturedef subscription_order_confirmed_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.ORDER_CONFIRMED, WebhookEventAsyncType.ORDER_CONFIRMED+ queries.ORDER_CONFIRMED, WebhookEventAsyncType.ORDER_CONFIRMED)@pytest.fixturedef subscription_order_fully_paid_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.ORDER_FULLY_PAID, WebhookEventAsyncType.ORDER_FULLY_PAID+ queries.ORDER_FULLY_PAID, WebhookEventAsyncType.ORDER_FULLY_PAID)@pytest.fixturedef subscription_order_cancelled_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.ORDER_CANCELLED, WebhookEventAsyncType.ORDER_CANCELLED+ queries.ORDER_CANCELLED, WebhookEventAsyncType.ORDER_CANCELLED)@pytest.fixturedef subscription_order_fulfilled_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.ORDER_FULFILLED, WebhookEventAsyncType.ORDER_FULFILLED+ queries.ORDER_FULFILLED, WebhookEventAsyncType.ORDER_FULFILLED)@pytest.fixturedef subscription_draft_order_created_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.DRAFT_ORDER_CREATED,+ queries.DRAFT_ORDER_CREATED,WebhookEventAsyncType.DRAFT_ORDER_CREATED,)@@ -398,7 +394,7 @@ def subscription_draft_order_created_webhook(subscription_webhook):@pytest.fixturedef subscription_draft_order_updated_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.DRAFT_ORDER_UPDATED,+ queries.DRAFT_ORDER_UPDATED,WebhookEventAsyncType.DRAFT_ORDER_UPDATED,)@@ -406,7 +402,7 @@ def subscription_draft_order_updated_webhook(subscription_webhook):@pytest.fixturedef subscription_draft_order_deleted_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.DRAFT_ORDER_DELETED,+ queries.DRAFT_ORDER_DELETED,WebhookEventAsyncType.DRAFT_ORDER_DELETED,)@@ -414,56 +410,54 @@ def subscription_draft_order_deleted_webhook(subscription_webhook):@pytest.fixturedef subscription_sale_created_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.SALE_CREATED, WebhookEventAsyncType.SALE_CREATED+ queries.SALE_CREATED, WebhookEventAsyncType.SALE_CREATED)@pytest.fixturedef subscription_sale_updated_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.SALE_UPDATED, WebhookEventAsyncType.SALE_UPDATED+ queries.SALE_UPDATED, WebhookEventAsyncType.SALE_UPDATED)@pytest.fixturedef subscription_sale_deleted_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.SALE_DELETED, WebhookEventAsyncType.SALE_DELETED+ queries.SALE_DELETED, WebhookEventAsyncType.SALE_DELETED)@pytest.fixturedef subscription_sale_toggle_webhook(subscription_webhook):- return subscription_webhook(- subscription_queries.SALE_TOGGLE, WebhookEventAsyncType.SALE_TOGGLE- )+ return subscription_webhook(queries.SALE_TOGGLE, WebhookEventAsyncType.SALE_TOGGLE)@pytest.fixturedef subscription_invoice_requested_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.INVOICE_REQUESTED, WebhookEventAsyncType.INVOICE_REQUESTED+ queries.INVOICE_REQUESTED, WebhookEventAsyncType.INVOICE_REQUESTED)@pytest.fixturedef subscription_invoice_deleted_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.INVOICE_DELETED, WebhookEventAsyncType.INVOICE_DELETED+ queries.INVOICE_DELETED, WebhookEventAsyncType.INVOICE_DELETED)@pytest.fixturedef subscription_invoice_sent_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.INVOICE_SENT, WebhookEventAsyncType.INVOICE_SENT+ queries.INVOICE_SENT, WebhookEventAsyncType.INVOICE_SENT)@pytest.fixturedef subscription_fulfillment_created_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.FULFILLMENT_CREATED,+ queries.FULFILLMENT_CREATED,WebhookEventAsyncType.FULFILLMENT_CREATED,)@@ -471,7 +465,7 @@ def subscription_fulfillment_created_webhook(subscription_webhook):@pytest.fixturedef subscription_fulfillment_canceled_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.FULFILLMENT_CANCELED,+ queries.FULFILLMENT_CANCELED,WebhookEventAsyncType.FULFILLMENT_CANCELED,)@@ -479,28 +473,28 @@ def subscription_fulfillment_canceled_webhook(subscription_webhook):@pytest.fixturedef subscription_customer_created_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.CUSTOMER_CREATED, WebhookEventAsyncType.CUSTOMER_CREATED+ queries.CUSTOMER_CREATED, WebhookEventAsyncType.CUSTOMER_CREATED)@pytest.fixturedef subscription_customer_updated_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.CUSTOMER_UPDATED, WebhookEventAsyncType.CUSTOMER_UPDATED+ queries.CUSTOMER_UPDATED, WebhookEventAsyncType.CUSTOMER_UPDATED)@pytest.fixturedef subscription_customer_deleted_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.CUSTOMER_DELETED, WebhookEventAsyncType.CUSTOMER_DELETED+ queries.CUSTOMER_DELETED, WebhookEventAsyncType.CUSTOMER_DELETED)@pytest.fixturedef subscription_collection_created_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.COLLECTION_CREATED,+ queries.COLLECTION_CREATED,WebhookEventAsyncType.COLLECTION_CREATED,)@@ -508,7 +502,7 @@ def subscription_collection_created_webhook(subscription_webhook):@pytest.fixturedef subscription_collection_updated_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.COLLECTION_UPDATED,+ queries.COLLECTION_UPDATED,WebhookEventAsyncType.COLLECTION_UPDATED,)@@ -516,7 +510,7 @@ def subscription_collection_updated_webhook(subscription_webhook):@pytest.fixturedef subscription_collection_deleted_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.COLLECTION_DELETED,+ queries.COLLECTION_DELETED,WebhookEventAsyncType.COLLECTION_DELETED,)@@ -524,28 +518,28 @@ def subscription_collection_deleted_webhook(subscription_webhook):@pytest.fixturedef subscription_checkout_created_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.CHECKOUT_CREATED, WebhookEventAsyncType.CHECKOUT_CREATED+ queries.CHECKOUT_CREATED, WebhookEventAsyncType.CHECKOUT_CREATED)@pytest.fixturedef subscription_checkout_updated_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.CHECKOUT_UPDATED, WebhookEventAsyncType.CHECKOUT_UPDATED+ queries.CHECKOUT_UPDATED, WebhookEventAsyncType.CHECKOUT_UPDATED)@pytest.fixturedef subscription_page_created_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.PAGE_CREATED, WebhookEventAsyncType.PAGE_CREATED+ queries.PAGE_CREATED, WebhookEventAsyncType.PAGE_CREATED)@pytest.fixturedef subscription_page_updated_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.PAGE_UPDATED,+ queries.PAGE_UPDATED,WebhookEventAsyncType.PAGE_UPDATED,)@@ -553,7 +547,7 @@ def subscription_page_updated_webhook(subscription_webhook):@pytest.fixturedef subscription_page_deleted_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.PAGE_DELETED,+ queries.PAGE_DELETED,WebhookEventAsyncType.PAGE_DELETED,)@@ -561,28 +555,28 @@ def subscription_page_deleted_webhook(subscription_webhook):@pytest.fixturedef subscription_page_type_created_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.PAGE_TYPE_CREATED, WebhookEventAsyncType.PAGE_TYPE_CREATED+ queries.PAGE_TYPE_CREATED, WebhookEventAsyncType.PAGE_TYPE_CREATED)@pytest.fixturedef subscription_page_type_updated_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.PAGE_TYPE_UPDATED, WebhookEventAsyncType.PAGE_TYPE_UPDATED+ queries.PAGE_TYPE_UPDATED, WebhookEventAsyncType.PAGE_TYPE_UPDATED)@pytest.fixturedef subscription_page_type_deleted_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.PAGE_TYPE_DELETED, WebhookEventAsyncType.PAGE_TYPE_DELETED+ queries.PAGE_TYPE_DELETED, WebhookEventAsyncType.PAGE_TYPE_DELETED)@pytest.fixturedef subscription_permission_group_created_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.PERMISSION_GROUP_CREATED,+ queries.PERMISSION_GROUP_CREATED,WebhookEventAsyncType.PERMISSION_GROUP_CREATED,)@@ -590,7 +584,7 @@ def subscription_permission_group_created_webhook(subscription_webhook):@pytest.fixturedef subscription_permission_group_updated_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.PERMISSION_GROUP_UPDATED,+ queries.PERMISSION_GROUP_UPDATED,WebhookEventAsyncType.PERMISSION_GROUP_UPDATED,)@@ -598,7 +592,7 @@ def subscription_permission_group_updated_webhook(subscription_webhook):@pytest.fixturedef subscription_permission_group_deleted_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.PERMISSION_GROUP_DELETED,+ queries.PERMISSION_GROUP_DELETED,WebhookEventAsyncType.PERMISSION_GROUP_DELETED,)@@ -606,7 +600,7 @@ def subscription_permission_group_deleted_webhook(subscription_webhook):@pytest.fixturedef subscription_product_created_multiple_events_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.MULTIPLE_EVENTS,+ queries.MULTIPLE_EVENTS,WebhookEventAsyncType.TRANSLATION_CREATED,)@@ -614,14 +608,14 @@ def subscription_product_created_multiple_events_webhook(subscription_webhook):@pytest.fixturedef subscription_staff_created_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.STAFF_CREATED, WebhookEventAsyncType.STAFF_CREATED+ queries.STAFF_CREATED, WebhookEventAsyncType.STAFF_CREATED)@pytest.fixturedef subscription_staff_updated_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.STAFF_UPDATED,+ queries.STAFF_UPDATED,WebhookEventAsyncType.STAFF_UPDATED,)@@ -629,7 +623,7 @@ def subscription_staff_updated_webhook(subscription_webhook):@pytest.fixturedef subscription_staff_deleted_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.STAFF_DELETED,+ queries.STAFF_DELETED,WebhookEventAsyncType.STAFF_DELETED,)@@ -637,7 +631,7 @@ def subscription_staff_deleted_webhook(subscription_webhook):@pytest.fixturedef subscription_translation_created_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.TRANSLATION_CREATED,+ queries.TRANSLATION_CREATED,WebhookEventAsyncType.TRANSLATION_CREATED,)@@ -645,7 +639,7 @@ def subscription_translation_created_webhook(subscription_webhook):@pytest.fixturedef subscription_translation_updated_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.TRANSLATION_UPDATED,+ queries.TRANSLATION_UPDATED,WebhookEventAsyncType.TRANSLATION_UPDATED,)@@ -653,48 +647,171 @@ def subscription_translation_updated_webhook(subscription_webhook):@pytest.fixturedef subscription_warehouse_created_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.WAREHOUSE_CREATED, WebhookEventAsyncType.WAREHOUSE_CREATED+ queries.WAREHOUSE_CREATED, WebhookEventAsyncType.WAREHOUSE_CREATED)@pytest.fixturedef subscription_warehouse_updated_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.WAREHOUSE_UPDATED, WebhookEventAsyncType.WAREHOUSE_UPDATED+ queries.WAREHOUSE_UPDATED, WebhookEventAsyncType.WAREHOUSE_UPDATED)@pytest.fixturedef subscription_warehouse_deleted_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.WAREHOUSE_DELETED, WebhookEventAsyncType.WAREHOUSE_DELETED+ queries.WAREHOUSE_DELETED, WebhookEventAsyncType.WAREHOUSE_DELETED)@pytest.fixturedef subscription_voucher_created_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.VOUCHER_CREATED, WebhookEventAsyncType.VOUCHER_CREATED+ queries.VOUCHER_CREATED, WebhookEventAsyncType.VOUCHER_CREATED)@pytest.fixturedef subscription_voucher_updated_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.VOUCHER_UPDATED, WebhookEventAsyncType.VOUCHER_UPDATED+ queries.VOUCHER_UPDATED, WebhookEventAsyncType.VOUCHER_UPDATED)@pytest.fixturedef subscription_voucher_deleted_webhook(subscription_webhook):return subscription_webhook(- subscription_queries.VOUCHER_DELETED, WebhookEventAsyncType.VOUCHER_DELETED+ queries.VOUCHER_DELETED, WebhookEventAsyncType.VOUCHER_DELETED)@pytest.fixturedef subscription_voucher_webhook_with_meta(subscription_webhook):return subscription_webhook(- subscription_queries.VOUCHER_CREATED_WITH_META,+ queries.VOUCHER_CREATED_WITH_META,WebhookEventAsyncType.VOUCHER_CREATED,)+++def subscription_payment_authorize_webhook(subscription_webhook):+ return subscription_webhook(+ queries.PAYMENT_AUTHORIZE, WebhookEventSyncType.PAYMENT_AUTHORIZE+ )+++def subscription_payment_capture_webhook(subscription_webhook):+ return subscription_webhook(+ queries.PAYMENT_CAPTURE, WebhookEventSyncType.PAYMENT_CAPTURE+ )+++def subscription_payment_refund_webhook(subscription_webhook):+ return subscription_webhook(+ queries.PAYMENT_REFUND, WebhookEventSyncType.PAYMENT_REFUND+ )+++def subscription_payment_void_webhook(subscription_webhook):+ return subscription_webhook(queries.PAYMENT_VOID, WebhookEventSyncType.PAYMENT_VOID)+++def subscription_payment_confirm_webhook(subscription_webhook):+ return subscription_webhook(+ queries.PAYMENT_CONFIRM, WebhookEventSyncType.PAYMENT_CONFIRM+ )+++def subscription_payment_process_webhook(subscription_webhook):+ return subscription_webhook(+ queries.PAYMENT_PROCESS, WebhookEventSyncType.PAYMENT_PROCESS+ )+++def subscription_payment_list_gateways_webhook(subscription_webhook):+ return subscription_webhook(+ queries.PAYMENT_LIST_GATEWAYS,+ WebhookEventSyncType.PAYMENT_LIST_GATEWAYS,+ )+++def subscription_checkout_filter_shipping_methods_webhook(subscription_webhook):+ return subscription_webhook(+ queries.CHECKOUT_FILTER_SHIPPING_METHODS,+ WebhookEventSyncType.CHECKOUT_FILTER_SHIPPING_METHODS,+ )+++def subscription_shipping_list_methods_for_checkout_webhook(subscription_webhook):+ return subscription_webhook(+ queries.SHIPPING_LIST_METHODS_FOR_CHECKOUT,+ WebhookEventSyncType.SHIPPING_LIST_METHODS_FOR_CHECKOUT,+ )+++def subscription_order_filter_shipping_methods_webhook(subscription_webhook):+ return subscription_webhook(+ queries.ORDER_FILTER_SHIPPING_METHODS,+ WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS,+ )+++def subscription_checkout_filter_shipping_method_webhook_with_shipping_methods(+ subscription_webhook,+):+ return subscription_webhook(+ queries.CHECKOUT_FILTER_SHIPPING_METHODS_CIRCULAR_SHIPPING_METHODS,+ WebhookEventSyncType.CHECKOUT_FILTER_SHIPPING_METHODS,+ )+++def subscription_checkout_filter_shipping_method_webhook_with_available_ship_methods(+ subscription_webhook,+):++ return subscription_webhook(+ queries.CHECKOUT_FILTER_SHIPPING_METHODS_AVAILABLE_SHIPPING_METHODS,+ WebhookEventSyncType.CHECKOUT_FILTER_SHIPPING_METHODS,+ )+++def subscription_checkout_filter_shipping_method_webhook_with_payment_gateways(+ subscription_webhook,+):+ return subscription_webhook(+ queries.CHECKOUT_FILTER_SHIPPING_METHODS_AVAILABLE_PAYMENT_GATEWAYS,+ WebhookEventSyncType.CHECKOUT_FILTER_SHIPPING_METHODS,+ )+++def subscription_order_filter_shipping_methods_webhook_with_shipping_methods(+ subscription_webhook,+):+ return subscription_webhook(+ queries.ORDER_FILTER_SHIPPING_METHODS_CIRCULAR_SHIPPING_METHODS,+ WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS,+ )+++def subscription_order_filter_shipping_methods_webhook_with_available_ship_methods(+ subscription_webhook,+):+ return subscription_webhook(+ queries.ORDER_FILTER_SHIPPING_METHODS_AVAILABLE_SHIPPING_METHODS,+ WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS,+ )diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/payloads.py b/saleor/plugins/webhook/tests/subscription_webhooks/payloads.pyindex 1757495774..04d6c56e31 100644--- a/saleor/plugins/webhook/tests/subscription_webhooks/payloads.py+++ b/saleor/plugins/webhook/tests/subscription_webhooks/payloads.py@@ -440,3 +440,15 @@ def generate_warehouse_payload(warehouse, warehouse_global_id):}})+++def generate_payment_payload(payment):+ total = payment.get_total()+ return {+ "payment": {+ "id": graphene.Node.to_global_id("Payment", payment.pk),+ "total": {"amount": float(total.amount), "currency": total.currency},+ "gateway": payment.gateway,+ "isActive": payment.is_active,+ }+ }diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/subscription_queries.py b/saleor/plugins/webhook/tests/subscription_webhooks/subscription_queries.pyindex e3da4798e2..d79ba79842 100644--- a/saleor/plugins/webhook/tests/subscription_webhooks/subscription_queries.py+++ b/saleor/plugins/webhook/tests/subscription_webhooks/subscription_queries.py@@ -1552,3 +1552,236 @@ WAREHOUSE_DELETED = (}""")++PAYMENT_AUTHORIZE = (+ fragments.PAYMENT_DETAILS+ + """+ subscription{+ event{+ ...on PaymentAuthorize{+ payment{+ ...PaymentDetails+ }+ }+ }+ }+ """+)+++PAYMENT_CAPTURE = (+ fragments.PAYMENT_DETAILS+ + """+ subscription{+ event{+ ...on PaymentCaptureEvent{+ payment{+ ...PaymentDetails+ }+ }+ }+ }+ """+)+++PAYMENT_REFUND = (+ fragments.PAYMENT_DETAILS+ + """+ subscription{+ event{+ ...on PaymentRefundEvent{+ payment{+ ...PaymentDetails+ }+ }+ }+ }+ """+)+++PAYMENT_VOID = (+ fragments.PAYMENT_DETAILS+ + """+ subscription{+ event{+ ...on PaymentVoidEvent{+ payment{+ ...PaymentDetails+ }+ }+ }+ }+ """+)+++PAYMENT_CONFIRM = (+ fragments.PAYMENT_DETAILS+ + """+ subscription{+ event{+ ...on PaymentConfirmEvent{+ payment{+ ...PaymentDetails+ }+ }+ }+ }+ """+)+++PAYMENT_PROCESS = (+ fragments.PAYMENT_DETAILS+ + """+ subscription{+ event{+ ...on PaymentProcessEvent{+ payment{+ ...PaymentDetails+ }+ }+ }+ }+ """+)++PAYMENT_LIST_GATEWAYS = """+ subscription{+ event{+ ...on PaymentListGateways{+ checkout{+ id+ }+ }+ }+ }+ """++ORDER_FILTER_SHIPPING_METHODS = """+subscription{+ event{+ ...on OrderFilterShippingMethods{+ order{+ id+ }+ shippingMethods{+ id+ name+ }+ }+ }+}+"""+++CHECKOUT_FILTER_SHIPPING_METHODS = """+subscription{+ event{+ ...on CheckoutFilterShippingMethods{+ checkout{+ id+ }+ shippingMethods{+ name+ id+ }+ }+ }+}+"""+++SHIPPING_LIST_METHODS_FOR_CHECKOUT = """+subscription{+ event{+ ...on ShippingListMethodsForCheckout{+ checkout{+ id+ }+ shippingMethods{+ name+ id+ }+ }+ }+}+"""+++CHECKOUT_FILTER_SHIPPING_METHODS_CIRCULAR_SHIPPING_METHODS = """+subscription{+ event{+ ...on CheckoutFilterShippingMethods{+ checkout{+ id+ shippingMethods{+ id+ }+ }+ }+ }+}+"""++CHECKOUT_FILTER_SHIPPING_METHODS_AVAILABLE_SHIPPING_METHODS = """+subscription{+ event{+ ...on CheckoutFilterShippingMethods{+ checkout{+ id+ availableShippingMethods{+ id+ }+ }+ }+ }+}+"""++CHECKOUT_FILTER_SHIPPING_METHODS_AVAILABLE_PAYMENT_GATEWAYS = """+subscription{+ event{+ ...on CheckoutFilterShippingMethods{+ checkout{+ id+ availablePaymentGateways{+ id+ }+ }+ }+ }+}+"""++ORDER_FILTER_SHIPPING_METHODS_AVAILABLE_SHIPPING_METHODS = """+subscription{+ event{+ ...on OrderFilterShippingMethods{+ order{+ id+ availableShippingMethods{+ id+ }+ }+ }+ }+}+"""++ORDER_FILTER_SHIPPING_METHODS_CIRCULAR_SHIPPING_METHODS = """+subscription{+ event{+ ...on OrderFilterShippingMethods{+ order{+ id+ shippingMethods{+ id+ }+ }+ }+ }+}+"""diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/test_create_deliveries_for_subscription.py b/saleor/plugins/webhook/tests/subscription_webhooks/test_create_deliveries_for_subscription.pyindex e643b9d710..f9cffd08d3 100644--- a/saleor/plugins/webhook/tests/subscription_webhooks/test_create_deliveries_for_subscription.py+++ b/saleor/plugins/webhook/tests/subscription_webhooks/test_create_deliveries_for_subscription.py@@ -12,7 +12,7 @@ from .....graphql.webhook.subscription_payload import validate_subscription_querfrom .....menu.models import Menu, MenuItemfrom .....product.models import Categoryfrom .....shipping.models import ShippingMethod, ShippingZone-from .....webhook.event_types import WebhookEventAsyncType+from .....webhook.event_types import WebhookEventAsyncType, WebhookEventSyncTypefrom ...tasks import create_deliveries_for_subscriptions, loggerfrom . import subscription_queriesfrom .payloads import (@@ -1620,6 +1620,283 @@ def test_voucher_deleted(voucher, subscription_voucher_deleted_webhook):assert deliveries[0].webhook == webhooks[0]+def test_shipping_list_methods_for_checkout(+ checkout_with_shipping_required,+ subscription_shipping_list_methods_for_checkout_webhook,+ address,+ shipping_method,+):+ # given+ checkout = checkout_with_shipping_required+ checkout.shipping_address = address+ checkout.shipping_method = shipping_method+ webhooks = [subscription_shipping_list_methods_for_checkout_webhook]+ event_type = WebhookEventSyncType.SHIPPING_LIST_METHODS_FOR_CHECKOUT+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)+ all_shipping_methods = ShippingMethod.objects.all()+ # when+ deliveries = create_deliveries_for_subscriptions(event_type, checkout, webhooks)+ # then+ expected_payload = {+ "checkout": {"id": checkout_id},+ "shippingMethods": [+ {+ "id": graphene.Node.to_global_id("ShippingMethod", sm.pk),+ "name": sm.name,+ }+ for sm in all_shipping_methods+ ],+ }+ assert json.loads(deliveries[0].payload.payload) == expected_payload+ assert len(deliveries) == len(webhooks)+ assert deliveries[0].webhook == webhooks[0]+++def test_checkout_filter_shipping_methods(+ checkout_with_shipping_required,+ subscription_checkout_filter_shipping_methods_webhook,+ address,+ shipping_method,+):+ # given+ checkout = checkout_with_shipping_required+ checkout.shipping_address = address+ checkout.shipping_method = shipping_method+ webhooks = [subscription_checkout_filter_shipping_methods_webhook]+ event_type = WebhookEventSyncType.CHECKOUT_FILTER_SHIPPING_METHODS+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)+ all_shipping_methods = ShippingMethod.objects.all()+ # when+ deliveries = create_deliveries_for_subscriptions(event_type, checkout, webhooks)+ # then+ expected_payload = {+ "checkout": {"id": checkout_id},+ "shippingMethods": [+ {+ "id": graphene.Node.to_global_id("ShippingMethod", sm.pk),+ "name": sm.name,+ }+ for sm in all_shipping_methods+ ],+ }+ assert json.loads(deliveries[0].payload.payload) == expected_payload+ assert len(deliveries) == len(webhooks)+ assert deliveries[0].webhook == webhooks[0]+++def test_checkout_filter_shipping_methods_no_methods_in_channel(+ checkout,+ subscription_checkout_filter_shipping_methods_webhook,+ address,+ shipping_method,+ shipping_method_channel_PLN,+):+ # given+ webhooks = [subscription_checkout_filter_shipping_methods_webhook]+ event_type = WebhookEventSyncType.CHECKOUT_FILTER_SHIPPING_METHODS+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)++ # when+ deliveries = create_deliveries_for_subscriptions(event_type, checkout, webhooks)++ # then+ expected_payload = {"checkout": {"id": checkout_id}, "shippingMethods": []}+ assert json.loads(deliveries[0].payload.payload) == expected_payload+ assert len(deliveries) == len(webhooks)+ assert deliveries[0].webhook == webhooks[0]+++def test_checkout_filter_shipping_methods_with_circular_call_for_shipping_methods(+ checkout_ready_to_complete,+ subscription_checkout_filter_shipping_method_webhook_with_shipping_methods,+):++ # given+ webhooks = [+ subscription_checkout_filter_shipping_method_webhook_with_shipping_methods+ ]+ event_type = WebhookEventSyncType.CHECKOUT_FILTER_SHIPPING_METHODS++ # when+ deliveries = create_deliveries_for_subscriptions(+ event_type, checkout_ready_to_complete, webhooks+ )++ # then+ payload = json.loads(deliveries[0].payload.payload)++ assert len(payload["errors"]) == 1+ assert (+ payload["errors"][0]["message"]+ == "Resolving this field is not allowed in synchronous events."+ )+ assert payload["checkout"] is None+++def test_checkout_filter_shipping_methods_with_available_shipping_methods_field(+ checkout_ready_to_complete,+ subscription_checkout_filter_shipping_method_webhook_with_available_ship_methods,+):++ # given+ webhooks = [+ subscription_checkout_filter_shipping_method_webhook_with_available_ship_methods+ ]+ event_type = WebhookEventSyncType.CHECKOUT_FILTER_SHIPPING_METHODS++ # when+ deliveries = create_deliveries_for_subscriptions(+ event_type, checkout_ready_to_complete, webhooks+ )++ # then+ payload = json.loads(deliveries[0].payload.payload)++ assert len(payload["errors"]) == 1+ assert (+ payload["errors"][0]["message"]+ == "Resolving this field is not allowed in synchronous events."+ )+ assert payload["checkout"] is None+++def test_checkout_filter_shipping_methods_with_circular_call_for_available_gateways(+ checkout_ready_to_complete,+ subscription_checkout_filter_shipping_method_webhook_with_payment_gateways,+):++ # given+ webhooks = [+ subscription_checkout_filter_shipping_method_webhook_with_payment_gateways+ ]+ event_type = WebhookEventSyncType.CHECKOUT_FILTER_SHIPPING_METHODS++ # when+ deliveries = create_deliveries_for_subscriptions(+ event_type, checkout_ready_to_complete, webhooks+ )++ # then+ payload = json.loads(deliveries[0].payload.payload)++ assert len(payload["errors"]) == 1+ assert (+ payload["errors"][0]["message"]+ == "Resolving this field is not allowed in synchronous events."+ )+ assert payload["checkout"] is None+++def test_order_filter_shipping_methods(+ order_line_with_one_allocation,+ subscription_order_filter_shipping_methods_webhook,+ address,+):+ # given+ order = order_line_with_one_allocation.order+ order_line_with_one_allocation.is_shipping_required = True+ order_line_with_one_allocation.save(update_fields=["is_shipping_required"])++ order.currency = "USD"+ order.shipping_address = address+ order.save(update_fields=["shipping_address"])+ webhooks = [subscription_order_filter_shipping_methods_webhook]+ event_type = WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS+ order_id = graphene.Node.to_global_id("Order", order.pk)+ all_shipping_methods = ShippingMethod.objects.all()++ # when+ deliveries = create_deliveries_for_subscriptions(event_type, order, webhooks)+ # then+ expected_payload = {+ "order": {"id": order_id},+ "shippingMethods": [+ {+ "id": graphene.Node.to_global_id("ShippingMethod", sm.pk),+ "name": sm.name,+ }+ for sm in all_shipping_methods+ ],+ }+ assert json.loads(deliveries[0].payload.payload) == expected_payload+ assert len(deliveries) == len(webhooks)+ assert deliveries[0].webhook == webhooks[0]+++def test_order_filter_shipping_methods_no_methods_in_channel(+ order_line_with_one_allocation,+ subscription_order_filter_shipping_methods_webhook,+ shipping_method_channel_PLN,+):+ # given+ order = order_line_with_one_allocation.order+ order.save(update_fields=["shipping_address"])+ webhooks = [subscription_order_filter_shipping_methods_webhook]+ event_type = WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS+ order_id = graphene.Node.to_global_id("Order", order.pk)++ # when+ deliveries = create_deliveries_for_subscriptions(event_type, order, webhooks)++ # then+ expected_payload = {"order": {"id": order_id}, "shippingMethods": []}++ assert json.loads(deliveries[0].payload.payload) == expected_payload+ assert len(deliveries) == len(webhooks)+ assert deliveries[0].webhook == webhooks[0]+++def test_order_filter_shipping_methods_with_circular_call_for_available_methods(+ order_line_with_one_allocation,+ subscription_order_filter_shipping_methods_webhook_with_available_ship_methods,+):++ # given+ webhooks = [+ subscription_order_filter_shipping_methods_webhook_with_available_ship_methods+ ]+ event_type = WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS+ order = order_line_with_one_allocation.order++ # when+ deliveries = create_deliveries_for_subscriptions(event_type, order, webhooks)++ # then+ payload = json.loads(deliveries[0].payload.payload)++ assert len(payload["errors"]) == 1+ assert (+ payload["errors"][0]["message"]+ == "Resolving this field is not allowed in synchronous events."+ )+++def test_order_filter_shipping_methods_with_circular_call_for_shipping_methods(+ order_line_with_one_allocation,+ subscription_order_filter_shipping_methods_webhook_with_shipping_methods,+):++ # given+ webhooks = [+ subscription_order_filter_shipping_methods_webhook_with_shipping_methods+ ]+ event_type = WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS+ order = order_line_with_one_allocation.order++ # when+ deliveries = create_deliveries_for_subscriptions(event_type, order, webhooks)++ # then+ payload = json.loads(deliveries[0].payload.payload)++ assert len(payload["errors"]) == 1+ assert (+ payload["errors"][0]["message"]+ == "Resolving this field is not allowed in synchronous events."+ )+ assert payload["order"] is None++@patch.object(logger, "info")def test_create_deliveries_for_subscriptions_unsubscribable_event(mocked_logger, product, subscription_product_updated_webhook, any_webhookdiff --git a/saleor/plugins/webhook/tests/subscription_webhooks/test_create_deliveries_for_subscriptions_payments.py b/saleor/plugins/webhook/tests/subscription_webhooks/test_create_deliveries_for_subscriptions_payments.pynew file mode 100644index 0000000000..907228981a--- /dev/null+++ b/saleor/plugins/webhook/tests/subscription_webhooks/test_create_deliveries_for_subscriptions_payments.py@@ -0,0 +1,115 @@+import json++import graphene++from .....webhook.event_types import WebhookEventSyncType+from ...tasks import create_deliveries_for_subscriptions+from .payloads import generate_payment_payload+++def test_payment_authorize(payment, subscription_payment_authorize_webhook):+ # given+ webhooks = [subscription_payment_authorize_webhook]+ event_type = WebhookEventSyncType.PAYMENT_AUTHORIZE++ # when+ deliveries = create_deliveries_for_subscriptions(event_type, payment, webhooks)++ # then+ expected_payload = generate_payment_payload(payment)+ assert json.loads(deliveries[0].payload.payload) == expected_payload+ assert len(deliveries) == len(webhooks)+ assert deliveries[0].webhook == webhooks[0]+++def test_payment_capture(payment, subscription_payment_capture_webhook):+ # given+ webhooks = [subscription_payment_capture_webhook]+ event_type = WebhookEventSyncType.PAYMENT_CAPTURE++ # when+ deliveries = create_deliveries_for_subscriptions(event_type, payment, webhooks)++ # then+ expected_payload = generate_payment_payload(payment)+ assert json.loads(deliveries[0].payload.payload) == expected_payload+ assert len(deliveries) == len(webhooks)+ assert deliveries[0].webhook == webhooks[0]+++def test_payment_refund(payment, subscription_payment_refund_webhook):+ # given+ webhooks = [subscription_payment_refund_webhook]+ event_type = WebhookEventSyncType.PAYMENT_REFUND++ # when+ deliveries = create_deliveries_for_subscriptions(event_type, payment, webhooks)++ # then+ expected_payload = generate_payment_payload(payment)+ assert json.loads(deliveries[0].payload.payload) == expected_payload+ assert len(deliveries) == len(webhooks)+ assert deliveries[0].webhook == webhooks[0]+++def test_payment_void(payment, subscription_payment_void_webhook):+ # given+ webhooks = [subscription_payment_void_webhook]+ event_type = WebhookEventSyncType.PAYMENT_VOID++ # when+ deliveries = create_deliveries_for_subscriptions(event_type, payment, webhooks)++ # then+ expected_payload = generate_payment_payload(payment)+ assert json.loads(deliveries[0].payload.payload) == expected_payload+ assert len(deliveries) == len(webhooks)+ assert deliveries[0].webhook == webhooks[0]+++def test_payment_confirm(payment, subscription_payment_confirm_webhook):+ # given+ webhooks = [subscription_payment_confirm_webhook]+ event_type = WebhookEventSyncType.PAYMENT_CONFIRM++ # when+ deliveries = create_deliveries_for_subscriptions(event_type, payment, webhooks)++ # then+ expected_payload = generate_payment_payload(payment)+ assert json.loads(deliveries[0].payload.payload) == expected_payload+ assert len(deliveries) == len(webhooks)+ assert deliveries[0].webhook == webhooks[0]+++def test_payment_process(payment, subscription_payment_process_webhook):+ # given+ webhooks = [subscription_payment_process_webhook]+ event_type = WebhookEventSyncType.PAYMENT_PROCESS++ # when+ deliveries = create_deliveries_for_subscriptions(event_type, payment, webhooks)++ # then+ expected_payload = generate_payment_payload(payment)+ assert json.loads(deliveries[0].payload.payload) == expected_payload+ assert len(deliveries) == len(webhooks)+ assert deliveries[0].webhook == webhooks[0]+++def test_payment_list_gateways(checkout, subscription_payment_list_gateways_webhook):+ # given++ webhooks = [subscription_payment_list_gateways_webhook]+ event_type = WebhookEventSyncType.PAYMENT_LIST_GATEWAYS+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)++ # when++ deliveries = create_deliveries_for_subscriptions(event_type, checkout, webhooks)++ # then+ expected_payload = {"checkout": {"id": checkout_id}}+ assert json.loads(deliveries[0].payload.payload) == expected_payload+ assert len(deliveries) == len(webhooks)+ assert deliveries[0].webhook == webhooks[0]diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/test_webhook.py b/saleor/plugins/webhook/tests/subscription_webhooks/test_webhook.pyindex e97f6481b4..31134a6701 100644--- a/saleor/plugins/webhook/tests/subscription_webhooks/test_webhook.py+++ b/saleor/plugins/webhook/tests/subscription_webhooks/test_webhook.py@@ -1,9 +1,12 @@import dataclasses+import jsonfrom unittest import mock-from .....webhook.event_types import WebhookEventAsyncType+from .....core.models import EventDelivery+from .....webhook.event_types import WebhookEventAsyncType, WebhookEventSyncTypefrom .....webhook.models import Webhook-from ...tasks import trigger_webhooks_async+from ...tasks import trigger_webhook_sync, trigger_webhooks_async+from .payloads import generate_payment_payloadTEST_ID = "test_id"@@ -26,3 +29,22 @@ def test_trigger_webhooks_async_no_subscription_webhooks(data = {"regular_webhook": "data"}trigger_webhooks_async(data, webhook_type, webhooks, order)mocked_create_deliveries_for_subscriptions.assert_not_called()++[email protected]("saleor.plugins.webhook.tasks.send_webhook_request_sync")+def test_trigger_webhook_sync_with_subscription(+ mock_request, payment_app_with_subscription_webhooks, payment+):+ # given+ payment_app = payment_app_with_subscription_webhooks+ data = '{"key": "value"}'+ expected_payment_payload = generate_payment_payload(payment)+ # when+ trigger_webhook_sync(+ WebhookEventSyncType.PAYMENT_AUTHORIZE, data, payment_app, payment+ )+ event_delivery = EventDelivery.objects.first()++ # then+ assert json.loads(event_delivery.payload.payload) == expected_payment_payload+ mock_request.assert_called_once_with(payment_app.name, event_delivery)diff --git a/saleor/plugins/webhook/tests/test_payment_webhook.py b/saleor/plugins/webhook/tests/test_payment_webhook.pyindex 301d327c53..bf4fe04106 100644--- a/saleor/plugins/webhook/tests/test_payment_webhook.py+++ b/saleor/plugins/webhook/tests/test_payment_webhook.py@@ -55,6 +55,24 @@ def test_trigger_webhook_sync(mock_request, payment_app):mock_request.assert_called_once_with(payment_app.name, event_delivery)[email protected]("saleor.plugins.webhook.tasks.create_delivery_for_subscription_sync_event")[email protected]("saleor.plugins.webhook.tasks.send_webhook_request_sync")+def test_trigger_webhook_sync_with_subscription(+ mock_request,+ mock_delivery_create,+ payment,+ payment_app_with_subscription_webhooks,+):+ payment_app = payment_app_with_subscription_webhooks+ data = '{"key": "value"}'+ fake_delivery = "fake_delivery"+ mock_delivery_create.return_value = fake_delivery+ trigger_webhook_sync(+ WebhookEventSyncType.PAYMENT_CAPTURE, data, payment_app, payment+ )+ mock_request.assert_called_once_with(payment_app.name, fake_delivery)++@mock.patch("saleor.plugins.webhook.tasks.send_webhook_request_sync")def test_trigger_webhook_sync_use_first_webhook(mock_request, payment_app):webhook_1 = payment_app.webhooks.first()diff --git a/saleor/plugins/webhook/tests/test_shipping_webhook.py b/saleor/plugins/webhook/tests/test_shipping_webhook.pyindex c5d2dcba0f..0431348cdd 100644--- a/saleor/plugins/webhook/tests/test_shipping_webhook.py+++ b/saleor/plugins/webhook/tests/test_shipping_webhook.py@@ -119,7 +119,8 @@ def test_excluded_shipping_methods_for_order(WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS,payload,shipping_app,- EXCLUDED_SHIPPING_REQUEST_TIMEOUT,+ subscribable_object=order_with_lines,+ timeout=EXCLUDED_SHIPPING_REQUEST_TIMEOUT,)expected_cache_key = CACHE_EXCLUDED_SHIPPING_KEY + str(order_with_lines.id)@@ -198,13 +199,15 @@ def test_multiple_app_with_excluded_shipping_methods_for_order(WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS,payload,shipping_app,- EXCLUDED_SHIPPING_REQUEST_TIMEOUT,+ subscribable_object=order_with_lines,+ timeout=EXCLUDED_SHIPPING_REQUEST_TIMEOUT,)mocked_webhook.assert_any_call(WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS,payload,second_shipping_app,- EXCLUDED_SHIPPING_REQUEST_TIMEOUT,+ subscribable_object=order_with_lines,+ timeout=EXCLUDED_SHIPPING_REQUEST_TIMEOUT,)expected_cache_key = CACHE_EXCLUDED_SHIPPING_KEY + str(order_with_lines.id)@@ -464,7 +467,8 @@ def test_excluded_shipping_methods_for_checkout(WebhookEventSyncType.CHECKOUT_FILTER_SHIPPING_METHODS,payload,shipping_app,- EXCLUDED_SHIPPING_REQUEST_TIMEOUT,+ subscribable_object=checkout_with_items,+ timeout=EXCLUDED_SHIPPING_REQUEST_TIMEOUT,)expected_cache_key = CACHE_EXCLUDED_SHIPPING_KEY + str(checkout_with_items.token)@@ -544,13 +548,15 @@ def test_multiple_app_with_excluded_shipping_methods_for_checkout(WebhookEventSyncType.CHECKOUT_FILTER_SHIPPING_METHODS,payload,shipping_app,- EXCLUDED_SHIPPING_REQUEST_TIMEOUT,+ subscribable_object=checkout_with_items,+ timeout=EXCLUDED_SHIPPING_REQUEST_TIMEOUT,)mocked_webhook.assert_any_call(WebhookEventSyncType.CHECKOUT_FILTER_SHIPPING_METHODS,payload,second_shipping_app,- EXCLUDED_SHIPPING_REQUEST_TIMEOUT,+ subscribable_object=checkout_with_items,+ timeout=EXCLUDED_SHIPPING_REQUEST_TIMEOUT,)expected_cache_key = CACHE_EXCLUDED_SHIPPING_KEY + str(checkout_with_items.token)diff --git a/saleor/tests/fixtures.py b/saleor/tests/fixtures.pyindex c15db2269c..459d7a195d 100644--- a/saleor/tests/fixtures.py+++ b/saleor/tests/fixtures.py@@ -92,6 +92,7 @@ from ..plugins.manager import get_plugins_managerfrom ..plugins.models import PluginConfigurationfrom ..plugins.vatlayer.plugin import VatlayerPluginfrom ..plugins.webhook.tasks import WebhookResponse+from ..plugins.webhook.tests.subscription_webhooks import subscription_queriesfrom ..plugins.webhook.utils import to_payment_app_idfrom ..product import ProductMediaTypes, ProductTypeKindfrom ..product.models import (@@ -5452,6 +5453,27 @@ def payment_app(db, permission_manage_payments):return app+def payment_app_with_subscription_webhooks(db, permission_manage_payments):+ app = App.objects.create(name="Payment App", is_active=True)+ app.tokens.create(name="Default")+ app.permissions.add(permission_manage_payments)++ webhook = Webhook.objects.create(+ name="payment-subscription-webhook-1",+ app=app,+ target_url="https://payment-gateway.com/api/",+ subscription_query=subscription_queries.PAYMENT_AUTHORIZE,+ )+ webhook.events.bulk_create(+ [+ WebhookEvent(event_type=event_type, webhook=webhook)+ for event_type in WebhookEventSyncType.PAYMENT_EVENTS+ ]+ )+ return app++@pytest.fixturedef shipping_app(db, permission_manage_shipping):app = App.objects.create(name="Shipping App", is_active=True)diff --git a/saleor/webhook/event_types.py b/saleor/webhook/event_types.pyindex a489b02696..3c1bf7f21b 100644--- a/saleor/webhook/event_types.py+++ b/saleor/webhook/event_types.py@@ -605,6 +605,16 @@ SUBSCRIBABLE_EVENTS = [WebhookEventAsyncType.VOUCHER_CREATED,WebhookEventAsyncType.VOUCHER_UPDATED,WebhookEventAsyncType.VOUCHER_DELETED,+ WebhookEventSyncType.PAYMENT_AUTHORIZE,+ WebhookEventSyncType.PAYMENT_CAPTURE,+ WebhookEventSyncType.PAYMENT_REFUND,+ WebhookEventSyncType.PAYMENT_VOID,+ WebhookEventSyncType.PAYMENT_CONFIRM,+ WebhookEventSyncType.PAYMENT_PROCESS,+ WebhookEventSyncType.PAYMENT_LIST_GATEWAYS,+ WebhookEventSyncType.SHIPPING_LIST_METHODS_FOR_CHECKOUT,+ WebhookEventSyncType.CHECKOUT_FILTER_SHIPPING_METHODS,+ WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS,WebhookEventAsyncType.WAREHOUSE_CREATED,WebhookEventAsyncType.WAREHOUSE_UPDATED,WebhookEventAsyncType.WAREHOUSE_DELETED,