Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Change the response for storedPaymentMethodRequestDelete (#13794)
Maciej Korycinski46847619449d
diff --git a/saleor/graphql/payment/enums.py b/saleor/graphql/payment/enums.pyindex 2f17943426..a26a96a459 100644--- a/saleor/graphql/payment/enums.py+++ b/saleor/graphql/payment/enums.py@@ -1,3 +1,5 @@+import graphene+from ...payment import (ChargeStatus,StorePaymentMethod,@@ -6,6 +8,7 @@ from ...payment import (TransactionEventType,TransactionKind,)+from ...payment.interface import StoredPaymentMethodRequestDeleteResultfrom ..core.doc_category import DOC_CATEGORY_PAYMENTSfrom ..core.enums import to_enumfrom ..core.types import BaseEnum@@ -80,3 +83,9 @@ TokenizedPaymentFlowEnum = to_enum(type_name="TokenizedPaymentFlowEnum",description=TokenizedPaymentFlow.__doc__,)+TokenizedPaymentFlowEnum.doc_category = DOC_CATEGORY_PAYMENTS++StoredPaymentMethodRequestDeleteResultEnum = graphene.Enum.from_enum(+ StoredPaymentMethodRequestDeleteResult,+)+StoredPaymentMethodRequestDeleteResultEnum.doc_category = DOC_CATEGORY_PAYMENTSdiff --git a/saleor/graphql/payment/mutations/stored_payment_methods/payment_method_request_delete.py b/saleor/graphql/payment/mutations/stored_payment_methods/payment_method_request_delete.pyindex 5bd0b7a55a..5a2743c733 100644--- a/saleor/graphql/payment/mutations/stored_payment_methods/payment_method_request_delete.py+++ b/saleor/graphql/payment/mutations/stored_payment_methods/payment_method_request_delete.py@@ -1,7 +1,10 @@import graphenefrom django.core.exceptions import ValidationError-from .....payment.interface import StoredPaymentMethodRequestDeleteData+from .....payment.interface import (+ StoredPaymentMethodRequestDeleteData,+ StoredPaymentMethodRequestDeleteResult,+)from .....permission.auth_filters import AuthorizationFiltersfrom .....webhook.event_types import WebhookEventSyncTypefrom ....channel.utils import validate_channel@@ -12,14 +15,12 @@ from ....core.mutations import BaseMutationfrom ....core.types.common import PaymentMethodRequestDeleteErrorfrom ....core.utils import WebhookEventInfofrom ....plugins.dataloaders import get_plugin_manager_promise+from ...enums import StoredPaymentMethodRequestDeleteResultEnumclass StoredPaymentMethodRequestDelete(BaseMutation):- success = graphene.Boolean(- description="True, if the delete request was processed successfully.",- )- message = graphene.String(- description="A message returned by payment app.",+ result = StoredPaymentMethodRequestDeleteResultEnum(+ required=True, description="The result of deleting a stored payment method.")class Arguments:@@ -50,6 +51,17 @@ class StoredPaymentMethodRequestDelete(BaseMutation):@classmethoddef perform_mutation(cls, root, info, id, channel):+ try:+ return cls._perform_mutation(root, info, id, channel)+ except ValidationError as error:+ error_response = cls.handle_errors(error)+ error_response.result = (+ StoredPaymentMethodRequestDeleteResult.FAILED_TO_DELIVER+ )+ return error_response++ @classmethod+ def _perform_mutation(cls, root, info, id, channel):user = info.context.userif not user:raise ValidationError(@@ -75,4 +87,16 @@ class StoredPaymentMethodRequestDelete(BaseMutation):channel=channel,))- return cls(success=response.success, message=response.message)+ errors = []+ if (+ response.result+ != StoredPaymentMethodRequestDeleteResultEnum.SUCCESSFULLY_DELETED.value+ ):+ error_code = StoredPaymentMethodRequestDeleteErrorCode.GATEWAY_ERROR.value+ errors.append(+ {+ "message": response.error,+ "code": error_code,+ }+ )+ return cls(result=response.result, errors=errors)diff --git a/saleor/graphql/payment/tests/mutations/test_stored_payment_method_request_delete.py b/saleor/graphql/payment/tests/mutations/test_stored_payment_method_request_delete.pyindex 4a9a19e79e..04857a010b 100644--- a/saleor/graphql/payment/tests/mutations/test_stored_payment_method_request_delete.py+++ b/saleor/graphql/payment/tests/mutations/test_stored_payment_method_request_delete.py@@ -3,19 +3,21 @@ from unittest.mock import patchfrom .....payment.interface import (StoredPaymentMethodRequestDeleteData,StoredPaymentMethodRequestDeleteResponseData,+ StoredPaymentMethodRequestDeleteResult,)from .....plugins.manager import PluginsManagerfrom ....core.enums import StoredPaymentMethodRequestDeleteErrorCodefrom ....tests.utils import assert_no_permission, get_graphql_content+from ...enums import StoredPaymentMethodRequestDeleteResultEnumSTORED_PAYMENT_METHOD_REQUEST_DELETE_MUTATION = """mutation storedPaymentMethodRequestDelete($id: ID!, $channel: String!){storedPaymentMethodRequestDelete(id: $id, channel: $channel){- success- message+ resulterrors{fieldcode+ message}}}@@ -34,8 +36,8 @@ def test_stored_payment_method_request_delete(mocked_is_event_active_for_any_plugin.return_value = Truemocked_stored_payment_method_request_delete.return_value = (StoredPaymentMethodRequestDeleteResponseData(- success=True,- message=None,+ result=StoredPaymentMethodRequestDeleteResult.SUCCESSFULLY_DELETED.value,+ error=None,))expected_id = "test_id"@@ -48,7 +50,58 @@ def test_stored_payment_method_request_delete(# thencontent = get_graphql_content(response)- assert content["data"]["storedPaymentMethodRequestDelete"]["success"] is True+ assert (+ content["data"]["storedPaymentMethodRequestDelete"]["result"]+ == StoredPaymentMethodRequestDeleteResultEnum.SUCCESSFULLY_DELETED.name+ )++ mocked_is_event_active_for_any_plugin.assert_called_once_with(+ "stored_payment_method_request_delete"+ )+ mocked_stored_payment_method_request_delete.assert_called_once_with(+ request_delete_data=StoredPaymentMethodRequestDeleteData(+ payment_method_id=expected_id,+ user=user_api_client.user,+ channel=channel_USD,+ )+ )++[email protected](PluginsManager, "stored_payment_method_request_delete")[email protected](PluginsManager, "is_event_active_for_any_plugin")+def test_stored_payment_method_request_delete_app_returned_failure_event(+ mocked_is_event_active_for_any_plugin,+ mocked_stored_payment_method_request_delete,+ user_api_client,+ channel_USD,+):+ # given+ expected_error_message = "Failed to delete"+ mocked_is_event_active_for_any_plugin.return_value = True+ mocked_stored_payment_method_request_delete.return_value = (+ StoredPaymentMethodRequestDeleteResponseData(+ result=StoredPaymentMethodRequestDeleteResult.FAILED_TO_DELETE.value,+ error=expected_error_message,+ )+ )+ expected_id = "test_id"++ # when+ response = user_api_client.post_graphql(+ STORED_PAYMENT_METHOD_REQUEST_DELETE_MUTATION,+ variables={"id": expected_id, "channel": channel_USD.slug},+ )++ # then+ content = get_graphql_content(response)+ assert (+ content["data"]["storedPaymentMethodRequestDelete"]["result"]+ == StoredPaymentMethodRequestDeleteResultEnum.FAILED_TO_DELETE.name+ )+ assert len(content["data"]["storedPaymentMethodRequestDelete"]["errors"]) == 1+ error = content["data"]["storedPaymentMethodRequestDelete"]["errors"][0]+ assert error["code"] == StoredPaymentMethodRequestDeleteErrorCode.GATEWAY_ERROR.name+ assert error["message"] == expected_error_messagemocked_is_event_active_for_any_plugin.assert_called_once_with("stored_payment_method_request_delete"@@ -74,8 +127,7 @@ def test_stored_payment_method_request_delete_called_by_app(mocked_is_event_active_for_any_plugin.return_value = Truemocked_stored_payment_method_request_delete.return_value = (StoredPaymentMethodRequestDeleteResponseData(- success=True,- message="Payment method delete request was processed successfully.",+ result=StoredPaymentMethodRequestDeleteResult.SUCCESSFULLY_DELETED.value,))expected_id = "test_id"@@ -105,8 +157,7 @@ def test_stored_payment_method_request_delete_called_by_anynoums_user(mocked_is_event_active_for_any_plugin.return_value = Truemocked_stored_payment_method_request_delete.return_value = (StoredPaymentMethodRequestDeleteResponseData(- success=True,- message="Payment method delete request was processed successfully.",+ result=StoredPaymentMethodRequestDeleteResult.SUCCESSFULLY_DELETED.value,))expected_id = "test_id"@@ -136,8 +187,8 @@ def test_stored_payment_method_request_delete_not_app_or_plugin_subscribed_to_evmocked_is_event_active_for_any_plugin.return_value = Falsemocked_stored_payment_method_request_delete.return_value = (StoredPaymentMethodRequestDeleteResponseData(- success=True,- message=None,+ result=StoredPaymentMethodRequestDeleteResult.SUCCESSFULLY_DELETED.value,+ error=None,))expected_id = "test_id"@@ -150,6 +201,10 @@ def test_stored_payment_method_request_delete_not_app_or_plugin_subscribed_to_ev# thencontent = get_graphql_content(response)+ assert (+ content["data"]["storedPaymentMethodRequestDelete"]["result"]+ == StoredPaymentMethodRequestDeleteResultEnum.FAILED_TO_DELIVER.name+ )assert len(content["data"]["storedPaymentMethodRequestDelete"]["errors"]) == 1assert (content["data"]["storedPaymentMethodRequestDelete"]["errors"][0]["code"]@@ -173,8 +228,8 @@ def test_stored_payment_method_request_delete_incorrect_channel(mocked_is_event_active_for_any_plugin.return_value = Falsemocked_stored_payment_method_request_delete.return_value = (StoredPaymentMethodRequestDeleteResponseData(- success=True,- message=None,+ result=StoredPaymentMethodRequestDeleteResult.SUCCESSFULLY_DELETED,+ error=None,))expected_id = "test_id"@@ -192,6 +247,10 @@ def test_stored_payment_method_request_delete_incorrect_channel(content["data"]["storedPaymentMethodRequestDelete"]["errors"][0]["code"]== StoredPaymentMethodRequestDeleteErrorCode.NOT_FOUND.name)+ assert (+ content["data"]["storedPaymentMethodRequestDelete"]["result"]+ == StoredPaymentMethodRequestDeleteResultEnum.FAILED_TO_DELIVER.name+ )assert not mocked_is_event_active_for_any_plugin.calledassert not mocked_stored_payment_method_request_delete.calleddiff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 8359ac8e5b..ea86467efb 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -12496,7 +12496,7 @@ Represents possible tokenized payment flows that can be used to process payment.INTERACTIVE - Payment method can be used for 1 click checkout - it's prefilled incheckout form (might require additional authentication from user)"""-enum TokenizedPaymentFlowEnum {+enum TokenizedPaymentFlowEnum @doc(category: "Payments") {INTERACTIVE}@@ -23266,14 +23266,26 @@ Triggers the following webhook events:- STORED_PAYMENT_METHOD_DELETE_REQUESTED (sync): The customer requested to delete a payment method."""type StoredPaymentMethodRequestDelete @doc(category: "Payments") @webhookEventsInfo(asyncEvents: [], syncEvents: [STORED_PAYMENT_METHOD_DELETE_REQUESTED]) {- """True, if the delete request was processed successfully."""- success: Boolean-- """A message returned by payment app."""- message: String+ """The result of deleting a stored payment method."""+ result: StoredPaymentMethodRequestDeleteResult!errors: [PaymentMethodRequestDeleteError!]!}+"""+Result of deleting a stored payment method.++ This enum is used to determine the result of deleting a stored payment method.+ SUCCESSFULLY_DELETED - The stored payment method was successfully deleted.+ FAILED_TO_DELETE - The stored payment method was not deleted.+ FAILED_TO_DELIVER - The request to delete the stored payment method was not+ delivered.+"""+enum StoredPaymentMethodRequestDeleteResult @doc(category: "Payments") {+ SUCCESSFULLY_DELETED+ FAILED_TO_DELETE+ FAILED_TO_DELIVER+}+type PaymentMethodRequestDeleteError @doc(category: "Payments") {"""Name of a field that caused the error. A value of `null` indicates that the error isn't associated with a particular field.@@ -23293,6 +23305,7 @@ enum StoredPaymentMethodRequestDeleteErrorCode @doc(category: "Payments") {INVALIDNOT_FOUNDCHANNEL_INACTIVE+ GATEWAY_ERROR}"""diff --git a/saleor/payment/error_codes.py b/saleor/payment/error_codes.pyindex d219374bb5..076ae064a3 100644--- a/saleor/payment/error_codes.py+++ b/saleor/payment/error_codes.py@@ -97,3 +97,4 @@ class StoredPaymentMethodRequestDeleteErrorCode(Enum):INVALID = "invalid"NOT_FOUND = "not_found"CHANNEL_INACTIVE = "channel_inactive"+ GATEWAY_ERROR = "gateway_error"diff --git a/saleor/payment/interface.py b/saleor/payment/interface.pyindex 537ac59247..4efff56a6b 100644--- a/saleor/payment/interface.py+++ b/saleor/payment/interface.py@@ -20,12 +20,28 @@ JSONValue = Union[str, int, float, bool, None, Dict[str, Any], List[Any]]JSONType = Union[Dict[str, JSONValue], List[JSONValue]]+@dataclass+class StoredPaymentMethodRequestDeleteResult(str, Enum):+ """Result of deleting a stored payment method.++ This enum is used to determine the result of deleting a stored payment method.+ SUCCESSFULLY_DELETED - The stored payment method was successfully deleted.+ FAILED_TO_DELETE - The stored payment method was not deleted.+ FAILED_TO_DELIVER - The request to delete the stored payment method was not+ delivered.+ """++ SUCCESSFULLY_DELETED = "successfully_deleted"+ FAILED_TO_DELETE = "failed_to_delete"+ FAILED_TO_DELIVER = "failed_to_deliver"++@dataclassclass StoredPaymentMethodRequestDeleteResponseData:"""Dataclass for storing the response information from payment app."""- success: bool- message: Optional[str] = None+ result: StoredPaymentMethodRequestDeleteResult+ error: Optional[str] = None@dataclassdiff --git a/saleor/plugins/manager.py b/saleor/plugins/manager.pyindex 7d5be44e4e..8bb1789089 100644--- a/saleor/plugins/manager.py+++ b/saleor/plugins/manager.py@@ -43,6 +43,7 @@ from ..payment.interface import (PaymentMethodData,StoredPaymentMethodRequestDeleteData,StoredPaymentMethodRequestDeleteResponseData,+ StoredPaymentMethodRequestDeleteResult,TokenConfig,TransactionActionData,TransactionSessionData,@@ -1564,7 +1565,8 @@ class PluginsManager(PaymentInterface):request_delete_data: "StoredPaymentMethodRequestDeleteData",) -> "StoredPaymentMethodRequestDeleteResponseData":default_response = StoredPaymentMethodRequestDeleteResponseData(- success=False, message="Payment method request delete failed to deliver."+ result=StoredPaymentMethodRequestDeleteResult.FAILED_TO_DELIVER,+ error="Payment method request delete failed to deliver.",)response = self.__run_method_on_plugins("stored_payment_method_request_delete",diff --git a/saleor/plugins/tests/test_manager.py b/saleor/plugins/tests/test_manager.pyindex f61829d109..9fac0aad30 100644--- a/saleor/plugins/tests/test_manager.py+++ b/saleor/plugins/tests/test_manager.py@@ -23,6 +23,7 @@ from ...payment.interface import (PaymentGatewayData,StoredPaymentMethodRequestDeleteData,StoredPaymentMethodRequestDeleteResponseData,+ StoredPaymentMethodRequestDeleteResult,TransactionProcessActionData,TransactionSessionData,TransactionSessionResult,@@ -1378,9 +1379,9 @@ def test_stored_payment_method_request_delete(user=customer_user, payment_method_id="123", channel=channel_USD)previous_response = StoredPaymentMethodRequestDeleteResponseData(- success=False, message="Payment method request delete failed to deliver."+ result=StoredPaymentMethodRequestDeleteResult.FAILED_TO_DELIVER,+ error="Payment method request delete failed to deliver.",)-# whenmanager.stored_payment_method_request_delete(request_delete_data=request_delete_datadiff --git a/saleor/plugins/webhook/stored_payment_methods.py b/saleor/plugins/webhook/stored_payment_methods.pyindex d02a0b7511..e40d201d5a 100644--- a/saleor/plugins/webhook/stored_payment_methods.py+++ b/saleor/plugins/webhook/stored_payment_methods.py@@ -11,6 +11,7 @@ from ...payment.interface import (PaymentMethodCreditCardInfo,PaymentMethodData,StoredPaymentMethodRequestDeleteResponseData,+ StoredPaymentMethodRequestDeleteResult,)from ...webhook.event_types import WebhookEventSyncTypefrom ...webhook.utils import get_webhooks_for_event@@ -148,10 +149,21 @@ def get_list_stored_payment_methods_from_response(def get_response_for_stored_payment_method_request_delete(response_data: Optional[dict],) -> "StoredPaymentMethodRequestDeleteResponseData":- response_data = response_data or {"message": "Failed to delivery request."}+ if response_data is None:+ result = StoredPaymentMethodRequestDeleteResult.FAILED_TO_DELIVER+ error = "Failed to delivery request."+ else:+ try:+ response_result = response_data.get("result") or ""+ result = StoredPaymentMethodRequestDeleteResult[response_result]+ error = response_data.get("error", None)+ except KeyError:+ result = StoredPaymentMethodRequestDeleteResult.FAILED_TO_DELETE+ error = "Missing or incorrect `result` in response."+return StoredPaymentMethodRequestDeleteResponseData(- success=response_data.get("success", False),- message=response_data.get("message", None),+ result=result,+ error=error,)diff --git a/saleor/plugins/webhook/tests/test_stored_payment_method_request_delete.py b/saleor/plugins/webhook/tests/test_stored_payment_method_request_delete.pyindex 8d5c0c9ee7..d95dac1503 100644--- a/saleor/plugins/webhook/tests/test_stored_payment_method_request_delete.py+++ b/saleor/plugins/webhook/tests/test_stored_payment_method_request_delete.py@@ -9,6 +9,7 @@ from ....payment.interface import (ListStoredPaymentMethodsRequestData,StoredPaymentMethodRequestDeleteData,StoredPaymentMethodRequestDeleteResponseData,+ StoredPaymentMethodRequestDeleteResult,)from ....settings import WEBHOOK_SYNC_TIMEOUTfrom ....webhook.event_types import WebhookEventSyncType@@ -35,7 +36,9 @@ subscription {@pytest.fixturedef webhook_stored_payment_method_request_delete_response():- return {"success": True, "message": "Payment method deleted successfully"}+ return {+ "result": StoredPaymentMethodRequestDeleteResult.SUCCESSFULLY_DELETED.name,+ }@mock.patch("saleor.plugins.webhook.tasks.send_webhook_request_sync")@@ -63,7 +66,8 @@ def test_stored_payment_method_request_delete_with_static_payload()previous_value = StoredPaymentMethodRequestDeleteResponseData(- success=False, message="Payment method request delete failed to deliver."+ result=StoredPaymentMethodRequestDeleteResult.FAILED_TO_DELIVER,+ error="Payment method request delete failed to deliver.",)# when@@ -83,8 +87,7 @@ def test_stored_payment_method_request_delete_with_static_payload(mock_request.assert_called_once_with(delivery, timeout=WEBHOOK_SYNC_TIMEOUT)assert response == StoredPaymentMethodRequestDeleteResponseData(- success=True,- message=webhook_stored_payment_method_request_delete_response["message"],+ result=StoredPaymentMethodRequestDeleteResult.SUCCESSFULLY_DELETED, error=None)@@ -117,7 +120,8 @@ def test_stored_payment_method_request_delete_with_subscription_payload()previous_value = StoredPaymentMethodRequestDeleteResponseData(- success=False, message="Payment method request delete failed to deliver."+ result=StoredPaymentMethodRequestDeleteResult.FAILED_TO_DELIVER,+ error="Payment method request delete failed to deliver.",)# when@@ -137,13 +141,67 @@ def test_stored_payment_method_request_delete_with_subscription_payload(mock_request.assert_called_once_with(delivery, timeout=WEBHOOK_SYNC_TIMEOUT)assert response == StoredPaymentMethodRequestDeleteResponseData(- success=True,- message=webhook_stored_payment_method_request_delete_response["message"],+ result=StoredPaymentMethodRequestDeleteResult.SUCCESSFULLY_DELETED, error=None)@mock.patch("saleor.plugins.webhook.tasks.send_webhook_request_sync")-def test_stored_payment_method_request_delete_missing_correct_response_from_webhook(+def test_stored_payment_method_request_delete_failure_from_app(+ mock_request,+ customer_user,+ webhook_plugin,+ stored_payment_method_request_delete_app,+ webhook_stored_payment_method_request_delete_response,+ channel_USD,+):+ # given+ expected_error_msg = "Payment method request delete failed1."+ mock_request.return_value = {+ "result": StoredPaymentMethodRequestDeleteResult.FAILED_TO_DELETE.name,+ "error": expected_error_msg,+ }++ plugin = webhook_plugin()++ payment_method_id = "123"++ request_delete_data = StoredPaymentMethodRequestDeleteData(+ user=customer_user,+ payment_method_id=to_payment_app_id(+ stored_payment_method_request_delete_app, payment_method_id+ ),+ channel=channel_USD,+ )++ previous_value = StoredPaymentMethodRequestDeleteResponseData(+ result=StoredPaymentMethodRequestDeleteResult.FAILED_TO_DELIVER,+ error="Payment method request delete failed to deliver.",+ )++ # when+ response = plugin.stored_payment_method_request_delete(+ request_delete_data, previous_value+ )++ # then+ delivery = EventDelivery.objects.get()+ assert delivery.payload.payload == json.dumps(+ {+ "payment_method_id": payment_method_id,+ "user_id": graphene.Node.to_global_id("User", customer_user.pk),+ "channel_slug": channel_USD.slug,+ }+ )+ mock_request.assert_called_once_with(delivery, timeout=WEBHOOK_SYNC_TIMEOUT)++ assert response == StoredPaymentMethodRequestDeleteResponseData(+ result=StoredPaymentMethodRequestDeleteResult.FAILED_TO_DELETE,+ error=expected_error_msg,+ )++[email protected]("saleor.plugins.webhook.tasks.send_webhook_request_sync")+def test_stored_payment_method_request_delete_missing_response_from_webhook(mock_request,customer_user,webhook_plugin,@@ -171,7 +229,106 @@ def test_stored_payment_method_request_delete_missing_correct_response_from_webh)previous_value = StoredPaymentMethodRequestDeleteResponseData(- success=False, message="Payment method request delete failed to deliver."+ result=StoredPaymentMethodRequestDeleteResult.FAILED_TO_DELIVER,+ error="Payment method request delete failed to deliver.",+ )++ # when+ response = plugin.stored_payment_method_request_delete(+ request_delete_data, previous_value+ )++ # then+ delivery = EventDelivery.objects.get()++ mock_request.assert_called_once_with(delivery, timeout=WEBHOOK_SYNC_TIMEOUT)++ assert response == StoredPaymentMethodRequestDeleteResponseData(+ result=StoredPaymentMethodRequestDeleteResult.FAILED_TO_DELIVER,+ error="Failed to delivery request.",+ )++[email protected]("saleor.plugins.webhook.tasks.send_webhook_request_sync")+def test_stored_payment_method_request_delete_incorrect_result_response_from_webhook(+ mock_request,+ customer_user,+ webhook_plugin,+ stored_payment_method_request_delete_app,+ webhook_stored_payment_method_request_delete_response,+ channel_USD,+):+ # given+ mock_request.return_value = {"result": "incorrect_result"}++ webhook = stored_payment_method_request_delete_app.webhooks.first()+ webhook.subscription_query = STORED_PAYMENT_METHOD_DELETE_REQUESTED+ webhook.save()++ plugin = webhook_plugin()++ payment_method_id = "123"++ request_delete_data = StoredPaymentMethodRequestDeleteData(+ user=customer_user,+ payment_method_id=to_payment_app_id(+ stored_payment_method_request_delete_app, payment_method_id+ ),+ channel=channel_USD,+ )++ previous_value = StoredPaymentMethodRequestDeleteResponseData(+ result=StoredPaymentMethodRequestDeleteResult.FAILED_TO_DELIVER,+ error="Payment method request delete failed to deliver.",+ )++ # when+ response = plugin.stored_payment_method_request_delete(+ request_delete_data, previous_value+ )++ # then+ delivery = EventDelivery.objects.get()++ mock_request.assert_called_once_with(delivery, timeout=WEBHOOK_SYNC_TIMEOUT)++ assert response == StoredPaymentMethodRequestDeleteResponseData(+ result=StoredPaymentMethodRequestDeleteResult.FAILED_TO_DELETE,+ error="Missing or incorrect `result` in response.",+ )++[email protected]("saleor.plugins.webhook.tasks.send_webhook_request_sync")+def test_stored_payment_method_request_delete_missing_result_in_response_from_webhook(+ mock_request,+ customer_user,+ webhook_plugin,+ stored_payment_method_request_delete_app,+ webhook_stored_payment_method_request_delete_response,+ channel_USD,+):+ # given+ mock_request.return_value = {}++ webhook = stored_payment_method_request_delete_app.webhooks.first()+ webhook.subscription_query = STORED_PAYMENT_METHOD_DELETE_REQUESTED+ webhook.save()++ plugin = webhook_plugin()++ payment_method_id = "123"++ request_delete_data = StoredPaymentMethodRequestDeleteData(+ user=customer_user,+ payment_method_id=to_payment_app_id(+ stored_payment_method_request_delete_app, payment_method_id+ ),+ channel=channel_USD,+ )++ previous_value = StoredPaymentMethodRequestDeleteResponseData(+ result=StoredPaymentMethodRequestDeleteResult.FAILED_TO_DELIVER,+ error="Payment method request delete failed to deliver.",)# when@@ -185,7 +342,8 @@ def test_stored_payment_method_request_delete_missing_correct_response_from_webhmock_request.assert_called_once_with(delivery, timeout=WEBHOOK_SYNC_TIMEOUT)assert response == StoredPaymentMethodRequestDeleteResponseData(- success=False, message="Failed to delivery request."+ result=StoredPaymentMethodRequestDeleteResult.FAILED_TO_DELETE,+ error="Missing or incorrect `result` in response.",)@@ -238,7 +396,8 @@ def test_stored_payment_method_request_delete_invalidates_cache_for_app()previous_value = StoredPaymentMethodRequestDeleteResponseData(- success=False, message="Payment method request delete failed to deliver."+ result=StoredPaymentMethodRequestDeleteResult.FAILED_TO_DELIVER,+ error="Payment method request delete failed to deliver.",)data = ListStoredPaymentMethodsRequestData(@@ -290,6 +449,5 @@ def test_stored_payment_method_request_delete_invalidates_cache_for_app(mocked_request.assert_called_with(delivery, timeout=WEBHOOK_SYNC_TIMEOUT)assert response == StoredPaymentMethodRequestDeleteResponseData(- success=True,- message=webhook_stored_payment_method_request_delete_response["message"],+ result=StoredPaymentMethodRequestDeleteResult.SUCCESSFULLY_DELETED, error=None)