Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add checkoutFullyAuthorized webhook (#18153)
Maciej Korycinski3c5dcc46513f
diff --git a/saleor/checkout/actions.py b/saleor/checkout/actions.pyindex ab178d7a3f..8d5dbcb958 100644--- a/saleor/checkout/actions.py+++ b/saleor/checkout/actions.py@@ -36,6 +36,7 @@ from ..plugins.manager import PluginsManagerCHECKOUT_WEBHOOK_EVENT_MAP = {WebhookEventAsyncType.CHECKOUT_CREATED: PluginsManager.checkout_created.__name__,WebhookEventAsyncType.CHECKOUT_UPDATED: PluginsManager.checkout_updated.__name__,+ WebhookEventAsyncType.CHECKOUT_FULLY_AUTHORIZED: PluginsManager.checkout_fully_authorized.__name__,WebhookEventAsyncType.CHECKOUT_FULLY_PAID: PluginsManager.checkout_fully_paid.__name__,WebhookEventAsyncType.CHECKOUT_METADATA_UPDATED: PluginsManager.checkout_metadata_updated.__name__,}@@ -310,16 +311,26 @@ def _transaction_amounts_for_checkout_updated(checkout_info=checkout_info,lines=lines,)+ previous_authorize_status_is_full = (+ previous_authorize_status == CheckoutAuthorizeStatus.FULL+ )+ current_authorize_status_is_full = (+ checkout_info.checkout.authorize_status == CheckoutAuthorizeStatus.FULL+ )+ if not previous_authorize_status_is_full and current_authorize_status_is_full:+ call_checkout_info_event(+ manager,+ event_name=WebhookEventAsyncType.CHECKOUT_FULLY_AUTHORIZED,+ checkout_info=checkout_info,+ lines=lines,+ )channel = checkout_info.channelif (channel.automatically_complete_fully_paid_checkoutsand# ensure that checkout completion is triggered only once- (- previous_authorize_status != CheckoutAuthorizeStatus.FULL- and checkout_info.checkout.authorize_status == CheckoutAuthorizeStatus.FULL- )+ (not previous_authorize_status_is_full and current_authorize_status_is_full)):user_id = user.id if user else Noneapp_id = app.id if app else Nonediff --git a/saleor/checkout/tests/test_actions.py b/saleor/checkout/tests/test_actions.pyindex 9bf3d9f8fe..739f32ee6b 100644--- a/saleor/checkout/tests/test_actions.py+++ b/saleor/checkout/tests/test_actions.py@@ -26,7 +26,9 @@ from ..fetch import fetch_checkout_info, fetch_checkout_lines@patch("saleor.checkout.tasks.automatic_checkout_completion_task.delay")@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")def test_transaction_amounts_for_checkout_updated_fully_paid(+ mocked_fully_authorized,mocked_fully_paid,mocked_automatic_checkout_completion_task,checkout_with_items,@@ -55,12 +57,15 @@ def test_transaction_amounts_for_checkout_updated_fully_paid(assert checkout.charge_status == CheckoutChargeStatus.FULLassert checkout.authorize_status == CheckoutAuthorizeStatus.FULLmocked_fully_paid.assert_called_with(checkout, webhooks=set())+ mocked_fully_authorized.assert_called_with(checkout, webhooks=set())assert not mocked_automatic_checkout_completion_task.called@patch("saleor.checkout.tasks.automatic_checkout_completion_task.delay")@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")def test_transaction_amounts_for_checkout_fully_paid_automatic_checkout_complete(+ mocked_fully_authorized,mocked_fully_paid,mocked_automatic_checkout_completion_task,checkout_with_items,@@ -92,6 +97,7 @@ def test_transaction_amounts_for_checkout_fully_paid_automatic_checkout_completeassert checkout.charge_status == CheckoutChargeStatus.FULLassert checkout.authorize_status == CheckoutAuthorizeStatus.FULLmocked_fully_paid.assert_called_once_with(checkout, webhooks=set())+ mocked_fully_authorized.assert_called_once_with(checkout, webhooks=set())mocked_automatic_checkout_completion_task.assert_called_once_with(checkout.pk, None, app.id)@@ -99,7 +105,9 @@ def test_transaction_amounts_for_checkout_fully_paid_automatic_checkout_complete@patch("saleor.checkout.tasks.automatic_checkout_completion_task.delay")@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")def test_transaction_amounts_for_checkout_updated_not_fully_paid_no_automatic_complete(+ mocked_fully_authorized,mocked_fully_paid,mocked_automatic_checkout_completion_task,checkout_with_items,@@ -130,14 +138,17 @@ def test_transaction_amounts_for_checkout_updated_not_fully_paid_no_automatic_cocheckout.refresh_from_db()assert checkout.charge_status == CheckoutChargeStatus.PARTIALassert checkout.authorize_status == CheckoutAuthorizeStatus.PARTIAL+ assert not mocked_fully_authorized.calledassert not mocked_fully_paid.calledassert not mocked_automatic_checkout_completion_task.called@patch("saleor.checkout.tasks.automatic_checkout_completion_task.delay")@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")def test_transaction_amounts_for_checkout_updated_with_already_fully_paid(mocked_fully_paid,+ mocked_fully_authorized,mocked_automatic_checkout_completion_task,checkout_with_items,transaction_item_generator,@@ -170,12 +181,67 @@ def test_transaction_amounts_for_checkout_updated_with_already_fully_paid(assert checkout.charge_status == CheckoutChargeStatus.OVERCHARGEDassert checkout.authorize_status == CheckoutAuthorizeStatus.FULLassert not mocked_fully_paid.called+ assert not mocked_fully_authorized.calledassert not mocked_automatic_checkout_completion_task.called@patch("saleor.checkout.tasks.automatic_checkout_completion_task.delay")@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")+def test_transaction_amounts_for_checkout_updated_with_already_fully_authorized(+ mocked_fully_paid,+ mocked_fully_authorized,+ mocked_automatic_checkout_completion_task,+ checkout_with_items,+ transaction_item_generator,+ plugins_manager,+ django_capture_on_commit_callbacks,+):+ # given+ checkout = checkout_with_items+ lines, _ = fetch_checkout_lines(checkout)+ checkout_info = fetch_checkout_info(checkout, lines, plugins_manager)+ checkout_info, _ = fetch_checkout_data(checkout_info, plugins_manager, lines)+ total = calculate_checkout_total(+ manager=plugins_manager, checkout_info=checkout_info, lines=lines, address=None+ )++ first_authorized_amount = total.gross.amount - 1+ second_authorized_amount = 1+ transaction_item_generator(+ checkout_id=checkout.pk,+ authorized_value=first_authorized_amount,+ )++ second_transaction = transaction_item_generator(+ checkout_id=checkout.pk, authorized_value=second_authorized_amount+ )++ fetch_checkout_data(checkout_info, plugins_manager, lines, force_status_update=True)++ assert checkout.authorize_status == CheckoutAuthorizeStatus.FULL+ assert checkout.charge_status == CheckoutChargeStatus.NONE++ # when+ with django_capture_on_commit_callbacks(execute=True):+ transaction_amounts_for_checkout_updated(+ second_transaction, manager=plugins_manager, user=None, app=None+ )++ # then+ checkout.refresh_from_db()+ assert checkout.authorize_status == CheckoutAuthorizeStatus.FULL+ assert checkout.charge_status == CheckoutChargeStatus.NONE+ assert not mocked_fully_paid.called+ assert not mocked_fully_authorized.called+ assert not mocked_automatic_checkout_completion_task.called+++@patch("saleor.checkout.tasks.automatic_checkout_completion_task.delay")+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")def test_transaction_amounts_for_checkout_updated_fully_authorized(+ mocked_fully_authorized,mocked_fully_paid,mocked_automatic_checkout_completion_task,checkout_with_items,@@ -206,11 +272,14 @@ def test_transaction_amounts_for_checkout_updated_fully_authorized(assert checkout.authorize_status == CheckoutAuthorizeStatus.FULLassert not mocked_fully_paid.calledassert not mocked_automatic_checkout_completion_task.called+ mocked_fully_authorized.assert_called_once_with(checkout, webhooks=set())@patch("saleor.checkout.tasks.automatic_checkout_completion_task.delay")@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")def test_transaction_amounts_for_checkout_fully_authorized_automatic_checkout_complete(+ mocked_fully_authorized,mocked_fully_paid,mocked_automatic_checkout_completion_task,checkout_with_items,@@ -246,11 +315,14 @@ def test_transaction_amounts_for_checkout_fully_authorized_automatic_checkout_comocked_automatic_checkout_completion_task.assert_called_once_with(checkout.pk, staff_user.id, None)+ mocked_fully_authorized.assert_called_once_with(checkout, webhooks=set())@patch("saleor.checkout.tasks.automatic_checkout_completion_task.delay")@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")def test_transaction_amounts_automatic_checkout_complete_called_once(+ mocked_fully_authorized,mocked_fully_paid,mocked_automatic_checkout_completion_task,checkout_with_items,@@ -294,6 +366,7 @@ def test_transaction_amounts_automatic_checkout_complete_called_once(mocked_automatic_checkout_completion_task.assert_called_once_with(checkout.pk, None, app.id)+ mocked_fully_authorized.assert_called_once_with(checkout, webhooks=set())@pytest.mark.parametrize(@@ -1325,11 +1398,129 @@ def test_transaction_amounts_for_checkout_fully_paid_triggers_sync_webhook(assert tax_delivery.webhook_id == tax_webhook.idassert wrapped_call_checkout_info_event.called- mocked_call_event_including_protected_events.assert_called_once_with(++ assert mocked_call_event_including_protected_events.call_count == 2+ mocked_call_event_including_protected_events.assert_any_call(plugins_manager.checkout_fully_paid,checkout_with_items,webhooks={checkout_fully_paid_webhook},)+ mocked_call_event_including_protected_events.assert_any_call(+ plugins_manager.checkout_fully_authorized,+ checkout_with_items,+ webhooks=set(),+ )+++@freeze_time("2023-05-31 12:00:01")+@patch(+ "saleor.checkout.actions.call_checkout_info_event",+ wraps=call_checkout_info_event,+)+@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")+@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_authorized_triggers_sync_webhook(+ mocked_call_event_including_protected_events,+ mocked_send_webhook_request_async,+ mocked_send_webhook_request_sync,+ wrapped_call_checkout_info_event,+ setup_checkout_webhooks,+ settings,+ checkout_with_items,+ transaction_item_generator,+ django_capture_on_commit_callbacks,+ address,+):+ # given+ plugins_manager = get_plugins_manager(allow_replica=False)+ checkout_with_items.price_expiration = timezone.now() - datetime.timedelta(hours=10)++ # Ensure shipping is set so shipping webhooks are emitted+ checkout_with_items.shipping_address = address+ checkout_with_items.billing_address = address++ checkout_with_items.save(+ update_fields=["price_expiration", "billing_address", "shipping_address"]+ )++ mocked_send_webhook_request_sync.return_value = []+ (+ tax_webhook,+ shipping_webhook,+ shipping_filter_webhook,+ checkout_fully_authorized_webhook,+ ) = setup_checkout_webhooks(WebhookEventAsyncType.CHECKOUT_FULLY_AUTHORIZED)+ checkout = checkout_with_items+ lines, _ = fetch_checkout_lines(checkout)+ checkout_info = fetch_checkout_info(checkout, lines, plugins_manager)+ checkout_info, _ = fetch_checkout_data(checkout_info, plugins_manager, lines)++ transaction = transaction_item_generator(+ checkout_id=checkout.pk,+ authorized_value=checkout_info.checkout.total.gross.amount,+ )++ # when+ with django_capture_on_commit_callbacks(execute=True):+ transaction_amounts_for_checkout_updated(+ transaction, manager=plugins_manager, user=None, app=None+ )++ # then++ # confirm that event delivery was generated for each async webhook.+ checkout_fully_authorized_delivery = EventDelivery.objects.get(+ webhook_id=checkout_fully_authorized_webhook.id+ )+ mocked_send_webhook_request_async.assert_called_once_with(+ kwargs={+ "event_delivery_id": checkout_fully_authorized_delivery.id,+ "telemetry_context": ANY,+ },+ queue=settings.CHECKOUT_WEBHOOK_EVENTS_CELERY_QUEUE_NAME,+ MessageGroupId="example.com:saleor.app.additional",+ )++ # confirm each sync webhook was called without saving event delivery+ assert mocked_send_webhook_request_sync.call_count == 3+ assert not EventDelivery.objects.exclude(+ webhook_id=checkout_fully_authorized_webhook.id+ ).exists()++ tax_delivery_call, shipping_methods_call, filter_shipping_call = (+ mocked_send_webhook_request_sync.mock_calls+ )+ shipping_methods_delivery = shipping_methods_call.args[0]+ assert shipping_methods_delivery.webhook_id == shipping_webhook.id+ assert (+ shipping_methods_delivery.event_type+ == WebhookEventSyncType.SHIPPING_LIST_METHODS_FOR_CHECKOUT+ )++ filter_shipping_delivery = filter_shipping_call.args[0]+ assert filter_shipping_delivery.webhook_id == shipping_filter_webhook.id+ assert (+ filter_shipping_delivery.event_type+ == WebhookEventSyncType.CHECKOUT_FILTER_SHIPPING_METHODS+ )++ tax_delivery = tax_delivery_call.args[0]+ assert tax_delivery.webhook_id == tax_webhook.id++ assert wrapped_call_checkout_info_event.called++ mocked_call_event_including_protected_events.assert_called_once_with(+ plugins_manager.checkout_fully_authorized,+ checkout_with_items,+ webhooks={checkout_fully_authorized_webhook},+ )@freeze_time("2023-05-31 12:00:01")diff --git a/saleor/graphql/payment/tests/mutations/test_transaction_create.py b/saleor/graphql/payment/tests/mutations/test_transaction_create.pyindex 2e6de6d11f..0b5a718cb8 100644--- a/saleor/graphql/payment/tests/mutations/test_transaction_create.py+++ b/saleor/graphql/payment/tests/mutations/test_transaction_create.py@@ -1199,7 +1199,9 @@ def test_transaction_create_for_checkout_by_staff(@patch("saleor.checkout.tasks.automatic_checkout_completion_task.delay")@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")def test_transaction_create_for_checkout_fully_paid(+ mocked_checkout_fully_authorized,mocked_checkout_fully_paid,mocked_automatic_checkout_completion_task,checkout_with_prices,@@ -1249,12 +1251,15 @@ def test_transaction_create_for_checkout_fully_paid(assert checkout.authorize_status == CheckoutAuthorizeStatus.FULLmocked_checkout_fully_paid.assert_called_once_with(checkout, webhooks=set())+ mocked_checkout_fully_authorized.assert_called_once_with(checkout, webhooks=set())mocked_automatic_checkout_completion_task.assert_not_called()+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")def test_transaction_create_for_checkout_fully_paid_automatic_completion(mocked_checkout_fully_paid,+ mocked_checkout_fully_authorized,checkout_with_prices,permission_manage_payments,staff_api_client,@@ -1302,6 +1307,7 @@ def test_transaction_create_for_checkout_fully_paid_automatic_completion(# thenmocked_checkout_fully_paid.assert_called_once_with(checkout, webhooks=set())+ mocked_checkout_fully_authorized.assert_called_once_with(checkout, webhooks=set())with pytest.raises(Checkout.DoesNotExist):checkout.refresh_from_db()@@ -1314,9 +1320,11 @@ def test_transaction_create_for_checkout_fully_paid_automatic_completion(@patch("saleor.checkout.tasks.automatic_checkout_completion_task.delay")+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")def test_transaction_create_for_checkout_fully_authorized(mocked_checkout_fully_paid,+ mocked_checkout_fully_authorized,mocked_automatic_checkout_completion_task,checkout_with_prices,permission_manage_payments,@@ -1364,13 +1372,16 @@ def test_transaction_create_for_checkout_fully_authorized(assert checkout.charge_status == CheckoutChargeStatus.NONEassert checkout.authorize_status == CheckoutAuthorizeStatus.FULL+ mocked_checkout_fully_authorized.assert_called_once_with(checkout, webhooks=set())mocked_checkout_fully_paid.assert_not_called()mocked_automatic_checkout_completion_task.assert_not_called()+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")def test_transaction_create_for_checkout_fully_authorized_automatic_completion(mocked_checkout_fully_paid,+ mocked_checkout_fully_authorized,checkout_with_prices,permission_manage_payments,staff_api_client,@@ -1417,6 +1428,7 @@ def test_transaction_create_for_checkout_fully_authorized_automatic_completion()# then+ mocked_checkout_fully_authorized.assert_called_once_with(checkout, webhooks=set())mocked_checkout_fully_paid.assert_not_called()with pytest.raises(Checkout.DoesNotExist):diff --git a/saleor/graphql/payment/tests/mutations/test_transaction_event_report.py b/saleor/graphql/payment/tests/mutations/test_transaction_event_report.pyindex ad391bd842..c1a207bd6b 100644--- a/saleor/graphql/payment/tests/mutations/test_transaction_event_report.py+++ b/saleor/graphql/payment/tests/mutations/test_transaction_event_report.py@@ -1390,7 +1390,9 @@ def test_transaction_event_updates_checkout_last_transaction_modified_at(@patch("saleor.checkout.tasks.automatic_checkout_completion_task.delay")@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")def test_transaction_event_updates_checkout_full_paid_with_charged_amount(+ mocked_fully_authorized,mocked_fully_paid,mocked_automatic_checkout_completion_task,transaction_item_generator,@@ -1455,13 +1457,16 @@ def test_transaction_event_updates_checkout_full_paid_with_charged_amount(assert checkout.charge_status == CheckoutChargeStatus.FULLassert checkout.authorize_status == CheckoutAuthorizeStatus.FULLmocked_fully_paid.assert_called_once_with(checkout, webhooks=set())+ mocked_fully_authorized.assert_called_once_with(checkout, webhooks=set())mocked_automatic_checkout_completion_task.assert_not_called()@patch("saleor.checkout.tasks.automatic_checkout_completion_task.delay")@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")def test_transaction_event_updates_checkout_full_paid_with_pending_charge_amount(mocked_fully_paid,+ mocked_fully_authorized,mocked_automatic_checkout_completion_task,transaction_item_generator,app_api_client,@@ -1522,12 +1527,15 @@ def test_transaction_event_updates_checkout_full_paid_with_pending_charge_amountassert checkout.charge_status == CheckoutChargeStatus.FULLassert checkout.authorize_status == CheckoutAuthorizeStatus.FULLmocked_fully_paid.assert_called_once_with(checkout, webhooks=set())+ mocked_fully_authorized.assert_called_once_with(checkout, webhooks=set())mocked_automatic_checkout_completion_task.assert_not_called()+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")def test_transaction_event_updates_checkout_full_paid_automatic_completion(mocked_fully_paid,+ checkout_fully_authorized,transaction_item_generator,app_api_client,permission_manage_payments,@@ -1599,12 +1607,15 @@ def test_transaction_event_updates_checkout_full_paid_automatic_completion(type=OrderEvents.PLACED_AUTOMATICALLY_FROM_PAID_CHECKOUT).exists()+ checkout_fully_authorized.assert_called_once_with(checkout, webhooks=set())mocked_fully_paid.assert_called_once_with(checkout, webhooks=set())+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")def test_transaction_event_updates_checkout_full_paid_pending_charge_automatic_complete(mocked_fully_paid,+ checkout_fully_authorized,transaction_item_generator,app_api_client,permission_manage_payments,@@ -1673,11 +1684,14 @@ def test_transaction_event_updates_checkout_full_paid_pending_charge_automatic_cassert order.authorize_status == CheckoutAuthorizeStatus.NONEmocked_fully_paid.assert_called_once_with(checkout, webhooks=set())+ checkout_fully_authorized.assert_called_once_with(checkout, webhooks=set())@patch("saleor.checkout.tasks.automatic_checkout_completion_task.delay")@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")def test_transaction_event_updates_checkout_fully_authorized(+ mocked_fully_authorized,mocked_fully_paid,mocked_automatic_checkout_completion_task,transaction_item_generator,@@ -1741,13 +1755,17 @@ def test_transaction_event_updates_checkout_fully_authorized(assert checkout.charge_status == CheckoutChargeStatus.NONEassert checkout.authorize_status == CheckoutAuthorizeStatus.FULL+mocked_fully_paid.assert_not_called()+ mocked_fully_authorized.assert_called_once_with(checkout, webhooks=set())mocked_automatic_checkout_completion_task.assert_not_called()+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")def test_transaction_event_updates_checkout_fully_authorized_automatic_complete(mocked_fully_paid,+ mocked_fully_authorized,transaction_item_generator,app_api_client,permission_manage_payments,@@ -1819,11 +1837,14 @@ def test_transaction_event_updates_checkout_fully_authorized_automatic_complete(type=OrderEvents.PLACED_AUTOMATICALLY_FROM_PAID_CHECKOUT).exists()mocked_fully_paid.assert_not_called()+ mocked_fully_authorized.assert_called_once_with(checkout, webhooks=set())+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")def test_transaction_event_updates_checkout_fully_authorized_pending_automatic_complete(mocked_fully_paid,+ mocked_fully_authorized,transaction_item_generator,app_api_client,permission_manage_payments,@@ -1892,6 +1913,7 @@ def test_transaction_event_updates_checkout_fully_authorized_pending_automatic_cassert order.charge_status == CheckoutChargeStatus.NONEassert order.authorize_status == CheckoutAuthorizeStatus.NONEmocked_fully_paid.assert_not_called()+ mocked_fully_authorized.assert_called_once_with(checkout, webhooks=set())def test_transaction_event_report_with_info_event(diff --git a/saleor/graphql/payment/tests/mutations/test_transaction_initialize.py b/saleor/graphql/payment/tests/mutations/test_transaction_initialize.pyindex 1c547a45f6..7c73ab79cd 100644--- a/saleor/graphql/payment/tests/mutations/test_transaction_initialize.py+++ b/saleor/graphql/payment/tests/mutations/test_transaction_initialize.py@@ -1828,9 +1828,11 @@ def test_order_doesnt_exists()@mock.patch("saleor.checkout.tasks.automatic_checkout_completion_task.delay")@mock.patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")[email protected]("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")@mock.patch("saleor.plugins.manager.PluginsManager.transaction_initialize_session")def test_checkout_fully_paid(mocked_initialize,+ mocked_fully_authorized,mocked_fully_paid,mocked_automatic_checkout_completion_task,result,@@ -1875,16 +1877,19 @@ def test_checkout_fully_paid(assert not content["data"]["transactionInitialize"]["errors"]checkout.refresh_from_db()mocked_fully_paid.assert_called_once_with(checkout, webhooks=set())+ mocked_fully_authorized.assert_called_once_with(checkout, webhooks=set())mocked_automatic_checkout_completion_task.assert_not_called()assert checkout.charge_status == CheckoutChargeStatus.FULLassert checkout.authorize_status == CheckoutAuthorizeStatus.FULL[email protected]("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")@mock.patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")@mock.patch("saleor.plugins.manager.PluginsManager.transaction_initialize_session")def test_checkout_fully_paid_automatic_completion(mocked_initialize,mocked_fully_paid,+ mocked_fully_authorized,user_api_client,checkout_with_prices,webhook_app,@@ -1937,13 +1942,16 @@ def test_checkout_fully_paid_automatic_completion(type=OrderEvents.PLACED_AUTOMATICALLY_FROM_PAID_CHECKOUT).exists()mocked_fully_paid.assert_called_once_with(checkout, webhooks=set())+ mocked_fully_authorized.assert_called_once_with(checkout, webhooks=set())[email protected]("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")@mock.patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")@mock.patch("saleor.plugins.manager.PluginsManager.transaction_initialize_session")def test_checkout_fully_paid_pending_charge_automatic_completion(mocked_initialize,mocked_fully_paid,+ mocked_fully_authorized,user_api_client,checkout_with_prices,webhook_app,@@ -1993,6 +2001,7 @@ def test_checkout_fully_paid_pending_charge_automatic_completion(assert order.charge_status == CheckoutChargeStatus.NONEassert order.authorize_status == CheckoutAuthorizeStatus.NONEmocked_fully_paid.assert_called_once_with(checkout, webhooks=set())+ mocked_fully_authorized.assert_called_once_with(checkout, webhooks=set())@pytest.mark.parametrize(@@ -2004,9 +2013,11 @@ def test_checkout_fully_paid_pending_charge_automatic_completion()@mock.patch("saleor.checkout.tasks.automatic_checkout_completion_task.delay")@mock.patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")[email protected]("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")@mock.patch("saleor.plugins.manager.PluginsManager.transaction_initialize_session")def test_checkout_fully_authorized(mocked_initialize,+ mocked_fully_authorized,mocked_fully_paid,mocked_automatic_checkout_completion_task,result,@@ -2053,14 +2064,17 @@ def test_checkout_fully_authorized(assert checkout.charge_status == CheckoutChargeStatus.NONEassert checkout.authorize_status == CheckoutAuthorizeStatus.FULLmocked_automatic_checkout_completion_task.assert_not_called()+ mocked_fully_authorized.assert_called_once_with(checkout, webhooks=set())mocked_fully_paid.assert_not_called()[email protected]("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")@mock.patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")@mock.patch("saleor.plugins.manager.PluginsManager.transaction_initialize_session")def test_checkout_fully_authorized_automatic_completion(mocked_initialize,mocked_fully_paid,+ mocked_fully_authorized,user_api_client,checkout_with_prices,webhook_app,@@ -2113,13 +2127,16 @@ def test_checkout_fully_authorized_automatic_completion(type=OrderEvents.PLACED_AUTOMATICALLY_FROM_PAID_CHECKOUT).exists()mocked_fully_paid.assert_not_called()+ mocked_fully_authorized.assert_called_once_with(checkout, webhooks=set())[email protected]("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")@mock.patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")@mock.patch("saleor.plugins.manager.PluginsManager.transaction_initialize_session")def test_checkout_fully_authorizaed_pending_authorization_automatic_completion(mocked_initialize,mocked_fully_paid,+ mocked_fully_authorized,user_api_client,checkout_with_prices,webhook_app,@@ -2169,6 +2186,7 @@ def test_checkout_fully_authorizaed_pending_authorization_automatic_completion(assert order.charge_status == CheckoutChargeStatus.NONEassert order.authorize_status == CheckoutAuthorizeStatus.NONEmocked_fully_paid.assert_not_called()+ mocked_fully_authorized.assert_called_once_with(checkout, webhooks=set())def test_user_missing_permission_for_customer_ip_address(diff --git a/saleor/graphql/payment/tests/mutations/test_transaction_process.py b/saleor/graphql/payment/tests/mutations/test_transaction_process.pyindex 1bace3d5bf..21c7ebee81 100644--- a/saleor/graphql/payment/tests/mutations/test_transaction_process.py+++ b/saleor/graphql/payment/tests/mutations/test_transaction_process.py@@ -1125,9 +1125,11 @@ def test_app_attached_to_transaction_doesnt_exist()@mock.patch("saleor.checkout.tasks.automatic_checkout_completion_task.delay")@mock.patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")[email protected]("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")@mock.patch("saleor.plugins.manager.PluginsManager.transaction_process_session")def test_checkout_fully_paid(mocked_process,+ mocked_fully_authorized,mocked_fully_paid,mocked_automatic_checkout_completion_task,result,@@ -1184,15 +1186,18 @@ def test_checkout_fully_paid(checkout.refresh_from_db()mocked_fully_paid.assert_called_once_with(checkout, webhooks=set())+ mocked_fully_authorized.assert_called_once_with(checkout, webhooks=set())mocked_automatic_checkout_completion_task.assert_not_called()assert checkout.charge_status == CheckoutChargeStatus.FULLassert checkout.authorize_status == CheckoutAuthorizeStatus.FULL@mock.patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")[email protected]("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")@mock.patch("saleor.plugins.manager.PluginsManager.transaction_process_session")def test_checkout_fully_paid_automatic_completion(mocked_process,+ mocked_fully_authorized,mocked_fully_paid,user_api_client,checkout_with_prices,@@ -1257,13 +1262,16 @@ def test_checkout_fully_paid_automatic_completion(assert order.events.filter(type=OrderEvents.PLACED_AUTOMATICALLY_FROM_PAID_CHECKOUT).exists()+ mocked_fully_authorized.assert_called_once_with(checkout, webhooks=set())mocked_fully_paid.assert_called_once_with(checkout, webhooks=set())@mock.patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")[email protected]("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")@mock.patch("saleor.plugins.manager.PluginsManager.transaction_process_session")def test_checkout_fully_paid_pending_automatic_completion(mocked_process,+ mocked_fully_authorized,mocked_fully_paid,user_api_client,checkout_with_prices,@@ -1326,6 +1334,7 @@ def test_checkout_fully_paid_pending_automatic_completion(assert order.charge_status == CheckoutChargeStatus.NONEassert order.authorize_status == CheckoutAuthorizeStatus.NONEmocked_fully_paid.assert_called_once_with(checkout, webhooks=set())+ mocked_fully_authorized.assert_called_once_with(checkout, webhooks=set())@pytest.mark.parametrize(@@ -1336,11 +1345,13 @@ def test_checkout_fully_paid_pending_automatic_completion(],)@mock.patch("saleor.checkout.tasks.automatic_checkout_completion_task.delay")[email protected]("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")@mock.patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")@mock.patch("saleor.plugins.manager.PluginsManager.transaction_process_session")def test_checkout_fully_authorized(mocked_process,mocked_fully_paid,+ mocked_fully_authorized,mocked_automatic_checkout_completion_task,result,user_api_client,@@ -1397,14 +1408,17 @@ def test_checkout_fully_authorized(checkout.refresh_from_db()mocked_fully_paid.assert_not_called()mocked_automatic_checkout_completion_task.assert_not_called()+ mocked_fully_authorized.assert_called_once_with(checkout, webhooks=set())assert checkout.charge_status == CheckoutChargeStatus.NONEassert checkout.authorize_status == CheckoutAuthorizeStatus.FULL@mock.patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")[email protected]("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")@mock.patch("saleor.plugins.manager.PluginsManager.transaction_process_session")def test_checkout_fully_authorized_automatic_completion(mocked_process,+ mocked_fully_authorized,mocked_fully_paid,user_api_client,checkout_with_prices,@@ -1470,12 +1484,15 @@ def test_checkout_fully_authorized_automatic_completion(type=OrderEvents.PLACED_AUTOMATICALLY_FROM_PAID_CHECKOUT).exists()mocked_fully_paid.assert_not_called()+ mocked_fully_authorized.assert_called_once_with(checkout, webhooks=set())@mock.patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")[email protected]("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")@mock.patch("saleor.plugins.manager.PluginsManager.transaction_process_session")def test_checkout_fully_authorized_pending_automatic_completion(mocked_process,+ mocked_fully_authorized,mocked_fully_paid,user_api_client,checkout_with_prices,@@ -1538,6 +1555,7 @@ def test_checkout_fully_authorized_pending_automatic_completion(assert order.charge_status == CheckoutChargeStatus.NONEassert order.authorize_status == CheckoutAuthorizeStatus.NONEmocked_fully_paid.assert_not_called()+ mocked_fully_authorized.assert_called_once_with(checkout, webhooks=set())def test_transaction_process_doesnt_accept_old_id(diff --git a/saleor/graphql/payment/tests/mutations/test_transaction_update.py b/saleor/graphql/payment/tests/mutations/test_transaction_update.pyindex 39333e51d5..bef6736c32 100644--- a/saleor/graphql/payment/tests/mutations/test_transaction_update.py+++ b/saleor/graphql/payment/tests/mutations/test_transaction_update.py@@ -2693,7 +2693,9 @@ def test_transaction_update_for_checkout_updates_payment_statuses(@patch("saleor.checkout.tasks.automatic_checkout_completion_task.delay")@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")def test_transaction_update_for_checkout_fully_paid(+ mocked_checkout_fully_authorized,mocked_checkout_fully_paid,mocked_automatic_checkout_completion_task,checkout_with_prices,@@ -2741,11 +2743,14 @@ def test_transaction_update_for_checkout_fully_paid(assert checkout.authorize_status == CheckoutAuthorizeStatus.FULLmocked_checkout_fully_paid.assert_called_once_with(checkout, webhooks=set())+ mocked_checkout_fully_authorized.assert_called_once_with(checkout, webhooks=set())mocked_automatic_checkout_completion_task.assert_not_called()@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")def test_transaction_update_for_checkout_fully_paid_automatic_completion(+ mocked_checkout_fully_authorized,mocked_checkout_fully_paid,checkout_with_prices,permission_manage_payments,@@ -2801,11 +2806,14 @@ def test_transaction_update_for_checkout_fully_paid_automatic_completion().exists()mocked_checkout_fully_paid.assert_called_once_with(checkout, webhooks=set())+ mocked_checkout_fully_authorized.assert_called_once_with(checkout, webhooks=set())@patch("saleor.checkout.tasks.automatic_checkout_completion_task.delay")@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")def test_transaction_update_for_checkout_fully_authorized(+ mocked_checkout_fully_authorized,mocked_checkout_fully_paid,mocked_automatic_checkout_completion_task,checkout_with_prices,@@ -2853,11 +2861,14 @@ def test_transaction_update_for_checkout_fully_authorized(assert checkout.authorize_status == CheckoutAuthorizeStatus.FULLmocked_checkout_fully_paid.assert_not_called()+ mocked_checkout_fully_authorized.assert_called_once_with(checkout, webhooks=set())mocked_automatic_checkout_completion_task.assert_not_called()@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")def test_transaction_update_for_checkout_fully_authorized_automatic_completion(+ mocked_checkout_fully_authorized,mocked_checkout_fully_paid,checkout_with_prices,permission_manage_payments,@@ -2911,6 +2922,7 @@ def test_transaction_update_for_checkout_fully_authorized_automatic_completion().exists()mocked_checkout_fully_paid.assert_not_called()+ mocked_checkout_fully_authorized.assert_called_once_with(checkout, webhooks=set())def test_transaction_update_accepts_old_id_for_old_transaction(diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 436fa47ca0..00de537ed9 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -2052,6 +2052,19 @@ enum WebhookEventTypeEnum @doc(category: "Webhooks") {A checkout is updated. It also triggers all updates related to the checkout."""CHECKOUT_UPDATED++ """+ A checkout was fully authorized (its `authorizeStatus` is `FULL`).++ This event is emitted only for checkouts whose payments are processed through the Transaction API.+ """+ CHECKOUT_FULLY_AUTHORIZED++ """+ A checkout was fully paid (its `chargeStatus` is `FULL` or `OVERCHARGED`). This event is not sent if payments are only authorized but not fully charged.++ This event is emitted only for checkouts whose payments are processed through the Transaction API.+ """CHECKOUT_FULLY_PAID"""A checkout metadata is updated."""@@ -2614,6 +2627,19 @@ enum WebhookEventTypeAsyncEnum @doc(category: "Webhooks") {A checkout is updated. It also triggers all updates related to the checkout."""CHECKOUT_UPDATED++ """+ A checkout was fully authorized (its `authorizeStatus` is `FULL`).++ This event is emitted only for checkouts whose payments are processed through the Transaction API.+ """+ CHECKOUT_FULLY_AUTHORIZED++ """+ A checkout was fully paid (its `chargeStatus` is `FULL` or `OVERCHARGED`). This event is not sent if payments are only authorized but not fully charged.++ This event is emitted only for checkouts whose payments are processed through the Transaction API.+ """CHECKOUT_FULLY_PAID"""A checkout metadata is updated."""@@ -3425,6 +3451,7 @@ enum WebhookSampleEventTypeEnum @doc(category: "Webhooks") {PRODUCT_VARIANT_STOCK_UPDATEDCHECKOUT_CREATEDCHECKOUT_UPDATED+ CHECKOUT_FULLY_AUTHORIZEDCHECKOUT_FULLY_PAIDCHECKOUT_METADATA_UPDATEDNOTIFY_USER@@ -31016,6 +31043,20 @@ type Subscription @doc(category: "Miscellaneous") {channels: [String!]): CheckoutFullyPaid @doc(category: "Checkout")+ """+ Event sent when checkout is fully authorized.++ Added in Saleor 3.21.++ Note: this API is currently in Feature Preview and can be subject to changes at later point.+ """+ checkoutFullyAuthorized(+ """+ List of channel slugs. The event will be sent only if the object belongs to one of the provided channels. If the channel slug list is empty, objects that belong to any channel will be sent. Maximally 500 items.+ """+ channels: [String!]+ ): CheckoutFullyAuthorized @doc(category: "Checkout")+"""Event sent when checkout metadata is updated.@@ -31356,7 +31397,9 @@ type CheckoutUpdated implements Event @doc(category: "Checkout") {}"""-Event sent when checkout is fully paid with transactions. The checkout is considered as fully paid when the checkout `charge_status` is `FULL` or `OVERCHARGED`. The event is not sent when the checkout authorization flow strategy is used.+Event sent when a checkout was fully paid. A checkout is considered fully paid when its `chargeStatus` is `FULL` or `OVERCHARGED`. This event is not sent if payments are only authorized but not fully charged.++It is triggered only for checkouts whose payments are processed through the Transaction API."""type CheckoutFullyPaid implements Event @doc(category: "Checkout") {"""Time of the event."""@@ -31375,6 +31418,28 @@ type CheckoutFullyPaid implements Event @doc(category: "Checkout") {checkout: Checkout}+"""+Event sent when a checkout was fully authorized. A checkout is considered fully authorized when its `authorizeStatus` is `FULL`.++It is triggered only for checkouts whose payments are processed through the Transaction API.+"""+type CheckoutFullyAuthorized implements Event @doc(category: "Checkout") {+ """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+}+"""Event sent when checkout metadata is updated."""type CheckoutMetadataUpdated implements Event @doc(category: "Checkout") {"""Time of the event."""diff --git a/saleor/graphql/webhook/enums.py b/saleor/graphql/webhook/enums.pyindex 4ce914e620..6bd6491f5b 100644--- a/saleor/graphql/webhook/enums.py+++ b/saleor/graphql/webhook/enums.py@@ -26,7 +26,18 @@ order_updated_event_enum_description = ("An order is updated; triggered for all changes related to an order; ""covers all other order webhooks, except for ORDER_CREATED.")-+checkout_fully_authorized_event_enum_description = (+ "A checkout was fully authorized (its `authorizeStatus` is `FULL`)."+ "\n\nThis event is emitted only for checkouts whose payments are "+ "processed through the Transaction API."+)+checkout_fully_paid_event_enum_description = (+ "A checkout was fully paid (its `chargeStatus` is `FULL` "+ "or `OVERCHARGED`). This event is not sent if payments are only authorized "+ "but not fully charged."+ "\n\nThis event is emitted only for checkouts whose payments are processed"+ " through the Transaction API."+)WEBHOOK_EVENT_DESCRIPTION = {WebhookEventAsyncType.ACCOUNT_CONFIRMATION_REQUESTED: (@@ -65,6 +76,8 @@ WEBHOOK_EVENT_DESCRIPTION = {WebhookEventAsyncType.CHANNEL_METADATA_UPDATED: "A channel metadata is updated.",WebhookEventAsyncType.CHECKOUT_CREATED: "A new checkout is created.",WebhookEventAsyncType.CHECKOUT_UPDATED: checkout_updated_event_enum_description,+ WebhookEventAsyncType.CHECKOUT_FULLY_AUTHORIZED: checkout_fully_authorized_event_enum_description,+ WebhookEventAsyncType.CHECKOUT_FULLY_PAID: checkout_fully_paid_event_enum_description,WebhookEventAsyncType.CHECKOUT_METADATA_UPDATED: "A checkout metadata is updated.",WebhookEventAsyncType.COLLECTION_CREATED: "A new collection is created.",WebhookEventAsyncType.COLLECTION_UPDATED: "A collection is updated.",diff --git a/saleor/graphql/webhook/subscription_types.py b/saleor/graphql/webhook/subscription_types.pyindex b90f13dd0d..cb967306d9 100644--- a/saleor/graphql/webhook/subscription_types.py+++ b/saleor/graphql/webhook/subscription_types.py@@ -1506,11 +1506,25 @@ class CheckoutFullyPaid(SubscriptionObjectType, CheckoutBase):enable_dry_run = Trueinterfaces = (Event,)description = (- "Event sent when checkout is fully paid with transactions."- " The checkout is considered as fully paid when the checkout "- "`charge_status` is `FULL` or `OVERCHARGED`. "- "The event is not sent when the checkout authorization flow strategy "- "is used."+ "Event sent when a checkout was fully paid. A checkout is "+ "considered fully paid when its `chargeStatus` is `FULL` "+ "or `OVERCHARGED`. This event is not sent if payments are only "+ "authorized but not fully charged."+ "\n\nIt is triggered only for checkouts whose payments are "+ "processed through the Transaction API."+ )+++class CheckoutFullyAuthorized(SubscriptionObjectType, CheckoutBase):+ class Meta:+ root_type = "Checkout"+ enable_dry_run = True+ interfaces = (Event,)+ description = (+ "Event sent when a checkout was fully authorized. A checkout is "+ "considered fully authorized when its `authorizeStatus` is `FULL`."+ "\n\nIt is triggered only for checkouts whose payments are processed through "+ "the Transaction API.")@@ -2783,6 +2797,17 @@ class Subscription(SubscriptionObjectType):channels=channels_argument,doc_category=DOC_CATEGORY_CHECKOUT,)+ checkout_fully_authorized = BaseField(+ CheckoutFullyAuthorized,+ description=(+ "Event sent when checkout is fully authorized."+ + ADDED_IN_321+ + PREVIEW_FEATURE+ ),+ resolver=default_channel_filterable_resolver,+ channels=channels_argument,+ doc_category=DOC_CATEGORY_CHECKOUT,+ )checkout_metadata_updated = BaseField(CheckoutMetadataUpdated,description=(@@ -3007,6 +3032,7 @@ ASYNC_WEBHOOK_TYPES_MAP = {WebhookEventAsyncType.COLLECTION_METADATA_UPDATED: CollectionMetadataUpdated,WebhookEventAsyncType.CHECKOUT_CREATED: CheckoutCreated,WebhookEventAsyncType.CHECKOUT_UPDATED: CheckoutUpdated,+ WebhookEventAsyncType.CHECKOUT_FULLY_AUTHORIZED: CheckoutFullyAuthorized,WebhookEventAsyncType.CHECKOUT_FULLY_PAID: CheckoutFullyPaid,WebhookEventAsyncType.CHECKOUT_METADATA_UPDATED: CheckoutMetadataUpdated,WebhookEventAsyncType.PAGE_CREATED: PageCreated,diff --git a/saleor/payment/tests/test_utils/test_create_transaction_event_for_transaction_session.py b/saleor/payment/tests/test_utils/test_create_transaction_event_for_transaction_session.pyindex f0ccd1871e..cb1f43aee4 100644--- a/saleor/payment/tests/test_utils/test_create_transaction_event_for_transaction_session.py+++ b/saleor/payment/tests/test_utils/test_create_transaction_event_for_transaction_session.py@@ -916,7 +916,9 @@ def test_create_transaction_event_with_invalid_message(@patch("saleor.checkout.tasks.automatic_checkout_completion_task.delay")@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")def test_create_transaction_event_from_session_when_authorized_triggers_checkout_completion(+ mocked_checkout_fully_authorized,mocked_checkout_fully_paid,mocked_automatic_checkout_completion_task,transaction_item_generator,@@ -963,6 +965,7 @@ def test_create_transaction_event_from_session_when_authorized_triggers_checkoutcheckout.refresh_from_db()assert checkout.authorize_status == CheckoutAuthorizeStatus.FULLmocked_checkout_fully_paid.assert_not_called()+ mocked_checkout_fully_authorized.assert_called_once_with(checkout, webhooks=set())mocked_automatic_checkout_completion_task.assert_called_once_with(checkout.pk, None, app.id)diff --git a/saleor/payment/tests/test_utils/test_utils.py b/saleor/payment/tests/test_utils/test_utils.pyindex 1e17bc972f..3c350b044f 100644--- a/saleor/payment/tests/test_utils/test_utils.py+++ b/saleor/payment/tests/test_utils/test_utils.py@@ -820,8 +820,10 @@ def test_create_transaction_event_from_request_and_webhook_response_full_event(@patch("saleor.checkout.tasks.automatic_checkout_completion_task.delay")@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")def test_create_transaction_event_from_request_when_paid(mocked_checkout_fully_paid,+ mocked_checkout_fully_authorized,mocked_automatic_checkout_completion_task,transaction_item_generator,app,@@ -860,14 +862,17 @@ def test_create_transaction_event_from_request_when_paid(checkout.refresh_from_db()assert checkout.authorize_status == CheckoutAuthorizeStatus.FULLmocked_checkout_fully_paid.assert_called_once_with(checkout, webhooks=set())+ mocked_checkout_fully_authorized.assert_called_once_with(checkout, webhooks=set())mocked_automatic_checkout_completion_task.assert_not_called()@patch.object(logger, "error")@patch("saleor.checkout.tasks.automatic_checkout_completion_task.delay")@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")def test_create_transaction_event_from_request_when_authorized_logs_warnning(mocked_checkout_fully_paid,+ mocked_checkout_fully_authorized,mocked_automatic_checkout_completion_task,mocked_logger,transaction_item_generator,@@ -913,6 +918,7 @@ def test_create_transaction_event_from_request_when_authorized_logs_warnning(assert checkout.authorize_status == CheckoutAuthorizeStatus.NONEcheckout.refresh_from_db()mocked_checkout_fully_paid.assert_not_called()+ mocked_checkout_fully_authorized.assert_not_called()mocked_automatic_checkout_completion_task.assert_not_called()assert mocked_logger.call_count == 1assert len(mocked_logger.call_args) == 2@@ -920,8 +926,10 @@ def test_create_transaction_event_from_request_when_authorized_logs_warnning(@patch("saleor.checkout.tasks.automatic_checkout_completion_task.delay")@patch("saleor.plugins.manager.PluginsManager.checkout_fully_paid")+@patch("saleor.plugins.manager.PluginsManager.checkout_fully_authorized")def test_create_transaction_event_from_request_when_paid_triggers_checkout_completion(mocked_checkout_fully_paid,+ mocked_checkout_fully_authorized,mocked_automatic_checkout_completion_task,transaction_item_generator,app,@@ -967,6 +975,7 @@ def test_create_transaction_event_from_request_when_paid_triggers_checkout_complcheckout.refresh_from_db()assert checkout.authorize_status == CheckoutAuthorizeStatus.FULLmocked_checkout_fully_paid.assert_called_once_with(checkout, webhooks=set())+ mocked_checkout_fully_authorized.assert_called_once_with(checkout, webhooks=set())mocked_automatic_checkout_completion_task.assert_called_once_with(checkout.pk, None, app.id)diff --git a/saleor/plugins/base_plugin.py b/saleor/plugins/base_plugin.pyindex fee2a84a94..916394e925 100644--- a/saleor/plugins/base_plugin.py+++ b/saleor/plugins/base_plugin.py@@ -545,6 +545,15 @@ class BasePlugin:# Webhook-related functionality will be moved from the plugin to core modules.checkout_fully_paid: Callable[["Checkout", Any, None], Any]+ # Trigger when checkout is fully authorized with transactions.+ #+ # Overwrite this method if you need to trigger specific logic when a checkout is+ # updated.+ #+ # Note: This method is deprecated and will be removed in a future release.+ # Webhook-related functionality will be moved from the plugin to core modules.+ checkout_fully_authorized: Callable[["Checkout", Any, None], Any]+# Trigger when checkout metadata is updated.## Overwrite this method if you need to trigger specific logic when a checkoutdiff --git a/saleor/plugins/manager.py b/saleor/plugins/manager.pyindex c5e1157f4d..dee10df7ef 100644--- a/saleor/plugins/manager.py+++ b/saleor/plugins/manager.py@@ -1364,6 +1364,18 @@ class PluginsManager(PaymentInterface):webhooks=webhooks,)+ # Note: this method is deprecated and will be removed in a future release.+ # Webhook-related functionality will be moved from plugin to core modules.+ def checkout_fully_authorized(self, checkout: "Checkout", webhooks=None):+ default_value = None+ return self.__run_method_on_plugins(+ "checkout_fully_authorized",+ default_value,+ checkout,+ channel_slug=checkout.channel.slug,+ webhooks=webhooks,+ )+# Note: this method is deprecated and will be removed in a future release.# Webhook-related functionality will be moved from plugin to core modules.def checkout_fully_paid(self, checkout: "Checkout", webhooks=None):diff --git a/saleor/plugins/tests/sample_plugins.py b/saleor/plugins/tests/sample_plugins.pyindex d7c9115f5f..6c17cb2ef5 100644--- a/saleor/plugins/tests/sample_plugins.py+++ b/saleor/plugins/tests/sample_plugins.py@@ -339,6 +339,9 @@ class PluginSample(BasePlugin):def checkout_fully_paid(self, checkout, previous_value, webhooks):return None+ def checkout_fully_authorized(self, checkout, previous_value, webhooks):+ return None+def order_fully_refunded(self, order, previous_value, webhooks):return Nonediff --git a/saleor/plugins/tests/test_manager.py b/saleor/plugins/tests/test_manager.pyindex f30d46682c..5eee3c3c61 100644--- a/saleor/plugins/tests/test_manager.py+++ b/saleor/plugins/tests/test_manager.py@@ -1276,6 +1276,26 @@ def test_checkout_fully_paid(mocked_sample_method, checkout, webhook):)+@patch("saleor.plugins.tests.sample_plugins.PluginSample.checkout_fully_authorized")+def test_checkout_fully_authorized(mocked_sample_method, checkout, webhook):+ # given+ plugins = [+ "saleor.plugins.tests.sample_plugins.PluginSample",+ "saleor.plugins.tests.sample_plugins.PluginInactive",+ ]++ manager = PluginsManager(plugins=plugins)+ webhooks = {webhook}++ # when+ manager.checkout_fully_authorized(checkout, webhooks=webhooks)++ # then+ 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, webhook):# givendiff --git a/saleor/plugins/webhook/plugin.py b/saleor/plugins/webhook/plugin.pyindex b4b92396dd..2b1a0ba01a 100644--- a/saleor/plugins/webhook/plugin.py+++ b/saleor/plugins/webhook/plugin.py@@ -2123,6 +2123,31 @@ class WebhookPlugin(BasePlugin):)return previous_value+ def checkout_fully_authorized(+ self, checkout: "Checkout", previous_value: None, webhooks=None+ ) -> None:+ if not self.active:+ return previous_value+ event_type = WebhookEventAsyncType.CHECKOUT_FULLY_AUTHORIZED+ if webhooks := self._get_webhooks_for_channel_events(+ event_type, checkout.channel.slug, webhooks+ ):+ checkout_data_generator = partial(+ generate_checkout_payload,+ checkout,+ self.requestor,+ )+ self.trigger_webhooks_async(+ None,+ event_type,+ webhooks,+ checkout,+ self.requestor,+ legacy_data_generator=checkout_data_generator,+ queue=settings.CHECKOUT_WEBHOOK_EVENTS_CELERY_QUEUE_NAME,+ )+ return previous_value+def checkout_fully_paid(self, checkout: "Checkout", previous_value: None, webhooks=None) -> None:diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_checkout_fully_authorized.py b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_checkout_fully_authorized.pynew file mode 100644index 0000000000..d147cd279a--- /dev/null+++ b/saleor/plugins/webhook/tests/subscription_webhooks/filterable_webhooks/test_checkout_fully_authorized.py@@ -0,0 +1,247 @@+import json+from unittest.mock import patch++import graphene+from django.test import override_settings++from ......core.models import EventDelivery+from ......graphql.webhook.subscription_query import SubscriptionQuery+from ......webhook.event_types import WebhookEventAsyncType+from .....manager import get_plugins_manager++CHECKOUT_FULLY_AUTHORIZED_SUBSCRIPTION = """+subscription {+ checkoutFullyAuthorized(channels: ["%s"]) {+ checkout {+ id+ token+ lines {+ id+ variant {+ id+ }+ }+ }+ }+}+"""+++@patch(+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"+)+@override_settings(+ PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"],+ CELERY_TASK_ALWAYS_EAGER=True,+)+def test_checkout_fully_authorized(+ mocked_async, checkout_with_item, subscription_webhook, settings+):+ # given+ manager = get_plugins_manager(False)+ checkout = checkout_with_item+ checkout_line = checkout.lines.first()++ channel = checkout.channel+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG++ event_type = WebhookEventAsyncType.CHECKOUT_FULLY_AUTHORIZED++ query = CHECKOUT_FULLY_AUTHORIZED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG+ webhook = subscription_webhook(query, event_type)+ subscription_query = SubscriptionQuery(query)+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()+ webhook.save()++ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)++ # when+ manager.checkout_fully_authorized(checkout)++ # then+ expected_payload = json.dumps(+ {+ "data": {+ "checkoutFullyAuthorized": {+ "checkout": {+ "id": checkout_id,+ "token": str(checkout.token),+ "lines": [+ {+ "id": graphene.Node.to_global_id(+ "CheckoutLine", checkout_line.id+ ),+ "variant": {+ "id": graphene.Node.to_global_id(+ "ProductVariant", checkout_line.variant_id+ )+ },+ }+ ],+ }+ }+ }+ }+ )+ deliveries = EventDelivery.objects.all()+ assert len(deliveries) == 1+ assert deliveries[0].payload.get_payload() == expected_payload+ assert deliveries[0].webhook == webhook+ assert mocked_async.called+++@patch(+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"+)+@override_settings(+ PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"],+ CELERY_TASK_ALWAYS_EAGER=True,+)+def test_checkout_fully_authorized_without_channels_input(+ mocked_async, checkout_with_item, subscription_webhook+):+ # given+ manager = get_plugins_manager(False)+ checkout = checkout_with_item+ checkout_line = checkout.lines.first()++ event_type = WebhookEventAsyncType.CHECKOUT_FULLY_AUTHORIZED++ query = """subscription {+ checkoutFullyAuthorized {+ checkout {+ id+ token+ lines {+ id+ variant {+ id+ }+ }+ }+ }+ }"""+ webhook = subscription_webhook(query, event_type)+ subscription_query = SubscriptionQuery(query)+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()+ webhook.save()++ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)++ # when+ manager.checkout_fully_authorized(checkout)++ # then+ expected_payload = json.dumps(+ {+ "data": {+ "checkoutFullyAuthorized": {+ "checkout": {+ "id": checkout_id,+ "token": str(checkout.token),+ "lines": [+ {+ "id": graphene.Node.to_global_id(+ "CheckoutLine", checkout_line.id+ ),+ "variant": {+ "id": graphene.Node.to_global_id(+ "ProductVariant", checkout_line.variant_id+ )+ },+ }+ ],+ }+ }+ }+ }+ )+ deliveries = EventDelivery.objects.all()+ assert len(deliveries) == 1+ assert deliveries[0].payload.get_payload() == expected_payload+ assert deliveries[0].webhook == webhook+ assert mocked_async.called+++@patch(+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"+)+@patch(+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"+)+@override_settings(+ PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"],+ CELERY_TASK_ALWAYS_EAGER=True,+)+def test_checkout_fully_authorized_with_different_channel(+ mocked_async,+ mocked_create_event_delivery_list_for_webhooks,+ checkout_JPY_with_item,+ subscription_webhook,+ settings,+):+ # given+ manager = get_plugins_manager(False)+ checkout = checkout_JPY_with_item+ channel = checkout.channel+ assert channel.slug != settings.DEFAULT_CHANNEL_SLUG++ event_type = WebhookEventAsyncType.CHECKOUT_FULLY_AUTHORIZED++ query = CHECKOUT_FULLY_AUTHORIZED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG+ webhook = subscription_webhook(query, event_type)+ subscription_query = SubscriptionQuery(query)+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()+ webhook.save()++ # when+ manager.checkout_fully_authorized(checkout)++ # then+ assert not mocked_async.called+ assert not mocked_create_event_delivery_list_for_webhooks.called+ deliveries = EventDelivery.objects.all()+ assert len(deliveries) == 0+++@patch(+ "saleor.webhook.transport.asynchronous.transport.create_event_delivery_list_for_webhooks"+)+@patch(+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"+)+@override_settings(+ PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"],+ CELERY_TASK_ALWAYS_EAGER=True,+)+def test_different_event_doesnt_trigger_webhook(+ mocked_async,+ mocked_create_event_delivery_list_for_webhooks,+ checkout_with_item,+ subscription_webhook,+ settings,+):+ # given+ manager = get_plugins_manager(False)++ checkout = checkout_with_item++ channel = checkout.channel+ assert channel.slug == settings.DEFAULT_CHANNEL_SLUG++ event_type = WebhookEventAsyncType.CHECKOUT_UPDATED++ query = CHECKOUT_FULLY_AUTHORIZED_SUBSCRIPTION % settings.DEFAULT_CHANNEL_SLUG+ webhook = subscription_webhook(query, event_type)+ subscription_query = SubscriptionQuery(query)+ webhook.filterable_channel_slugs = subscription_query.get_filterable_channel_slugs()+ webhook.save()++ # when+ manager.checkout_fully_authorized(checkout)++ # then+ assert not mocked_async.called+ assert not mocked_create_event_delivery_list_for_webhooks.called+ deliveries = EventDelivery.objects.all()+ assert len(deliveries) == 0diff --git a/saleor/plugins/webhook/tests/test_webhook.py b/saleor/plugins/webhook/tests/test_webhook.pyindex 997caca3b7..dd841295ed 100644--- a/saleor/plugins/webhook/tests/test_webhook.py+++ b/saleor/plugins/webhook/tests/test_webhook.py@@ -1269,6 +1269,40 @@ def test_checkout_fully_paid()+@freeze_time("2014-06-28 10:50")[email protected]("saleor.plugins.webhook.plugin.get_webhooks_for_event")[email protected]("saleor.plugins.webhook.plugin.trigger_webhooks_async")+def test_checkout_fully_authorized(+ mocked_webhook_trigger,+ mocked_get_webhooks_for_event,+ any_webhook,+ settings,+ checkout_with_items,+):+ # given+ mocked_get_webhooks_for_event.return_value = [any_webhook]+ settings.PLUGINS = ["saleor.plugins.webhook.plugin.WebhookPlugin"]+ manager = get_plugins_manager(allow_replica=False)++ # when+ manager.checkout_fully_authorized(checkout_with_items)++ # then+ mocked_webhook_trigger.assert_called_once_with(+ None,+ WebhookEventAsyncType.CHECKOUT_FULLY_AUTHORIZED,+ [any_webhook],+ checkout_with_items,+ None,+ legacy_data_generator=ANY,+ allow_replica=False,+ queue=settings.CHECKOUT_WEBHOOK_EVENTS_CELERY_QUEUE_NAME,+ )+ assert isinstance(+ mocked_webhook_trigger.call_args.kwargs["legacy_data_generator"], partial+ )++@mock.patch("saleor.plugins.webhook.plugin.get_webhooks_for_event")@mock.patch("saleor.plugins.webhook.plugin.trigger_webhooks_async")def test_checkout_metadata_updated(diff --git a/saleor/tests/fixtures.py b/saleor/tests/fixtures.pyindex 9649fa874d..1ae73c87ce 100644--- a/saleor/tests/fixtures.py+++ b/saleor/tests/fixtures.py@@ -1239,6 +1239,7 @@ def async_subscription_webhooks_with_root_objects(subscription_collection_metadata_updated_webhook,subscription_checkout_created_webhook,subscription_checkout_updated_webhook,+ subscription_checkout_fully_authorized_webhook,subscription_checkout_fully_paid_webhook,subscription_checkout_metadata_updated_webhook,subscription_page_created_webhook,@@ -1527,6 +1528,10 @@ def async_subscription_webhooks_with_root_objects(subscription_checkout_fully_paid_webhook,checkout,],+ events.CHECKOUT_FULLY_AUTHORIZED: [+ subscription_checkout_fully_authorized_webhook,+ checkout,+ ],events.CHECKOUT_METADATA_UPDATED: [subscription_checkout_metadata_updated_webhook,checkout,diff --git a/saleor/webhook/event_types.py b/saleor/webhook/event_types.pyindex b1701ca8fd..50286113ad 100644--- a/saleor/webhook/event_types.py+++ b/saleor/webhook/event_types.py@@ -145,6 +145,7 @@ class WebhookEventAsyncType:CHECKOUT_CREATED = "checkout_created"CHECKOUT_UPDATED = "checkout_updated"+ CHECKOUT_FULLY_AUTHORIZED = "checkout_fully_authorized"CHECKOUT_FULLY_PAID = "checkout_fully_paid"CHECKOUT_METADATA_UPDATED = "checkout_metadata_updated"@@ -607,6 +608,10 @@ class WebhookEventAsyncType:"permission": CheckoutPermissions.MANAGE_CHECKOUTS,"is_deferred_payload": True,},+ CHECKOUT_FULLY_AUTHORIZED: {+ "name": "Checkout fully authorized",+ "permission": CheckoutPermissions.MANAGE_CHECKOUTS,+ },CHECKOUT_FULLY_PAID: {"name": "Checkout fully paid","permission": CheckoutPermissions.MANAGE_CHECKOUTS,diff --git a/saleor/webhook/tests/fixtures/subscription_webhooks.py b/saleor/webhook/tests/fixtures/subscription_webhooks.pyindex 4f500866b3..76906edaaa 100644--- a/saleor/webhook/tests/fixtures/subscription_webhooks.py+++ b/saleor/webhook/tests/fixtures/subscription_webhooks.py@@ -811,6 +811,14 @@ def subscription_checkout_fully_paid_webhook(subscription_webhook):)+def subscription_checkout_fully_authorized_webhook(subscription_webhook):+ return subscription_webhook(+ queries.CHECKOUT_FULLY_AUTHORIZED,+ WebhookEventAsyncType.CHECKOUT_FULLY_AUTHORIZED,+ )++@pytest.fixturedef subscription_checkout_metadata_updated_webhook(subscription_webhook):return subscription_webhook(diff --git a/saleor/webhook/tests/fixtures/webhook.py b/saleor/webhook/tests/fixtures/webhook.pyindex 71019d043c..4d39af5ed1 100644--- a/saleor/webhook/tests/fixtures/webhook.py+++ b/saleor/webhook/tests/fixtures/webhook.py@@ -136,6 +136,14 @@ def setup_checkout_webhooks(...CheckoutFragment}}+ ... on CheckoutFullyAuthorized {+ issuingPrincipal {+ ...IssuingPrincipal+ }+ checkout {+ ...CheckoutFragment+ }+ }... on CheckoutMetadataUpdated {issuingPrincipal {...IssuingPrincipaldiff --git a/saleor/webhook/tests/subscription_webhooks/subscription_queries.py b/saleor/webhook/tests/subscription_webhooks/subscription_queries.pyindex 63a007fa2f..7572b37803 100644--- a/saleor/webhook/tests/subscription_webhooks/subscription_queries.py+++ b/saleor/webhook/tests/subscription_webhooks/subscription_queries.py@@ -1804,6 +1804,18 @@ CHECKOUT_FULLY_PAID = """}"""+CHECKOUT_FULLY_AUTHORIZED = """+ subscription{+ event{+ ...on CheckoutFullyAuthorized{+ checkout{+ id+ }+ }+ }+ }+"""+CHECKOUT_METADATA_UPDATED = """subscription{event{diff --git a/saleor/webhook/tests/subscription_webhooks/test_create_deliveries_for_subscription.py b/saleor/webhook/tests/subscription_webhooks/test_create_deliveries_for_subscription.pyindex 63e94bc333..f926264ec1 100644--- a/saleor/webhook/tests/subscription_webhooks/test_create_deliveries_for_subscription.py+++ b/saleor/webhook/tests/subscription_webhooks/test_create_deliveries_for_subscription.py@@ -2178,6 +2178,25 @@ def test_checkout_fully_paid(checkout, subscription_checkout_fully_paid_webhook)assert deliveries[0].webhook == webhooks[0]+def test_checkout_fully_authorized(+ checkout, subscription_checkout_fully_authorized_webhook+):+ # given+ webhooks = [subscription_checkout_fully_authorized_webhook]+ event_type = WebhookEventAsyncType.CHECKOUT_FULLY_AUTHORIZED+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)++ # when+ deliveries = create_deliveries_for_subscriptions(event_type, checkout, webhooks)++ # then+ expected_payload = json.dumps({"checkout": {"id": checkout_id}})++ assert deliveries[0].payload.get_payload() == expected_payload+ assert len(deliveries) == len(webhooks)+ assert deliveries[0].webhook == webhooks[0]++def test_checkout_metadata_updated(checkout, subscription_checkout_metadata_updated_webhook):