Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Drop depreceated fields from transactionsAPI (#13020)
Maciej Korycinski54134007b84c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex bf98b8e39d..74ebc9f616 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -6,6 +6,40 @@ All notable, unreleased changes to this project will be documented in this file.# 3.15.0 [Unreleased]### Breaking changes+- Remove input and fields related to transaction API and deprecated in 3.13 - #13020 by @korycins+ - `WebhookEventTypeEnum.TRANSACTION_ACTION_REQUEST` - Use `TRANSACTION_CHARGE_REQUESTED`, `TRANSACTION_REFUND_REQUESTED`, `TRANSACTION_CANCELATION_REQUESTED` instead.+ - `WebhookEventTypeAsyncEnum.TRANSACTION_ACTION_REQUEST` - Use `TRANSACTION_CHARGE_REQUESTED`, `TRANSACTION_REFUND_REQUESTED`, `TRANSACTION_CANCELATION_REQUESTED` instead.+ - `WebhookSampleEventTypeEnum.TRANSACTION_ACTION_REQUEST`+ - `TransactionItem`:+ - `voidedAmount` - Use `canceledAmount` instead.+ - `status` - The amounts can be used to define the current status of transactions.+ - `type` - Use `name` or `message`.+ - `reference` - Use `pspReference` instead.+ - `TransactionActionEnum.VOID` - Use `CANCEL` instead.+ - `OrderEvent.status` - Use `TransactionEvent` to track the status of `TransactionItem`.+ - `OrderEventsEnum`:+ - `TRANSACTION_CAPTURE_REQUESTED` - Use `TRANSACTION_CHARGE_REQUESTED` instead.+ - `TRANSACTION_VOID_REQUESTED` - Use `TRANSACTION_CANCEL_REQUESTED` instead.+ - `TransactionStatus`+ - `TransactionEvent`:+ - `status` - Use `type` instead.+ - `reference` - Use `pspReference` instead.+ - `name` - Use `message` instead.+ - `TransactionCreateInput`:+ - `status` - The amounts can be used to define the current status of transactions.+ - `type` - Use `name` or `message`.+ - `reference` - Use `pspReference` instead.+ - `voidedAmount` - Use `canceledAmount` instead.+ - `TransactionEventInput`:+ - `status` - Status will be calculated by Saleor.+ - `reference` - Use `pspReference` instead.+ - `name` - Use `message` instead.+ - `TransactionUpdateInput`:+ - `status` - The amounts can be used to define the current status of transactions.+ - `type` - Use `name` or `message`.+ - `reference` - Use `pspReference` instead.+ - `voidedAmount` - Use `canceledAmount` instead.+ - `TransactionActionRequest` - Use `TransactionChargeRequested`, `TransactionRefundRequested`, `TransactionCancelationRequested` instead.- Remove `OrderBulkCreateInput.trackingClientId` field - #13146 by @SzymJ- Drop backend integration with Open Exchange Rates API - #13175 by @maarcingebaladiff --git a/saleor/celeryconf.py b/saleor/celeryconf.pyindex 796bb47112..ca626e45b1 100644--- a/saleor/celeryconf.py+++ b/saleor/celeryconf.py@@ -27,5 +27,11 @@ app = Celery("saleor")app.config_from_object("django.conf:settings", namespace="CELERY")app.autodiscover_tasks()+app.autodiscover_tasks(+ packages=[+ "saleor.order.migrations.tasks",+ ],+ related_name="saleor3_15",+)app.autodiscover_tasks(lambda: discover_plugins_modules(settings.PLUGINS)) # type: ignore[misc] # circular import # noqa: E501app.autodiscover_tasks(related_name="search_tasks")diff --git a/saleor/graphql/checkout/tests/test_checkout.py b/saleor/graphql/checkout/tests/test_checkout.pyindex af2f2a7142..ec8d763dd7 100644--- a/saleor/graphql/checkout/tests/test_checkout.py+++ b/saleor/graphql/checkout/tests/test_checkout.py@@ -2226,12 +2226,11 @@ QUERY_CHECKOUT_TRANSACTIONS = """def test_checkout_transactions_missing_permission(api_client, checkout):# givencheckout.payment_transactions.create(- status="Authorized",name="Credit card",psp_reference="123",currency="USD",authorized_value=Decimal("15"),- available_actions=[TransactionAction.CHARGE, TransactionAction.VOID],+ available_actions=[TransactionAction.CHARGE, TransactionAction.CANCEL],)query = QUERY_CHECKOUT_TRANSACTIONSvariables = {"id": to_global_id_or_none(checkout)}@@ -2248,12 +2247,11 @@ def test_checkout_transactions_with_manage_checkouts():# giventransaction = checkout.payment_transactions.create(- status="Authorized",name="Credit card",psp_reference="123",currency="USD",authorized_value=Decimal("15"),- available_actions=[TransactionAction.CHARGE, TransactionAction.VOID],+ available_actions=[TransactionAction.CHARGE, TransactionAction.CANCEL],)query = QUERY_CHECKOUT_TRANSACTIONSvariables = {"id": to_global_id_or_none(checkout)}@@ -2277,12 +2275,11 @@ def test_checkout_transactions_with_handle_payments():# giventransaction = checkout.payment_transactions.create(- status="Authorized",name="Credit card",psp_reference="123",currency="USD",authorized_value=Decimal("15"),- available_actions=[TransactionAction.CHARGE, TransactionAction.VOID],+ available_actions=[TransactionAction.CHARGE, TransactionAction.CANCEL],)query = QUERY_CHECKOUT_TRANSACTIONSvariables = {"id": to_global_id_or_none(checkout)}@@ -2322,14 +2319,13 @@ def test_checkout_payment_statuses():# givencheckout_with_prices.payment_transactions.create(- status="Authorized",name="Credit card",psp_reference="123",currency="USD",authorized_value=Decimal("15"),charged_value=Decimal("5"),charge_pending_value=Decimal("6"),- available_actions=[TransactionAction.CHARGE, TransactionAction.VOID],+ available_actions=[TransactionAction.CHARGE, TransactionAction.CANCEL],)query = QUERY_CHECKOUT_STATUSES_AND_BALANCEvariables = {"id": to_global_id_or_none(checkout_with_prices)}@@ -2359,14 +2355,13 @@ def test_checkout_balance():# giventransaction = checkout_with_prices.payment_transactions.create(- status="Authorized",name="Credit card",psp_reference="123",currency="USD",authorized_value=Decimal("15"),charged_value=Decimal("5"),charge_pending_value=Decimal("6"),- available_actions=[TransactionAction.CHARGE, TransactionAction.VOID],+ available_actions=[TransactionAction.CHARGE, TransactionAction.CANCEL],)query = QUERY_CHECKOUT_STATUSES_AND_BALANCEvariables = {"id": to_global_id_or_none(checkout_with_prices)}diff --git a/saleor/graphql/core/descriptions.py b/saleor/graphql/core/descriptions.pyindex 93d1c4fba4..3f43eb4ed6 100644--- a/saleor/graphql/core/descriptions.py+++ b/saleor/graphql/core/descriptions.py@@ -1,16 +1,10 @@# Deprecation message for queries, object fields and mutations. Use it, when# `deprecation_reason` argument is supported.DEPRECATED_IN_3X_FIELD = "This field will be removed in Saleor 4.0."-PREVIEW_FEATURE_DEPRECATED_IN_313_FIELD = (- "This field will be removed in Saleor 3.15 (Preview Feature)."-)# Deprecation message for input fields and query arguments. Use it, when# deprecation message needs to be included in the field description.DEPRECATED_IN_3X_INPUT = "\n\nDEPRECATED: this field will be removed in Saleor 4.0."-PREVIEW_FEATURE_DEPRECATED_IN_313_INPUT = (- "\n\nDEPRECATED: this field will be removed in Saleor 3.15 (Preview Feature)."-)DEPRECATED_IN_3X_MUTATION = ("\n\nDEPRECATED: this mutation will be removed in Saleor 4.0."diff --git a/saleor/graphql/order/enums.py b/saleor/graphql/order/enums.pyindex 732597297f..e79e81a99d 100644--- a/saleor/graphql/order/enums.py+++ b/saleor/graphql/order/enums.py@@ -11,7 +11,6 @@ from ...order import (StockUpdatePolicy,error_codes,)-from ..core.descriptions import PREVIEW_FEATURE_DEPRECATED_IN_313_FIELDfrom ..core.doc_category import DOC_CATEGORY_ORDERSfrom ..core.enums import to_enumfrom ..core.types import BaseEnum@@ -20,16 +19,6 @@ from ..core.types import BaseEnumdef order_event_enum_description(enum):if enum is None:return "The different order event types. "- if enum == OrderEventsEnum.TRANSACTION_VOID_REQUESTED:- return (- f"{PREVIEW_FEATURE_DEPRECATED_IN_313_FIELD} "- "Use `TRANSACTION_CANCEL_REQUESTED` instead."- )- if enum == OrderEventsEnum.TRANSACTION_CAPTURE_REQUESTED:- return (- f"{PREVIEW_FEATURE_DEPRECATED_IN_313_FIELD} "- "Use `TRANSACTION_CHARGE_REQUESTED` instead."- )return Nonediff --git a/saleor/graphql/order/tests/benchmark/test_order_bulk_create.py b/saleor/graphql/order/tests/benchmark/test_order_bulk_create.pyindex 0160652228..98f0755451 100644--- a/saleor/graphql/order/tests/benchmark/test_order_bulk_create.py+++ b/saleor/graphql/order/tests/benchmark/test_order_bulk_create.py@@ -42,7 +42,7 @@ def test_order_bulk_create(order_2["notes"] = [note_1, note_2]transaction_1 = {- "status": "Authorized for 10$",+ "name": "Authorized for 10$","amountAuthorized": {"amount": Decimal("20"),"currency": "PLN",@@ -50,7 +50,7 @@ def test_order_bulk_create(}transaction_2 = {- "type": "Credit Card",+ "name": "Credit Card","amountCharged": {"amount": Decimal("100"),"currency": "PLN",diff --git a/saleor/graphql/order/tests/mutations/test_fulfillment_refund_products.py b/saleor/graphql/order/tests/mutations/test_fulfillment_refund_products.pyindex 9b4baa32ae..f52189aac4 100644--- a/saleor/graphql/order/tests/mutations/test_fulfillment_refund_products.py+++ b/saleor/graphql/order/tests/mutations/test_fulfillment_refund_products.py@@ -81,7 +81,7 @@ def test_fulfillment_refund_products_by_user_no_channel_access(@patch("saleor.order.actions.gateway.refund")-def test_fulfillment_refund_products_with_transaction_action_request_by_app(+def test_fulfillment_refund_products_with_action_requested_by_app(mocked_refund,app_api_client,permission_manage_orders,diff --git a/saleor/graphql/order/tests/mutations/test_order_bulk_create.py b/saleor/graphql/order/tests/mutations/test_order_bulk_create.pyindex 6e2ec4f3a5..371174dfc6 100644--- a/saleor/graphql/order/tests/mutations/test_order_bulk_create.py+++ b/saleor/graphql/order/tests/mutations/test_order_bulk_create.py@@ -207,9 +207,9 @@ ORDER_BULK_CREATE = """}transactions {id- reference- type- status+ pspReference+ message+ nameauthorizedAmount {amountcurrency@@ -340,12 +340,12 @@ def order_bulk_input(fulfillment = {"trackingCode": "abc-123", "lines": [fulfillment_line]}transaction = {- "status": "Authorized for 10$",- "type": "Credit Card",- "reference": "PSP reference - 123",+ "name": "Authorized for 10$",+ "message": "Credit Card",+ "pspReference": "PSP reference - 123","availableActions": [TransactionActionEnum.CHARGE.name,- TransactionActionEnum.VOID.name,+ TransactionActionEnum.CANCEL.name,],"amountAuthorized": {"amount": Decimal("10"),@@ -666,18 +666,18 @@ def test_order_bulk_create(assert db_fulfillment.lines.all()[0].id == db_fulfillment_line.idtransaction = order["transactions"][0]- assert transaction["reference"] == "PSP reference - 123"- assert transaction["type"] == "Credit Card"- assert transaction["status"] == "Authorized for 10$"+ assert transaction["pspReference"] == "PSP reference - 123"+ assert transaction["message"] == "Credit Card"+ assert transaction["name"] == "Authorized for 10$"assert transaction["authorizedAmount"]["amount"] == Decimal("10")assert transaction["authorizedAmount"]["currency"] == "PLN"db_transaction = TransactionItem.objects.get()assert db_transaction.authorized_value == Decimal("10")assert db_transaction.currency == "PLN"assert db_transaction.psp_reference == "PSP reference - 123"- assert db_transaction.status == "Authorized for 10$"+ assert db_transaction.name == "Authorized for 10$"assert db_transaction.order_id == db_order.id- assert db_transaction.name == "Credit Card"+ assert db_transaction.message == "Credit Card"assert db_transaction.metadata == {"test-1": "123"}assert db_transaction.private_metadata == {"test-2": "321"}@@ -995,7 +995,7 @@ def test_order_bulk_create_multiple_transactions(transactions_count = TransactionItem.objects.count()transaction_1 = {- "status": "Authorized for 10$",+ "name": "Authorized for 10$","amountAuthorized": {"amount": Decimal("20"),"currency": "PLN",@@ -1003,7 +1003,7 @@ def test_order_bulk_create_multiple_transactions(}transaction_2 = {- "type": "Credit Card",+ "message": "Credit Card","amountCharged": {"amount": Decimal("100"),"currency": "PLN",@@ -1011,7 +1011,7 @@ def test_order_bulk_create_multiple_transactions(}transaction_3 = {- "reference": "PSP reference - 123",+ "pspReference": "PSP reference - 123","amountRefunded": {"amount": Decimal("15"),"currency": "PLN",@@ -1052,12 +1052,12 @@ def test_order_bulk_create_multiple_transactions(order = data[0]["order"]transaction_1, transaction_2, transaction_3, transaction_4 = order["transactions"]- assert transaction_1["status"] == "Authorized for 10$"+ assert transaction_1["name"] == "Authorized for 10$"assert transaction_1["authorizedAmount"]["amount"] == Decimal("20")- assert transaction_2["type"] == "Credit Card"+ assert transaction_2["message"] == "Credit Card"assert transaction_2["chargedAmount"]["amount"] == Decimal("100")assert transaction_2["chargedAmount"]["currency"] == "PLN"- assert transaction_3["reference"] == "PSP reference - 123"+ assert transaction_3["pspReference"] == "PSP reference - 123"assert transaction_3["refundedAmount"]["amount"] == Decimal("15")assert transaction_3["refundedAmount"]["currency"] == "PLN"assert transaction_4["canceledAmount"]["amount"] == Decimal("20")@@ -1070,9 +1070,9 @@ def test_order_bulk_create_multiple_transactions(db_transaction_3,db_transaction_4,) = TransactionItem.objects.all()- assert db_transaction_1.status == "Authorized for 10$"+ assert db_transaction_1.name == "Authorized for 10$"assert db_transaction_1.authorized_value == Decimal("20")- assert db_transaction_2.name == "Credit Card"+ assert db_transaction_2.message == "Credit Card"assert db_transaction_2.charged_value == Decimal("100")assert db_transaction_3.psp_reference == "PSP reference - 123"assert db_transaction_3.refunded_value == Decimal("15")diff --git a/saleor/graphql/order/tests/queries/test_order.py b/saleor/graphql/order/tests/queries/test_order.pyindex bdc6b1279e..dab43f53d6 100644--- a/saleor/graphql/order/tests/queries/test_order.py+++ b/saleor/graphql/order/tests/queries/test_order.py@@ -22,7 +22,6 @@ from .....payment.models import TransactionEvent, TransactionItemfrom .....shipping.models import ShippingMethod, ShippingMethodChannelListingfrom .....warehouse.models import Warehousefrom ....order.enums import OrderAuthorizeStatusEnum, OrderChargeStatusEnum-from ....payment.enums import TransactionEventStatusEnumfrom ....payment.types import PaymentChargeStatusEnumfrom ....tests.utils import (assert_graphql_error_with_message,@@ -126,9 +125,8 @@ query OrdersQuery {transactions{idevents{- statuspspReference- name+ message}}authorizeStatus@@ -256,7 +254,6 @@ query OrdersQuery {discount {value}- status}}}@@ -699,32 +696,31 @@ def test_order_query_with_transactions_details(user=None,app=None,reference="ref-123",- status=None,message="Message",)transactions = TransactionItem.objects.bulk_create([TransactionItem(order_id=order.id,- status="Authorized",+ message="Authorized",name="Credit card",psp_reference="123",currency="USD",authorized_value=Decimal("15"),- available_actions=[TransactionAction.CHARGE, TransactionAction.VOID],+ available_actions=[TransactionAction.CHARGE, TransactionAction.CANCEL],),TransactionItem(order_id=order.id,- status="Authorized second credit card",+ message="Authorized second credit card",name="Credit card",psp_reference="321",currency="USD",authorized_value=Decimal("10"),- available_actions=[TransactionAction.CHARGE, TransactionAction.VOID],+ available_actions=[TransactionAction.CHARGE, TransactionAction.CANCEL],),TransactionItem(order_id=order.id,- status="Captured",+ message="Captured",name="Credit card",psp_reference="111",currency="USD",@@ -733,7 +729,7 @@ def test_order_query_with_transactions_details(),TransactionItem(order_id=order.id,- status="Captured",+ message="Captured",name="Credit card",psp_reference="111",currency="USD",@@ -744,14 +740,12 @@ def test_order_query_with_transactions_details()update_order_authorize_data(order)update_order_charge_data(order)- event_status = TransactionEventStatusEnum.FAILURE.valueevent_reference = "PSP-ref"- event_name = "Failed authorization"+ event_message = "Failed authorization"TransactionEvent.objects.bulk_create([TransactionEvent(- message=event_name,- status=event_status,+ message=event_message,psp_reference=f"{event_reference}{transaction.token}",transaction=transaction,currency=transaction.currency,@@ -789,8 +783,7 @@ def test_order_query_with_transactions_details(for transaction in order_data["transactions"]:assert len(transaction["events"]) == 1event = transaction["events"][0]- assert event["name"] == event_name- assert event["status"] == TransactionEventStatusEnum.FAILURE.name+ assert event["message"] == event_message_, expected_uuid = graphene.Node.from_global_id(transaction.get("id"))assert event["pspReference"] == f"{event_reference}{expected_uuid}"diff --git a/saleor/graphql/order/tests/queries/test_order_amounts.py b/saleor/graphql/order/tests/queries/test_order_amounts.pyindex b57d92ec06..c12a9bf48a 100644--- a/saleor/graphql/order/tests/queries/test_order_amounts.py+++ b/saleor/graphql/order/tests/queries/test_order_amounts.py@@ -62,34 +62,29 @@ query OrdersQuery {amount}transactions{- referencepspReference- type- statusmodifiedAtcreatedAtauthorizedAmount{amountcurrency}- voidedAmount{+ chargedAmount{currencyamount}- chargedAmount{+ refundedAmount{currencyamount}- refundedAmount{+ canceledAmount{currencyamount}events{- status- pspReference- reference- name- createdAt+ pspReference+ message+ createdAt}}subtotal {diff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.pyindex 732f47b767..3fca181746 100644--- a/saleor/graphql/order/types.py+++ b/saleor/graphql/order/types.py@@ -77,7 +77,6 @@ from ..core.descriptions import (ADDED_IN_315,DEPRECATED_IN_3X_FIELD,PREVIEW_FEATURE,- PREVIEW_FEATURE_DEPRECATED_IN_313_FIELD,)from ..core.doc_category import DOC_CATEGORY_ORDERSfrom ..core.enums import LanguageCodeEnum@@ -108,7 +107,7 @@ from ..invoice.types import Invoicefrom ..meta.resolvers import check_private_metadata_privilege, resolve_metadatafrom ..meta.types import MetadataItem, ObjectWithMetadatafrom ..payment.dataloaders import TransactionByPaymentIdLoader-from ..payment.enums import OrderAction, TransactionEventStatusEnum+from ..payment.enums import OrderActionfrom ..payment.types import Payment, PaymentChargeStatusEnum, TransactionItemfrom ..plugins.dataloaders import (get_plugin_manager_promise,@@ -392,14 +391,6 @@ class OrderEvent(ModelObjectType[models.OrderEvent]):discount = graphene.Field(OrderEventDiscountObject, description="The discount applied to the order.")- status = graphene.Field(- TransactionEventStatusEnum,- description="The status of payment's transaction.",- deprecation_reason=(- PREVIEW_FEATURE_DEPRECATED_IN_313_FIELD- + "Use `TransactionEvent` to track the status of `TransactionItem`."- ),- )reference = graphene.String(description="The reference of payment's transaction.")class Meta:diff --git a/saleor/graphql/payment/enums.py b/saleor/graphql/payment/enums.pyindex 2c20eca059..ab5015d71d 100644--- a/saleor/graphql/payment/enums.py+++ b/saleor/graphql/payment/enums.py@@ -2,7 +2,6 @@ from ...payment import (ChargeStatus,StorePaymentMethod,TransactionAction,- TransactionEventStatus,TransactionEventType,TransactionKind,)@@ -28,13 +27,6 @@ TransactionEventTypeEnum = to_enum()TransactionEventTypeEnum.doc_category = DOC_CATEGORY_PAYMENTS-TransactionEventStatusEnum = to_enum(- TransactionEventStatus,- type_name="TransactionStatus",- description=TransactionEventStatus.__doc__,-)-TransactionEventStatusEnum.doc_category = DOC_CATEGORY_PAYMENTS-class OrderAction(BaseEnum):CAPTURE = "CAPTURE"diff --git a/saleor/graphql/payment/mutations/transaction/transaction_create.py b/saleor/graphql/payment/mutations/transaction/transaction_create.pyindex e45d134057..c0b9051a62 100644--- a/saleor/graphql/payment/mutations/transaction/transaction_create.py+++ b/saleor/graphql/payment/mutations/transaction/transaction_create.py@@ -24,38 +24,20 @@ from .....payment.utils import create_manual_adjustment_eventsfrom .....permission.enums import PaymentPermissionsfrom ....app.dataloaders import get_app_promisefrom ....core import ResolveInfo-from ....core.descriptions import (- ADDED_IN_34,- ADDED_IN_313,- PREVIEW_FEATURE,- PREVIEW_FEATURE_DEPRECATED_IN_313_INPUT,-)+from ....core.descriptions import ADDED_IN_34, ADDED_IN_313, PREVIEW_FEATUREfrom ....core.doc_category import DOC_CATEGORY_PAYMENTSfrom ....core.mutations import BaseMutationfrom ....core.types import BaseInputObjectTypefrom ....core.types import common as common_typesfrom ....meta.inputs import MetadataInputfrom ....plugins.dataloaders import get_plugin_manager_promise-from ...enums import TransactionActionEnum, TransactionEventStatusEnum+from ...enums import TransactionActionEnumfrom ...types import TransactionItemfrom ...utils import metadata_contains_empty_keyfrom ..payment.payment_check_balance import MoneyInputclass TransactionCreateInput(BaseInputObjectType):- status = graphene.String(- description=(- "Status of the transaction."- + PREVIEW_FEATURE_DEPRECATED_IN_313_INPUT- + " The `status` is not needed. The amounts can be used to define "- "the current status of transactions."- ),- )- type = graphene.String(- description="Payment type used for this transaction."- + PREVIEW_FEATURE_DEPRECATED_IN_313_INPUT- + " Use `name` and `message` instead.",- )name = graphene.String(description="Payment name of the transaction." + ADDED_IN_313)@@ -63,13 +45,6 @@ class TransactionCreateInput(BaseInputObjectType):description="The message of the transaction." + ADDED_IN_313)- reference = graphene.String(- description=(- "Reference of the transaction. "- + PREVIEW_FEATURE_DEPRECATED_IN_313_INPUT- + " Use `pspReference` instead."- )- )psp_reference = graphene.String(description=("PSP Reference of the transaction. " + ADDED_IN_313))@@ -80,11 +55,7 @@ class TransactionCreateInput(BaseInputObjectType):amount_authorized = MoneyInput(description="Amount authorized by this transaction.")amount_charged = MoneyInput(description="Amount charged by this transaction.")amount_refunded = MoneyInput(description="Amount refunded by this transaction.")- amount_voided = MoneyInput(- description="Amount voided by this transaction."- + PREVIEW_FEATURE_DEPRECATED_IN_313_INPUT- + " Use `amountCanceled` instead."- )+amount_canceled = MoneyInput(description="Amount canceled by this transaction." + ADDED_IN_313)@@ -111,29 +82,10 @@ class TransactionCreateInput(BaseInputObjectType):class TransactionEventInput(BaseInputObjectType):- status = graphene.Field(- TransactionEventStatusEnum,- required=False,- description="Current status of the payment transaction."- + PREVIEW_FEATURE_DEPRECATED_IN_313_INPUT- + " Status will be calculated by Saleor.",- )- reference = graphene.String(- description=(- "Reference of the transaction. "- + PREVIEW_FEATURE_DEPRECATED_IN_313_INPUT- + " Use `pspReference` instead."- )- )-psp_reference = graphene.String(description=("PSP Reference related to this action." + ADDED_IN_313))- name = graphene.String(- description="Name of the transaction."- + PREVIEW_FEATURE_DEPRECATED_IN_313_INPUT- + " Use `message` instead. `name` field will be added to `message`."- )+message = graphene.String(description="The message related to the event." + ADDED_IN_313)@@ -208,8 +160,6 @@ class TransactionCreate(BaseMutation):if amount_canceled := cleaned_data.pop("amount_canceled", None):money_data["canceled_value"] = amount_canceled["amount"]- elif amount_voided := cleaned_data.pop("amount_voided", None):- money_data["canceled_value"] = amount_voided["amount"]return money_data@classmethod@@ -248,7 +198,6 @@ class TransactionCreate(BaseMutation):"amount_charged","amount_refunded","amount_canceled",- "amount_voided",]errors = {}for money_field_name in money_input_fields:@@ -295,13 +244,6 @@ class TransactionCreate(BaseMutation):cls, transaction_input: dict, user, app, save: bool = True) -> payment_models.TransactionItem:cls.cleanup_metadata_data(transaction_input)-- transaction_type = transaction_input.pop("type", None)- transaction_input["name"] = transaction_input.get("name", transaction_type)- reference = transaction_input.pop("reference", None)- transaction_input["psp_reference"] = transaction_input.get(- "psp_reference", reference- )app_identifier = Noneif app and app.identifier:app_identifier = app.identifier@@ -325,15 +267,12 @@ class TransactionCreate(BaseMutation):user,app,) -> payment_models.TransactionEvent:- reference = transaction_event_input.pop("reference", None)- psp_reference = transaction_event_input.get("psp_reference", reference)app_identifier = Noneif app and app.identifier:app_identifier = app.identifierreturn transaction.events.create(- status=transaction_event_input.get("status"),- psp_reference=psp_reference,- message=cls.create_event_message(transaction_event_input),+ psp_reference=transaction_event_input.get("psp_reference"),+ message=transaction_event_input.get("message", ""),transaction=transaction,user=user if user and user.is_authenticated else None,app_identifier=app_identifier,@@ -342,18 +281,6 @@ class TransactionCreate(BaseMutation):currency=transaction.currency,)- @classmethod- def create_event_message(cls, transaction_event: dict) -> str:- message = transaction_event.get("message")- name = transaction_event.get("name")- if message and name:- return message + " " + name- elif message:- return message- elif name:- return name- return ""-@classmethoddef update_order(cls,@@ -418,15 +345,12 @@ class TransactionCreate(BaseMutation):else:transaction_data["order_id"] = order_or_checkout_instance.pkif transaction_event:- reference = transaction_event.get("reference", None)- psp_reference = transaction_event.get("psp_reference", reference)order_transaction_event(order=order_or_checkout_instance,user=user,app=app,- reference=psp_reference,- status=transaction_event.get("status"),- message=cls.create_event_message(transaction_event),+ reference=transaction_event.get("psp_reference"),+ message=transaction_event.get("message", ""),)money_data = cls.get_money_data_from_input(transaction_data)new_transaction = cls.create_transaction(transaction_data, user=user, app=app)diff --git a/saleor/graphql/payment/mutations/transaction/transaction_request_action.py b/saleor/graphql/payment/mutations/transaction/transaction_request_action.pyindex a5609bd971..413f0863e6 100644--- a/saleor/graphql/payment/mutations/transaction/transaction_request_action.py+++ b/saleor/graphql/payment/mutations/transaction/transaction_request_action.py@@ -68,7 +68,7 @@ class TransactionRequestAction(BaseMutation):user: Optional["User"],app: Optional[App],):- if action == TransactionAction.VOID or action == TransactionAction.CANCEL:+ if action == TransactionAction.CANCEL:transaction = action_kwargs["transaction"]request_event = cls.create_transaction_event_requested(transaction, 0, action, user=user, app=app@@ -104,7 +104,7 @@ class TransactionRequestAction(BaseMutation):def create_transaction_event_requested(cls, transaction, action_value, action, user=None, app=None):- if action in (TransactionAction.CANCEL, TransactionAction.VOID):+ if action == TransactionAction.CANCEL:type = TransactionEventType.CANCEL_REQUESTelif action == TransactionAction.CHARGE:type = TransactionEventType.CHARGE_REQUESTdiff --git a/saleor/graphql/payment/mutations/transaction/transaction_update.py b/saleor/graphql/payment/mutations/transaction/transaction_update.pyindex 789357cf52..b34f98b6d8 100644--- a/saleor/graphql/payment/mutations/transaction/transaction_update.py+++ b/saleor/graphql/payment/mutations/transaction/transaction_update.py@@ -129,9 +129,7 @@ class TransactionUpdate(TransactionCreate):user: Optional["User"],app: Optional["App"],):- psp_reference = transaction_data.get(- "psp_reference", transaction_data.pop("reference", None)- )+ psp_reference = transaction_data.get("psp_reference")if psp_reference and instance.psp_reference != psp_reference:if payment_models.TransactionItem.objects.filter(psp_reference=psp_reference@@ -144,10 +142,6 @@ class TransactionUpdate(TransactionCreate):)})- transaction_data["name"] = transaction_data.get(- "name", transaction_data.pop("type", None)- )- transaction_data["psp_reference"] = psp_referenceinstance = cls.construct_instance(instance, transaction_data)instance.save()if money_data:@@ -212,15 +206,12 @@ class TransactionUpdate(TransactionCreate):if transaction_event:event = cls.create_transaction_event(transaction_event, instance, user, app)if instance.order:- reference = transaction_event.pop("reference", None)- psp_reference = transaction_event.get("psp_reference", reference)order_transaction_event(order=instance.order,user=user,app=app,- reference=psp_reference or "",- status=transaction_event["status"],- message=cls.create_event_message(transaction_event),+ reference=transaction_event.get("psp_reference"),+ message=transaction_event.get("message", ""),)if instance.order_id:order = cast(order_models.Order, instance.order)diff --git a/saleor/graphql/payment/tests/mutations/test_transaction_create.py b/saleor/graphql/payment/tests/mutations/test_transaction_create.pyindex 454fd646ee..348c3d88e2 100644--- a/saleor/graphql/payment/tests/mutations/test_transaction_create.py+++ b/saleor/graphql/payment/tests/mutations/test_transaction_create.py@@ -9,16 +9,12 @@ from .....checkout.calculations import fetch_checkout_datafrom .....checkout.fetch import fetch_checkout_info, fetch_checkout_linesfrom .....order import OrderAuthorizeStatus, OrderChargeStatus, OrderEvents, OrderStatusfrom .....order.utils import update_order_authorize_data, update_order_charge_data-from .....payment import TransactionEventStatus, TransactionEventType+from .....payment import TransactionEventTypefrom .....payment.error_codes import TransactionCreateErrorCodefrom .....payment.models import TransactionItemfrom ....core.utils import to_global_id_or_nonefrom ....tests.utils import assert_no_permission, get_graphql_content-from ...enums import (- TransactionActionEnum,- TransactionEventStatusEnum,- TransactionEventTypeEnum,-)+from ...enums import TransactionActionEnum, TransactionEventTypeEnumTEST_SERVER_DOMAIN = "testserver.com"@@ -37,8 +33,6 @@ mutation TransactionCreate(idactionspspReference- type- statusmodifiedAtcreatedAtexternalUrl@@ -50,10 +44,6 @@ mutation TransactionCreate(currencyamount}- voidedAmount{- currency- amount- }chargedAmount{currencyamount@@ -71,9 +61,7 @@ mutation TransactionCreate(}}events{- statuspspReference- namemessagecreatedAtexternalUrl@@ -106,12 +94,10 @@ def test_transaction_create_updates_order_authorize_amounts(order_with_lines, permission_manage_payments, app_api_client):# given- status = "Authorized for 10$"- type = "Credit Card"+ name = "Credit Card"psp_reference = "PSP reference - 123"available_actions = [TransactionActionEnum.CHARGE.name,- TransactionActionEnum.VOID.name,]authorized_value = Decimal("10")metadata = {"key": "test-1", "value": "123"}@@ -121,8 +107,7 @@ def test_transaction_create_updates_order_authorize_amounts(variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": status,- "type": type,+ "name": name,"pspReference": psp_reference,"availableActions": available_actions,"amountAuthorized": {@@ -152,12 +137,10 @@ def test_transaction_create_for_order_by_app(order_with_lines, permission_manage_payments, app_api_client):# given- status = "Authorized for 10$"- type = "Credit Card"+ name = "Credit Card"psp_reference = "PSP reference - 123"available_actions = [TransactionActionEnum.CHARGE.name,- TransactionActionEnum.VOID.name,]authorized_value = Decimal("10")metadata = {"key": "test-1", "value": "123"}@@ -167,8 +150,7 @@ def test_transaction_create_for_order_by_app(variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": status,- "type": type,+ "name": name,"pspReference": psp_reference,"availableActions": available_actions,"amountAuthorized": {@@ -191,14 +173,12 @@ def test_transaction_create_for_order_by_app(content = get_graphql_content(response)data = content["data"]["transactionCreate"]["transaction"]assert data["actions"] == available_actions- assert data["status"] == statusassert data["pspReference"] == psp_referenceassert data["authorizedAmount"]["amount"] == authorized_valueassert data["externalUrl"] == external_urlassert data["createdBy"]["id"] == to_global_id_or_none(app_api_client.app)assert available_actions == list(map(str.upper, transaction.available_actions))- assert status == transaction.statusassert psp_reference == transaction.psp_referenceassert authorized_value == transaction.authorized_valueassert transaction.metadata == {metadata["key"]: metadata["value"]}@@ -227,8 +207,7 @@ def test_transaction_create_for_order_updates_order_total_authorized_by_app(variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": "Authorized for 10$",- "type": "Credit Card",+ "name": "Credit Card","pspReference": "PSP reference - 123","availableActions": [],"amountAuthorized": {@@ -273,8 +252,7 @@ def test_transaction_create_for_order_updates_order_total_charged_by_app(variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": "Charged 10$",- "type": "Credit Card",+ "name": "Credit Card","pspReference": "PSP reference - 123","availableActions": [],"amountCharged": {@@ -308,12 +286,10 @@ def test_transaction_create_for_checkout_by_app(checkout_with_items, permission_manage_payments, app_api_client):# given- status = "Authorized for 10$"- type = "Credit Card"+ name = "Credit Card"psp_reference = "PSP reference - 123"available_actions = [TransactionActionEnum.CHARGE.name,- TransactionActionEnum.VOID.name,]authorized_value = Decimal("10")metadata = {"key": "test-1", "value": "123"}@@ -323,8 +299,7 @@ def test_transaction_create_for_checkout_by_app(variables = {"id": graphene.Node.to_global_id("Checkout", checkout_with_items.pk),"transaction": {- "status": status,- "type": type,+ "name": name,"pspReference": psp_reference,"availableActions": available_actions,"amountAuthorized": {@@ -351,14 +326,12 @@ def test_transaction_create_for_checkout_by_app(content = get_graphql_content(response)data = content["data"]["transactionCreate"]["transaction"]assert data["actions"] == available_actions- assert data["status"] == statusassert data["pspReference"] == psp_referenceassert data["authorizedAmount"]["amount"] == authorized_valueassert data["externalUrl"] == external_urlassert data["createdBy"]["id"] == to_global_id_or_none(app_api_client.app)assert available_actions == list(map(str.upper, transaction.available_actions))- assert status == transaction.statusassert psp_reference == transaction.psp_referenceassert authorized_value == transaction.authorized_valueassert transaction.metadata == {metadata["key"]: metadata["value"]}@@ -376,7 +349,6 @@ def test_transaction_create_for_checkout_by_app([("amountAuthorized", "authorized_value"),("amountCharged", "charged_value"),- ("amountVoided", "canceled_value"),("amountCanceled", "canceled_value"),("amountRefunded", "refunded_value"),],@@ -389,16 +361,14 @@ def test_transaction_create_calculate_amount_by_app(app_api_client,):# given- status = "Authorized for 10$"- type = "Credit Card"+ name = "Credit Card"psp_reference = "PSP reference - 123"expected_value = Decimal("10")variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": status,- "type": type,+ "name": name,"pspReference": psp_reference,"availableActions": [],amount_field_name: {@@ -424,12 +394,10 @@ def test_transaction_create_multiple_amounts_provided_by_app(order_with_lines, permission_manage_payments, app_api_client):# given- status = "Authorized for 10$"- type = "Credit Card"+ name = "Credit Card"psp_reference = "PSP reference - 123"available_actions = [TransactionActionEnum.CHARGE.name,- TransactionActionEnum.VOID.name,]authorized_value = Decimal("10")charged_value = Decimal("11")@@ -439,8 +407,7 @@ def test_transaction_create_multiple_amounts_provided_by_app(variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": status,- "type": type,+ "name": name,"pspReference": psp_reference,"availableActions": available_actions,"amountAuthorized": {@@ -472,7 +439,7 @@ def test_transaction_create_multiple_amounts_provided_by_app(content = get_graphql_content(response)data = content["data"]["transactionCreate"]["transaction"]assert data["actions"] == available_actions- assert data["status"] == status+assert data["pspReference"] == psp_referenceassert data["authorizedAmount"]["amount"] == authorized_valueassert data["chargedAmount"]["amount"] == charged_value@@ -489,12 +456,10 @@ def test_transaction_create_create_event_for_order_by_app(order_with_lines, permission_manage_payments, app_api_client):# given- status = "Authorized for 10$"- type = "Credit Card"+ name = "Credit Card"psp_reference = "PSP reference - 123"available_actions = [TransactionActionEnum.CHARGE.name,- TransactionActionEnum.VOID.name,]authorized_value = Decimal("10")transaction_reference = "transaction reference"@@ -503,8 +468,7 @@ def test_transaction_create_create_event_for_order_by_app(variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": status,- "type": type,+ "name": name,"pspReference": psp_reference,"availableActions": available_actions,"amountAuthorized": {@@ -531,18 +495,15 @@ def test_transaction_create_create_event_for_order_by_app(assert event.parameters == {"message": transaction_name,"reference": transaction_reference,- "status": None,}def test_transaction_create_missing_permission_by_app(order_with_lines, app_api_client):# given- status = "Authorized for 10$"- type = "Credit Card"+ name = "Credit Card"psp_reference = "PSP reference - 123"available_actions = [TransactionActionEnum.CHARGE.name,- TransactionActionEnum.VOID.name,]authorized_value = Decimal("10")metadata = {"key": "test-1", "value": "123"}@@ -551,8 +512,7 @@ def test_transaction_create_missing_permission_by_app(order_with_lines, app_api_variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": status,- "type": type,+ "name": name,"pspReference": psp_reference,"availableActions": available_actions,"amountAuthorized": {@@ -576,7 +536,6 @@ def test_transaction_create_missing_permission_by_app(order_with_lines, app_api_[("amountAuthorized", "authorized_value"),("amountCharged", "charged_value"),- ("amountVoided", "canceled_value"),("amountCanceled", "canceled_value"),("amountRefunded", "refunded_value"),],@@ -589,16 +548,14 @@ def test_transaction_create_incorrect_currency_by_app(app_api_client,):# given- status = "Authorized for 10$"- type = "Credit Card"+ name = "Credit Card"psp_reference = "PSP reference - 123"expected_value = Decimal("10")variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": status,- "type": type,+ "name": name,"pspReference": psp_reference,"availableActions": [],amount_field_name: {@@ -626,12 +583,10 @@ def test_transaction_create_empty_metadata_key_by_app(order_with_lines, permission_manage_payments, app_api_client):# given- status = "Authorized for 10$"- type = "Credit Card"+ name = "Credit Card"psp_reference = "PSP reference - 123"available_actions = [TransactionActionEnum.CHARGE.name,- TransactionActionEnum.VOID.name,]authorized_value = Decimal("10")metadata = {"key": "", "value": "123"}@@ -639,8 +594,7 @@ def test_transaction_create_empty_metadata_key_by_app(variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": status,- "type": type,+ "name": name,"pspReference": psp_reference,"availableActions": available_actions,"amountAuthorized": {@@ -670,12 +624,10 @@ def test_transaction_create_empty_private_metadata_key_by_app(order_with_lines, permission_manage_payments, app_api_client):# given- status = "Authorized for 10$"- type = "Credit Card"+ name = "Credit Card"psp_reference = "PSP reference - 123"available_actions = [TransactionActionEnum.CHARGE.name,- TransactionActionEnum.VOID.name,]authorized_value = Decimal("10")metadata = {"key": "test-1", "value": "123"}@@ -683,8 +635,7 @@ def test_transaction_create_empty_private_metadata_key_by_app(variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": status,- "type": type,+ "name": name,"pspReference": psp_reference,"availableActions": available_actions,"amountAuthorized": {@@ -714,8 +665,7 @@ def test_creates_transaction_event_for_order_by_app(order_with_lines, permission_manage_payments, app_api_client):# given- status = "Failed authorized for 10$"- type = "Credit Card"+ name = "Credit Card"psp_reference = "PSP reference - 123"available_actions = []authorized_value = Decimal("0")@@ -724,12 +674,11 @@ def test_creates_transaction_event_for_order_by_app(event_psp_reference = "PSP-ref"event_message = "Failed authorization"- event_name = "Depreceated field attached to message."+variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": status,- "type": type,+ "name": name,"pspReference": psp_reference,"availableActions": available_actions,"amountAuthorized": {@@ -742,7 +691,6 @@ def test_creates_transaction_event_for_order_by_app("transaction_event": {"pspReference": event_psp_reference,"message": event_message,- "name": event_name,},}@@ -759,16 +707,14 @@ def test_creates_transaction_event_for_order_by_app(events_data = data["events"]assert len(events_data) == 1event_data = events_data[0]- assert event_data["message"] == event_message + " " + event_name- assert event_data["name"] == event_message + " " + event_name+ assert event_data["message"] == event_messageassert event_data["pspReference"] == event_psp_referenceassert event_data["externalUrl"] == ""assert event_data["createdBy"]["id"] == to_global_id_or_none(app_api_client.app)assert transaction.events.count() == 1event = transaction.events.first()- assert event.message == event_message + " " + event_name- assert event.status is None+ assert event.message == event_messageassert event.psp_reference == event_psp_referenceassert event.app_identifier == app_api_client.app.identifierassert event.app == app_api_client.app@@ -779,25 +725,22 @@ def test_creates_transaction_event_for_checkout_by_app(checkout_with_items, permission_manage_payments, app_api_client):# given- status = "Authorized for 10$"- type = "Credit Card"+ name = "Credit Card"psp_reference = "PSP reference - 123"available_actions = [TransactionActionEnum.CHARGE.name,- TransactionActionEnum.VOID.name,]authorized_value = Decimal("0")metadata = {"key": "test-1", "value": "123"}private_metadata = {"key": "test-2", "value": "321"}event_psp_reference = "PSP-ref"- event_name = "Failed authorization"+ event_message = "Failed authorization"variables = {"id": graphene.Node.to_global_id("Checkout", checkout_with_items.pk),"transaction": {- "status": status,- "type": type,+ "name": name,"pspReference": psp_reference,"availableActions": available_actions,"amountAuthorized": {@@ -809,7 +752,7 @@ def test_creates_transaction_event_for_checkout_by_app(},"transaction_event": {"pspReference": event_psp_reference,- "name": event_name,+ "message": event_message,},}@@ -826,14 +769,13 @@ def test_creates_transaction_event_for_checkout_by_app(events_data = data["events"]assert len(events_data) == 1event_data = events_data[0]- assert event_data["message"] == event_name- assert event_data["name"] == event_name+ assert event_data["message"] == event_messageassert event_data["pspReference"] == event_psp_referenceassert event_data["createdBy"]["id"] == to_global_id_or_none(app_api_client.app)assert transaction.events.count() == 1event = transaction.events.first()- assert event.message == event_name+ assert event.message == event_messageassert event.psp_reference == event_psp_referenceassert event.app_identifier == app_api_client.app.identifierassert event.app == app_api_client.app@@ -844,12 +786,10 @@ def test_transaction_create_for_order_by_staff(order_with_lines, permission_manage_payments, staff_api_client):# given- status = "Authorized for 10$"- type = "Credit Card"+ name = "Credit Card"psp_reference = "PSP reference - 123"available_actions = [TransactionActionEnum.CHARGE.name,- TransactionActionEnum.VOID.name,]authorized_value = Decimal("10")metadata = {"key": "test-1", "value": "123"}@@ -858,8 +798,7 @@ def test_transaction_create_for_order_by_staff(variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": status,- "type": type,+ "name": name,"pspReference": psp_reference,"availableActions": available_actions,"amountAuthorized": {@@ -881,13 +820,12 @@ def test_transaction_create_for_order_by_staff(content = get_graphql_content(response)data = content["data"]["transactionCreate"]["transaction"]assert data["actions"] == available_actions- assert data["status"] == status+assert data["pspReference"] == psp_referenceassert data["authorizedAmount"]["amount"] == authorized_valueassert data["createdBy"]["id"] == to_global_id_or_none(staff_api_client.user)assert available_actions == list(map(str.upper, transaction.available_actions))- assert status == transaction.statusassert psp_reference == transaction.psp_referenceassert authorized_value == transaction.authorized_valueassert transaction.metadata == {metadata["key"]: metadata["value"]}@@ -915,8 +853,7 @@ def test_transaction_create_for_order_updates_order_total_authorized_by_staff(variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": "Authorized for 10$",- "type": "Credit Card",+ "name": "Credit Card","pspReference": "PSP reference - 123","availableActions": [],"amountAuthorized": {@@ -961,8 +898,7 @@ def test_transaction_create_for_order_updates_order_total_charged_by_staff(variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": "Charged 10$",- "type": "Credit Card",+ "name": "Credit Card","pspReference": "PSP reference - 123","availableActions": [],"amountCharged": {@@ -996,12 +932,10 @@ def test_transaction_create_for_checkout_by_staff(checkout_with_items, permission_manage_payments, staff_api_client):# given- status = "Authorized for 10$"- type = "Credit Card"+ name = "Credit Card"psp_reference = "PSP reference - 123"available_actions = [TransactionActionEnum.CHARGE.name,- TransactionActionEnum.VOID.name,]authorized_value = Decimal("10")metadata = {"key": "test-1", "value": "123"}@@ -1010,8 +944,7 @@ def test_transaction_create_for_checkout_by_staff(variables = {"id": graphene.Node.to_global_id("Checkout", checkout_with_items.pk),"transaction": {- "status": status,- "type": type,+ "name": name,"pspReference": psp_reference,"availableActions": available_actions,"amountAuthorized": {@@ -1036,13 +969,12 @@ def test_transaction_create_for_checkout_by_staff(content = get_graphql_content(response)data = content["data"]["transactionCreate"]["transaction"]assert data["actions"] == available_actions- assert data["status"] == status+assert data["pspReference"] == psp_referenceassert data["authorizedAmount"]["amount"] == authorized_valueassert data["createdBy"]["id"] == to_global_id_or_none(staff_api_client.user)assert available_actions == list(map(str.upper, transaction.available_actions))- assert status == transaction.statusassert psp_reference == transaction.psp_referenceassert authorized_value == transaction.authorized_valueassert transaction.metadata == {metadata["key"]: metadata["value"]}@@ -1063,12 +995,10 @@ def test_transaction_create_for_checkout_fully_paid(plugins_manager,):# given- status = "Authorized for 10$"- type = "Credit Card"+ name = "Credit Card"psp_reference = "PSP reference - 123"available_actions = [TransactionActionEnum.CHARGE.name,- TransactionActionEnum.VOID.name,]metadata = {"key": "test-1", "value": "123"}private_metadata = {"key": "test-2", "value": "321"}@@ -1081,8 +1011,7 @@ def test_transaction_create_for_checkout_fully_paid(variables = {"id": graphene.Node.to_global_id("Checkout", checkout.pk),"transaction": {- "status": status,- "type": type,+ "name": name,"pspReference": psp_reference,"availableActions": available_actions,"amountCharged": {@@ -1112,7 +1041,6 @@ def test_transaction_create_for_checkout_fully_paid([("amountAuthorized", "authorized_value"),("amountCharged", "charged_value"),- ("amountVoided", "canceled_value"),("amountCanceled", "canceled_value"),("amountRefunded", "refunded_value"),],@@ -1125,16 +1053,14 @@ def test_transaction_create_calculate_amount_by_staff(staff_api_client,):# given- status = "Authorized for 10$"- type = "Credit Card"+ name = "Credit Card"psp_reference = "PSP reference - 123"expected_value = Decimal("10")variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": status,- "type": type,+ "name": name,"pspReference": psp_reference,"availableActions": [],amount_field_name: {@@ -1160,12 +1086,10 @@ def test_transaction_create_multiple_amounts_provided_by_staff(order_with_lines, permission_manage_payments, staff_api_client):# given- status = "Authorized for 10$"- type = "Credit Card"+ name = "Credit Card"psp_reference = "PSP reference - 123"available_actions = [TransactionActionEnum.CHARGE.name,- TransactionActionEnum.VOID.name,]authorized_value = Decimal("10")charged_value = Decimal("11")@@ -1175,8 +1099,7 @@ def test_transaction_create_multiple_amounts_provided_by_staff(variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": status,- "type": type,+ "name": name,"pspReference": psp_reference,"availableActions": available_actions,"amountAuthorized": {@@ -1191,7 +1114,7 @@ def test_transaction_create_multiple_amounts_provided_by_staff("amount": refunded_value,"currency": "USD",},- "amountVoided": {+ "amountCanceled": {"amount": canceled_value,"currency": "USD",},@@ -1208,12 +1131,11 @@ def test_transaction_create_multiple_amounts_provided_by_staff(content = get_graphql_content(response)data = content["data"]["transactionCreate"]["transaction"]assert data["actions"] == available_actions- assert data["status"] == status+assert data["pspReference"] == psp_referenceassert data["authorizedAmount"]["amount"] == authorized_valueassert data["chargedAmount"]["amount"] == charged_valueassert data["refundedAmount"]["amount"] == refunded_value- assert data["voidedAmount"]["amount"] == canceled_valueassert data["canceledAmount"]["amount"] == canceled_valueassert transaction.authorized_value == authorized_value@@ -1226,23 +1148,19 @@ def test_transaction_create_create_event_for_order_by_staff(order_with_lines, permission_manage_payments, staff_api_client):# given- status = "Authorized for 10$"- type = "Credit Card"+ name = "Credit Card"psp_reference = "PSP reference - 123"available_actions = [TransactionActionEnum.CHARGE.name,- TransactionActionEnum.VOID.name,]authorized_value = Decimal("10")- transaction_status = "PENDING"transaction_reference = "transaction reference"transaction_name = "Processing transaction"variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": status,- "type": type,+ "name": name,"pspReference": psp_reference,"availableActions": available_actions,"amountAuthorized": {@@ -1251,7 +1169,6 @@ def test_transaction_create_create_event_for_order_by_staff(},},"transaction_event": {- "status": transaction_status,"pspReference": transaction_reference,"message": transaction_name,},@@ -1269,7 +1186,6 @@ def test_transaction_create_create_event_for_order_by_staff(assert event.parameters == {"message": transaction_name,"reference": transaction_reference,- "status": transaction_status.lower(),}@@ -1277,12 +1193,10 @@ def test_transaction_create_missing_permission_by_staff(order_with_lines, staff_api_client):# given- status = "Authorized for 10$"- type = "Credit Card"+ name = "Credit Card"psp_reference = "PSP reference - 123"available_actions = [TransactionActionEnum.CHARGE.name,- TransactionActionEnum.VOID.name,]authorized_value = Decimal("10")metadata = {"key": "test-1", "value": "123"}@@ -1291,8 +1205,7 @@ def test_transaction_create_missing_permission_by_staff(variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": status,- "type": type,+ "name": name,"pspReference": psp_reference,"availableActions": available_actions,"amountAuthorized": {@@ -1316,7 +1229,6 @@ def test_transaction_create_missing_permission_by_staff([("amountAuthorized", "authorized_value"),("amountCharged", "charged_value"),- ("amountVoided", "canceled_value"),("amountCanceled", "canceled_value"),("amountRefunded", "refunded_value"),],@@ -1329,16 +1241,14 @@ def test_transaction_create_incorrect_currency_by_staff(staff_api_client,):# given- status = "Authorized for 10$"- type = "Credit Card"+ name = "Credit Card"psp_reference = "PSP reference - 123"expected_value = Decimal("10")variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": status,- "type": type,+ "name": name,"pspReference": psp_reference,"availableActions": [],amount_field_name: {@@ -1366,12 +1276,10 @@ def test_transaction_create_empty_metadata_key_by_staff(order_with_lines, permission_manage_payments, staff_api_client):# given- status = "Authorized for 10$"- type = "Credit Card"+ name = "Credit Card"psp_reference = "PSP reference - 123"available_actions = [TransactionActionEnum.CHARGE.name,- TransactionActionEnum.VOID.name,]authorized_value = Decimal("10")metadata = {"key": "", "value": "123"}@@ -1379,8 +1287,7 @@ def test_transaction_create_empty_metadata_key_by_staff(variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": status,- "type": type,+ "name": name,"pspReference": psp_reference,"availableActions": available_actions,"amountAuthorized": {@@ -1410,12 +1317,10 @@ def test_transaction_create_empty_private_metadata_key_by_staff(order_with_lines, permission_manage_payments, staff_api_client):# given- status = "Authorized for 10$"- type = "Credit Card"+ name = "Credit Card"psp_reference = "PSP reference - 123"available_actions = [TransactionActionEnum.CHARGE.name,- TransactionActionEnum.VOID.name,]authorized_value = Decimal("10")metadata = {"key": "test-1", "value": "123"}@@ -1423,8 +1328,7 @@ def test_transaction_create_empty_private_metadata_key_by_staff(variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": status,- "type": type,+ "name": name,"pspReference": psp_reference,"availableActions": available_actions,"amountAuthorized": {@@ -1454,22 +1358,19 @@ def test_creates_transaction_event_for_order_by_staff(order_with_lines, permission_manage_payments, staff_api_client):# given- status = "Failed authorized for 10$"- type = "Credit Card"+ name = "Credit Card"psp_reference = "PSP reference - 123"available_actions = []authorized_value = Decimal("0")metadata = {"key": "test-1", "value": "123"}private_metadata = {"key": "test-2", "value": "321"}- event_status = TransactionEventStatus.FAILUREevent_psp_reference = "PSP-ref"- event_name = "Failed authorization"+ event_message = "Failed authorization"variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": status,- "type": type,+ "name": name,"pspReference": psp_reference,"availableActions": available_actions,"amountAuthorized": {@@ -1480,9 +1381,8 @@ def test_creates_transaction_event_for_order_by_staff("privateMetadata": [private_metadata],},"transaction_event": {- "status": TransactionEventStatusEnum.FAILURE.name,"pspReference": event_psp_reference,- "message": event_name,+ "message": event_message,},}@@ -1499,17 +1399,14 @@ def test_creates_transaction_event_for_order_by_staff(events_data = data["events"]assert len(events_data) == 1event_data = events_data[0]- assert event_data["message"] == event_name- assert event_data["name"] == event_name- assert event_data["status"] == TransactionEventStatusEnum.FAILURE.name+ assert event_data["message"] == event_messageassert event_data["pspReference"] == event_psp_referenceassert event_data["createdBy"]["id"] == to_global_id_or_none(staff_api_client.user)assert event_data["type"] == TransactionEventTypeEnum.INFO.nameassert transaction.events.count() == 1event = transaction.events.first()- assert event.message == event_name- assert event.status == event_status+ assert event.message == event_messageassert event.psp_reference == event_psp_referenceassert event.user == staff_api_client.userassert event.app_identifier is None@@ -1521,26 +1418,22 @@ def test_creates_transaction_event_for_checkout_by_staff(checkout_with_items, permission_manage_payments, staff_api_client):# given- status = "Authorized for 10$"- type = "Credit Card"+ name = "Credit Card"psp_reference = "PSP reference - 123"available_actions = [TransactionActionEnum.CHARGE.name,- TransactionActionEnum.VOID.name,]authorized_value = Decimal("10")metadata = {"key": "test-1", "value": "123"}private_metadata = {"key": "test-2", "value": "321"}- event_status = TransactionEventStatus.SUCCESSevent_psp_reference = "PSP-ref"- event_name = "Failed authorization"+ event_message = "Failed authorization"variables = {"id": graphene.Node.to_global_id("Checkout", checkout_with_items.pk),"transaction": {- "status": status,- "type": type,+ "name": name,"pspReference": psp_reference,"availableActions": available_actions,"amountAuthorized": {@@ -1551,9 +1444,8 @@ def test_creates_transaction_event_for_checkout_by_staff("privateMetadata": [private_metadata],},"transaction_event": {- "status": TransactionEventStatusEnum.SUCCESS.name,"pspReference": event_psp_reference,- "message": event_name,+ "message": event_message,},}@@ -1572,9 +1464,7 @@ def test_creates_transaction_event_for_checkout_by_staff(event_data = [event for event in events_data if event["pspReference"] == event_psp_reference][0]- assert event_data["message"] == event_name- assert event_data["name"] == event_name- assert event_data["status"] == TransactionEventStatusEnum.SUCCESS.name+ assert event_data["message"] == event_messageassert event_data["pspReference"] == event_psp_referenceassert event_data["createdBy"]["id"] == to_global_id_or_none(staff_api_client.user)assert event_data["type"] == TransactionEventTypeEnum.INFO.name@@ -1583,8 +1473,7 @@ def test_creates_transaction_event_for_checkout_by_staff(event = transaction.events.exclude(type=TransactionEventType.AUTHORIZATION_SUCCESS).first()- assert event.message == event_name- assert event.status == event_status+ assert event.message == event_messageassert event.psp_reference == event_psp_referenceassert event.user == staff_api_client.userassert event.app_identifier is None@@ -1601,8 +1490,7 @@ def test_creates_transaction_automatically_confirm(order_with_lines.channel.automatically_confirm_all_new_orders = Trueorder_with_lines.channel.save()- status = "Failed authorized for 10$"- type = "Credit Card"+ name = "Credit Card"reference = "PSP reference - 123"available_actions = []authorized_value = Decimal("0")@@ -1610,13 +1498,12 @@ def test_creates_transaction_automatically_confirm(private_metadata = {"key": "test-2", "value": "321"}event_reference = "PSP-ref"- event_name = "Test"+ event_message = "Test"variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": status,- "type": type,- "reference": reference,+ "name": name,+ "pspReference": reference,"availableActions": available_actions,"amountAuthorized": {"amount": authorized_value,@@ -1626,9 +1513,8 @@ def test_creates_transaction_automatically_confirm("privateMetadata": [private_metadata],},"transaction_event": {- "status": TransactionEventStatusEnum.SUCCESS.name,- "reference": event_reference,- "name": event_name,+ "pspReference": event_reference,+ "message": event_message,},}@@ -1648,12 +1534,10 @@ def test_transaction_create_external_url_incorrect_url_format_by_app(order_with_lines, permission_manage_payments, app_api_client):# given- status = "Authorized for 10$"- type = "Credit Card"+ name = "Credit Card"psp_reference = "PSP reference - 123"available_actions = [TransactionActionEnum.CHARGE.name,- TransactionActionEnum.VOID.name,]authorized_value = Decimal("10")metadata = {"key": "test-1", "value": "123"}@@ -1662,8 +1546,7 @@ def test_transaction_create_external_url_incorrect_url_format_by_app(variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": status,- "type": type,+ "name": name,"pspReference": psp_reference,"availableActions": available_actions,"amountAuthorized": {@@ -1784,8 +1667,7 @@ def test_transaction_create_for_order_triggers_webhooks_when_fully_paid(variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": "Charged 10$",- "type": "Credit Card",+ "name": "Credit Card","pspReference": "PSP reference - 123","availableActions": [],"amountCharged": {@@ -1827,8 +1709,7 @@ def test_transaction_create_for_order_triggers_webhook_when_partially_paid(variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": "Charged 10$",- "type": "Credit Card",+ "name": "Credit Card","pspReference": "PSP reference - 123","availableActions": [],"amountCharged": {@@ -1868,8 +1749,7 @@ def test_transaction_create_for_order_triggers_webhook_when_authorized(variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": "Charged 10$",- "type": "Credit Card",+ "name": "Credit Card","pspReference": "PSP reference - 123","availableActions": [],"amountAuthorized": {@@ -1910,8 +1790,7 @@ def test_transaction_create_for_order_triggers_webhooks_when_fully_refunded(variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": "Charged 10$",- "type": "Credit Card",+ "name": "Credit Card","pspReference": "PSP reference - 123","availableActions": [],"amountRefunded": {@@ -1952,8 +1831,7 @@ def test_transaction_create_for_order_triggers_webhook_when_partially_refunded(variables = {"id": graphene.Node.to_global_id("Order", order_with_lines.pk),"transaction": {- "status": "Charged 10$",- "type": "Credit Card",+ "name": "Credit Card","pspReference": "PSP reference - 123","availableActions": [],"amountRefunded": {diff --git a/saleor/graphql/payment/tests/mutations/test_transaction_request_action.py b/saleor/graphql/payment/tests/mutations/test_transaction_request_action.pyindex 6d79ec3718..8aff1dfcdf 100644--- a/saleor/graphql/payment/tests/mutations/test_transaction_request_action.py+++ b/saleor/graphql/payment/tests/mutations/test_transaction_request_action.py@@ -28,20 +28,13 @@ mutation TransactionRequestAction(transaction{idactions- referencepspReference- type- statusmodifiedAtcreatedAtauthorizedAmount{amountcurrency}- voidedAmount{- currency- amount- }chargedAmount{currencyamount@@ -61,540 +54,22 @@ mutation TransactionRequestAction("""- "charge_amount, expected_called_charge_amount",- [- (Decimal("8.00"), Decimal("8.00")),- (None, Decimal("10.00")),- (Decimal("100"), Decimal("10.00")),- ],-)-@patch("saleor.plugins.manager.PluginsManager.is_event_active_for_any_plugin")-@patch("saleor.plugins.manager.PluginsManager.transaction_action_request")-def test_transaction_request_charge_action_for_order(- mocked_payment_action_request,- mocked_is_active,- charge_amount,- expected_called_charge_amount,- order_with_lines,- app_api_client,- permission_manage_payments,-):- # given- mocked_is_active.side_effect = [True, False]-- transaction = TransactionItem.objects.create(- status="Authorized",- name="Credit card",- psp_reference="PSP ref",- available_actions=["charge", "void"],- currency="USD",- order_id=order_with_lines.pk,- authorized_value=Decimal("10"),- )-- variables = {- "id": graphene.Node.to_global_id("TransactionItem", transaction.token),- "action_type": TransactionActionEnum.CHARGE.name,- "amount": charge_amount,- }-- # when- response = app_api_client.post_graphql(- MUTATION_TRANSACTION_REQUEST_ACTION,- variables,- permissions=[permission_manage_payments],- )-- # then- get_graphql_content(response)-- request_event = TransactionEvent.objects.filter(- type=TransactionEventType.CHARGE_REQUEST- ).first()-- assert mocked_is_active.called- assert request_event- mocked_payment_action_request.assert_called_once_with(- TransactionActionData(- transaction=transaction,- action_type=TransactionAction.CHARGE,- action_value=expected_called_charge_amount,- event=request_event,- transaction_app_owner=None,- ),- channel_slug=order_with_lines.channel.slug,- )-- event = order_with_lines.events.first()- assert event.type == OrderEvents.TRANSACTION_CHARGE_REQUESTED- assert Decimal(event.parameters["amount"]) == expected_called_charge_amount- assert event.parameters["reference"] == transaction.psp_reference-- assert TransactionEvent.objects.get(- transaction=transaction,- type=TransactionEventType.CHARGE_REQUEST,- amount_value=expected_called_charge_amount,- )--- "refund_amount, expected_called_refund_amount",- [- (Decimal("8.00"), Decimal("8.00")),- (None, Decimal("10.00")),- (Decimal("100"), Decimal("10.00")),- ],-)-@patch("saleor.plugins.manager.PluginsManager.is_event_active_for_any_plugin")-@patch("saleor.plugins.manager.PluginsManager.transaction_action_request")-def test_transaction_request_refund_action_for_order(- mocked_payment_action_request,- mocked_is_active,- refund_amount,- expected_called_refund_amount,- order_with_lines,- app_api_client,- permission_manage_payments,-):- # given- mocked_is_active.side_effect = [True, False]-- transaction = TransactionItem.objects.create(- status="Captured",- name="Credit card",- psp_reference="PSP ref",- available_actions=["refund"],- currency="USD",- order_id=order_with_lines.pk,- charged_value=Decimal("10"),- )-- variables = {- "id": graphene.Node.to_global_id("TransactionItem", transaction.token),- "action_type": TransactionActionEnum.REFUND.name,- "amount": refund_amount,- }-- # when- response = app_api_client.post_graphql(- MUTATION_TRANSACTION_REQUEST_ACTION,- variables,- permissions=[permission_manage_payments],- )-- # then- get_graphql_content(response)-- request_event = TransactionEvent.objects.filter(- type=TransactionEventType.REFUND_REQUEST,- ).first()-- assert request_event- assert mocked_is_active.called- mocked_payment_action_request.assert_called_once_with(- TransactionActionData(- transaction=transaction,- action_type=TransactionAction.REFUND,- action_value=expected_called_refund_amount,- event=request_event,- transaction_app_owner=None,- ),- channel_slug=order_with_lines.channel.slug,- )-- event = order_with_lines.events.first()- assert event.type == OrderEvents.TRANSACTION_REFUND_REQUESTED- assert Decimal(event.parameters["amount"]) == expected_called_refund_amount- assert event.parameters["reference"] == transaction.psp_reference-- assert TransactionEvent.objects.get(- transaction=transaction,- type=TransactionEventType.REFUND_REQUEST,- amount_value=expected_called_refund_amount,- )---@patch("saleor.plugins.manager.PluginsManager.is_event_active_for_any_plugin")-@patch("saleor.plugins.manager.PluginsManager.transaction_action_request")-def test_transaction_request_void_action_for_order(- mocked_payment_action_request,- mocked_is_active,- order_with_lines,- app_api_client,- permission_manage_payments,-):- # given- mocked_is_active.side_effect = [True, False]-- transaction = TransactionItem.objects.create(- status="Authorized",- name="Credit card",- psp_reference="PSP ref",- available_actions=["charge", "void"],- currency="USD",- order_id=order_with_lines.pk,- authorized_value=Decimal("10"),- )- variables = {- "id": graphene.Node.to_global_id("TransactionItem", transaction.token),- "action_type": TransactionActionEnum.VOID.name,- }-- # when- response = app_api_client.post_graphql(- MUTATION_TRANSACTION_REQUEST_ACTION,- variables,- permissions=[permission_manage_payments],- )-- # then- get_graphql_content(response)-- request_event = TransactionEvent.objects.filter(- type=TransactionEventType.CANCEL_REQUEST,- ).first()- assert request_event- assert mocked_is_active.called- mocked_payment_action_request.assert_called_once_with(- TransactionActionData(- transaction=transaction,- action_type=TransactionAction.VOID,- action_value=None,- event=request_event,- transaction_app_owner=None,- ),- channel_slug=order_with_lines.channel.slug,- )-- event = order_with_lines.events.first()- assert event.type == OrderEvents.TRANSACTION_CANCEL_REQUESTED- assert event.parameters["reference"] == transaction.psp_reference-- assert TransactionEvent.objects.get(- transaction=transaction,- type=TransactionEventType.CANCEL_REQUEST,- amount_value=0,- )---@patch("saleor.plugins.manager.PluginsManager.is_event_active_for_any_plugin")-@patch("saleor.plugins.manager.PluginsManager.transaction_action_request")-def test_transaction_request_void_action_for_order_by_user_no_channel_access(- mocked_payment_action_request,- mocked_is_active,- order_with_lines,- staff_api_client,- permission_group_all_perms_channel_USD_only,- channel_PLN,-):- # given- permission_group_all_perms_channel_USD_only.user_set.add(staff_api_client.user)- mocked_is_active.return_value = True-- order_with_lines.channel = channel_PLN- order_with_lines.save(update_fields=["channel"])-- transaction = TransactionItem.objects.create(- status="Authorized",- psp_reference="PSP ref",- available_actions=["charge", "void"],- currency="USD",- order_id=order_with_lines.pk,- authorized_value=Decimal("10"),- )- variables = {- "id": graphene.Node.to_global_id("TransactionItem", transaction.token),- "action_type": TransactionActionEnum.VOID.name,- }-- # when- response = staff_api_client.post_graphql(- MUTATION_TRANSACTION_REQUEST_ACTION,- variables,- )-- # then- assert_no_permission(response)---@patch("saleor.plugins.manager.PluginsManager.is_event_active_for_any_plugin")-@patch("saleor.plugins.manager.PluginsManager.transaction_action_request")-def test_transaction_request_void_action_for_checkout(- mocked_payment_action_request,- mocked_is_active,- checkout,- app_api_client,- permission_manage_payments,-):- # given- mocked_is_active.side_effect = [True, False]-- transaction = TransactionItem.objects.create(- status="Authorized",- name="Credit card",- psp_reference="PSP ref",- available_actions=["charge", "void"],- currency="USD",- checkout_id=checkout.pk,- authorized_value=Decimal("10"),- )- variables = {- "id": graphene.Node.to_global_id("TransactionItem", transaction.token),- "action_type": TransactionActionEnum.VOID.name,- }-- # when- response = app_api_client.post_graphql(- MUTATION_TRANSACTION_REQUEST_ACTION,- variables,- permissions=[permission_manage_payments],- )-- # then- get_graphql_content(response)-- request_event = TransactionEvent.objects.filter(- type=TransactionEventType.CANCEL_REQUEST,- ).first()-- assert request_event- assert mocked_is_active.called- mocked_payment_action_request.assert_called_once_with(- TransactionActionData(- transaction=transaction,- action_type=TransactionAction.VOID,- action_value=None,- event=request_event,- transaction_app_owner=None,- ),- channel_slug=checkout.channel.slug,- )-- assert TransactionEvent.objects.get(- transaction=transaction,- type=TransactionEventType.CANCEL_REQUEST,- amount_value=0,- )--- "charge_amount, expected_called_charge_amount",- [- (Decimal("8.00"), Decimal("8.00")),- (None, Decimal("10.00")),- (Decimal("100"), Decimal("10.00")),- ],-)-@patch("saleor.plugins.manager.PluginsManager.is_event_active_for_any_plugin")-@patch("saleor.plugins.manager.PluginsManager.transaction_action_request")-def test_transaction_request_charge_action_for_checkout(- mocked_payment_action_request,- mocked_is_active,- charge_amount,- expected_called_charge_amount,- checkout,- app_api_client,- permission_manage_payments,-):- # given- mocked_is_active.side_effect = [True, False]-- transaction = TransactionItem.objects.create(- status="Authorized",- name="Credit card",- psp_reference="PSP ref",- available_actions=["charge", "void"],- currency="USD",- checkout_id=checkout.pk,- authorized_value=Decimal("10"),- )-- variables = {- "id": graphene.Node.to_global_id("TransactionItem", transaction.token),- "action_type": TransactionActionEnum.CHARGE.name,- "amount": charge_amount,- }-- # when- response = app_api_client.post_graphql(- MUTATION_TRANSACTION_REQUEST_ACTION,- variables,- permissions=[permission_manage_payments],- )-- # then- get_graphql_content(response)-- request_event = TransactionEvent.objects.filter(- type=TransactionEventType.CHARGE_REQUEST- ).first()-- assert request_event- assert mocked_is_active.called- mocked_payment_action_request.assert_called_once_with(- TransactionActionData(- transaction=transaction,- action_type=TransactionAction.CHARGE,- action_value=expected_called_charge_amount,- event=request_event,- transaction_app_owner=None,- ),- channel_slug=checkout.channel.slug,- )-- assert TransactionEvent.objects.get(- transaction=transaction,- type=TransactionEventType.CHARGE_REQUEST,- amount_value=expected_called_charge_amount,- )--- "refund_amount, expected_called_refund_amount",- [- (Decimal("8.00"), Decimal("8.00")),- (None, Decimal("10.00")),- (Decimal("100"), Decimal("10.00")),- ],-)-@patch("saleor.plugins.manager.PluginsManager.is_event_active_for_any_plugin")-@patch("saleor.plugins.manager.PluginsManager.transaction_action_request")-def test_transaction_request_refund_action_for_checkout(- mocked_payment_action_request,- mocked_is_active,- refund_amount,- expected_called_refund_amount,- checkout,- app_api_client,- permission_manage_payments,-):- # given- mocked_is_active.side_effect = [True, False]-- transaction = TransactionItem.objects.create(- status="Captured",- name="Credit card",- psp_reference="PSP ref",- available_actions=["refund"],- currency="USD",- checkout_id=checkout.pk,- charged_value=Decimal("10"),- )-- variables = {- "id": graphene.Node.to_global_id("TransactionItem", transaction.token),- "action_type": TransactionActionEnum.REFUND.name,- "amount": refund_amount,- }-- # when- response = app_api_client.post_graphql(- MUTATION_TRANSACTION_REQUEST_ACTION,- variables,- permissions=[permission_manage_payments],- )-- # then- get_graphql_content(response)-- request_event = TransactionEvent.objects.filter(- type=TransactionEventType.REFUND_REQUEST,- ).first()-- assert request_event- assert mocked_is_active.called- mocked_payment_action_request.assert_called_once_with(- TransactionActionData(- transaction=transaction,- action_type=TransactionAction.REFUND,- action_value=expected_called_refund_amount,- event=request_event,- transaction_app_owner=None,- ),- channel_slug=checkout.channel.slug,- )-- assert TransactionEvent.objects.get(- transaction=transaction,- type=TransactionEventType.REFUND_REQUEST,- amount_value=expected_called_refund_amount,- )---@patch("saleor.plugins.manager.PluginsManager.is_event_active_for_any_plugin")-@patch("saleor.plugins.manager.PluginsManager.transaction_action_request")-def test_transaction_action_request_uses_handle_payment_permission(- mocked_payment_action_request,- mocked_is_active,- checkout,- app_api_client,- permission_manage_payments,-):- # given- mocked_is_active.side_effect = [True, False]-- transaction = TransactionItem.objects.create(- status="Captured",- name="Credit card",- psp_reference="PSP ref",- available_actions=["refund"],- currency="USD",- checkout_id=checkout.pk,- charged_value=Decimal("10"),- )- refund_amount = Decimal("1")- variables = {- "id": graphene.Node.to_global_id("TransactionItem", transaction.token),- "action_type": TransactionActionEnum.REFUND.name,- "amount": refund_amount,- }-- # when- response = app_api_client.post_graphql(- MUTATION_TRANSACTION_REQUEST_ACTION,- variables,- permissions=[permission_manage_payments],- )-- # then- get_graphql_content(response)-- request_event = TransactionEvent.objects.filter(- type=TransactionEventType.REFUND_REQUEST,- ).first()-- assert request_event- assert mocked_is_active.called- mocked_payment_action_request.assert_called_once_with(- TransactionActionData(- transaction=transaction,- action_type=TransactionAction.REFUND,- action_value=refund_amount,- event=request_event,- transaction_app_owner=None,- ),- channel_slug=checkout.channel.slug,- )--def test_transaction_request_action_missing_permission(app_api_client, order_with_lines, permission_manage_orders):# giventransaction = TransactionItem.objects.create(- status="Authorized",name="Credit card",psp_reference="PSP ref",- available_actions=["charge", "void"],+ available_actions=["charge", "cancel"],currency="USD",order_id=order_with_lines.pk,authorized_value=Decimal("10"),)variables = {"id": graphene.Node.to_global_id("TransactionItem", transaction.token),- "action_type": TransactionActionEnum.VOID.name,+ "action_type": TransactionActionEnum.CANCEL.name,}# when@@ -621,10 +96,9 @@ def test_transaction_request_action_missing_event(permission_group_manage_orders.user_set.add(staff_api_client.user)authorization_value = Decimal("10")transaction = TransactionItem.objects.create(- status="Authorized",name="Credit card",psp_reference="PSP ref",- available_actions=["charge", "void"],+ available_actions=["charge", "cancel"],currency="USD",order_id=order.pk,authorized_value=authorization_value,@@ -633,7 +107,7 @@ def test_transaction_request_action_missing_event(variables = {"id": graphene.Node.to_global_id("TransactionItem", transaction.token),- "action_type": TransactionActionEnum.VOID.name,+ "action_type": TransactionActionEnum.CANCEL.name,}permission_group_no_perms_all_channels.user_set.add(staff_api_client.user)@@ -702,10 +176,9 @@ def test_transaction_request_charge_for_order(mocked_is_active.return_value = Falsetransaction = TransactionItem.objects.create(- status="Authorized",name="Credit card",psp_reference="PSP ref",- available_actions=["charge", "void"],+ available_actions=["charge", "cancel"],currency="USD",order_id=order_with_lines.pk,authorized_value=Decimal("10"),@@ -786,7 +259,6 @@ def test_transaction_request_refund_for_order()transaction = TransactionItem.objects.create(- status="Captured",name="Credit card",psp_reference="PSP ref",available_actions=["refund"],@@ -858,10 +330,9 @@ def test_transaction_request_cancelation_for_order()transaction = TransactionItem.objects.create(- status="Authorized",name="Credit card",psp_reference="PSP ref",- available_actions=["charge", "void"],+ available_actions=["charge", "cancel"],currency="USD",order_id=order_with_lines.pk,authorized_value=Decimal("10"),@@ -870,7 +341,7 @@ def test_transaction_request_cancelation_for_order()variables = {"id": graphene.Node.to_global_id("TransactionItem", transaction.token),- "action_type": TransactionActionEnum.VOID.name,+ "action_type": TransactionActionEnum.CANCEL.name,}# when@@ -929,10 +400,9 @@ def test_transaction_request_cancelation_for_checkout()transaction = TransactionItem.objects.create(- status="Authorized",name="Credit card",psp_reference="PSP ref",- available_actions=["charge", "void"],+ available_actions=["charge", "cancel"],currency="USD",checkout_id=checkout.pk,authorized_value=Decimal("10"),@@ -941,7 +411,7 @@ def test_transaction_request_cancelation_for_checkout()variables = {"id": graphene.Node.to_global_id("TransactionItem", transaction.token),- "action_type": TransactionActionEnum.VOID.name,+ "action_type": TransactionActionEnum.CANCEL.name,}# when@@ -1006,10 +476,9 @@ def test_transaction_request_charge_for_checkout()transaction = TransactionItem.objects.create(- status="Authorized",name="Credit card",psp_reference="PSP ref",- available_actions=["charge", "void"],+ available_actions=["charge", "cancel"],currency="USD",checkout_id=checkout.pk,authorized_value=Decimal("10"),@@ -1084,7 +553,6 @@ def test_transaction_request_refund_for_checkout()transaction = TransactionItem.objects.create(- status="Captured",name="Credit card",psp_reference="PSP ref",available_actions=["refund"],@@ -1154,7 +622,6 @@ def test_transaction_request_refund_when_app_reinstalled()transaction = TransactionItem.objects.create(- status="Captured",name="Credit card",psp_reference="PSP ref",available_actions=["refund"],@@ -1222,7 +689,6 @@ def test_transaction_request_uses_handle_payment_permission()transaction = TransactionItem.objects.create(- status="Captured",name="Credit card",psp_reference="PSP ref",available_actions=["refund"],@@ -1277,10 +743,9 @@ def test_transaction_request_missing_permission()transaction = TransactionItem.objects.create(- status="Authorized",name="Credit card",psp_reference="PSP ref",- available_actions=["charge", "void"],+ available_actions=["charge", "cancel"],currency="USD",order_id=order_with_lines.pk,authorized_value=Decimal("10"),@@ -1289,7 +754,7 @@ def test_transaction_request_missing_permission()variables = {"id": graphene.Node.to_global_id("TransactionItem", transaction.token),- "action_type": TransactionActionEnum.VOID.name,+ "action_type": TransactionActionEnum.CANCEL.name,}# when@@ -1315,10 +780,9 @@ def test_transaction_request_missing_event(# givenauthorization_value = Decimal("10")transaction = TransactionItem.objects.create(- status="Authorized",name="Credit card",psp_reference="PSP ref",- available_actions=["charge", "void"],+ available_actions=["charge", "cancel"],currency="USD",order_id=order.pk,authorized_value=authorization_value,@@ -1331,7 +795,7 @@ def test_transaction_request_missing_event(variables = {"id": graphene.Node.to_global_id("TransactionItem", transaction.token),- "action_type": TransactionActionEnum.VOID.name,+ "action_type": TransactionActionEnum.CANCEL.name,}permission_group_no_perms_all_channels.user_set.add(staff_api_client.user)diff --git a/saleor/graphql/payment/tests/mutations/test_transaction_update.py b/saleor/graphql/payment/tests/mutations/test_transaction_update.pyindex 99b543ec67..8242dfcd85 100644--- a/saleor/graphql/payment/tests/mutations/test_transaction_update.py+++ b/saleor/graphql/payment/tests/mutations/test_transaction_update.py@@ -8,13 +8,13 @@ from .....checkout import CheckoutAuthorizeStatus, CheckoutChargeStatusfrom .....checkout.calculations import fetch_checkout_datafrom .....checkout.fetch import fetch_checkout_info, fetch_checkout_linesfrom .....order import OrderAuthorizeStatus, OrderChargeStatus, OrderEvents-from .....payment import TransactionEventStatus, TransactionEventType+from .....payment import TransactionEventTypefrom .....payment.error_codes import TransactionUpdateErrorCodefrom .....payment.models import TransactionEvent, TransactionItemfrom .....payment.transaction_item_calculations import recalculate_transaction_amountsfrom ....core.utils import to_global_id_or_nonefrom ....tests.utils import assert_no_permission, get_graphql_content-from ...enums import TransactionActionEnum, TransactionEventStatusEnum+from ...enums import TransactionActionEnumTEST_SERVER_DOMAIN = "testserver.com"@@ -33,10 +33,8 @@ mutation TransactionUpdate(idactionspspReference- typenamemessage- statusmodifiedAtcreatedAtexternalUrl@@ -44,10 +42,6 @@ mutation TransactionUpdate(amountcurrency}- voidedAmount{- currency- amount- }canceledAmount{currencyamount@@ -77,9 +71,7 @@ mutation TransactionUpdate(}}events{- statuspspReference- namemessagecreatedAtexternalUrl@@ -120,12 +112,12 @@ def test_only_owner_can_update_its_transaction_by_app(transaction.app_identifier = external_app.identifiertransaction.save()- status = "Captured for 10$"+ message = "Captured for 10$"variables = {"id": graphene.Node.to_global_id("TransactionItem", transaction.token),"transaction": {- "status": status,+ "message": message,},}# when@@ -137,33 +129,6 @@ def test_only_owner_can_update_its_transaction_by_app(assert_no_permission(response)-def test_transaction_update_status_by_app(- transaction_item_created_by_app, permission_manage_payments, app_api_client-):- # given- transaction = transaction_item_created_by_app- status = "Captured for 10$"-- variables = {- "id": graphene.Node.to_global_id("TransactionItem", transaction.token),- "transaction": {- "status": status,- },- }-- # when- response = app_api_client.post_graphql(- MUTATION_TRANSACTION_UPDATE, variables, permissions=[permission_manage_payments]- )-- # then- transaction.refresh_from_db()- content = get_graphql_content(response)- data = content["data"]["transactionUpdate"]["transaction"]- assert data["status"] == status- assert transaction_item_created_by_app.status == status--def test_transaction_update_metadata_by_app(transaction_item_created_by_app, permission_manage_payments, app_api_client):@@ -282,34 +247,6 @@ def test_transaction_update_private_metadata_incorrect_key_by_app(assert error["code"] == TransactionUpdateErrorCode.METADATA_KEY_REQUIRED.name-def test_transaction_update_type_by_app(- transaction_item_created_by_app, permission_manage_payments, app_api_client-):- # given- transaction = transaction_item_created_by_app- type = "New credit card"-- variables = {- "id": graphene.Node.to_global_id("TransactionItem", transaction.token),- "transaction": {- "type": type,- },- }-- # when- response = app_api_client.post_graphql(- MUTATION_TRANSACTION_UPDATE, variables, permissions=[permission_manage_payments]- )-- # then- transaction.refresh_from_db()- content = get_graphql_content(response)- data = content["data"]["transactionUpdate"]["transaction"]- assert data["type"] == type- assert data["name"] == type- assert transaction.name == type--def test_transaction_update_name_by_app(transaction_item_created_by_app, permission_manage_payments, app_api_client):@@ -334,7 +271,6 @@ def test_transaction_update_name_by_app(content = get_graphql_content(response)data = content["data"]["transactionUpdate"]["transaction"]assert data["name"] == name- assert data["type"] == nameassert transaction.name == name@@ -427,7 +363,6 @@ def test_transaction_update_available_actions_by_app(("amountAuthorized", "authorizedAmount", "authorized_value", Decimal("12")),("amountCharged", "chargedAmount", "charged_value", Decimal("13")),("amountCanceled", "canceledAmount", "canceled_value", Decimal("14")),- ("amountVoided", "voidedAmount", "canceled_value", Decimal("14")),("amountRefunded", "refundedAmount", "refunded_value", Decimal("15")),],)@@ -847,7 +782,6 @@ def test_transaction_update_multiple_amounts_provided_by_app(assert data["authorizedAmount"]["amount"] == authorized_valueassert data["chargedAmount"]["amount"] == charged_valueassert data["refundedAmount"]["amount"] == refunded_value- assert data["voidedAmount"]["amount"] == canceled_valueassert data["canceledAmount"]["amount"] == canceled_valueassert transaction@@ -862,14 +796,14 @@ def test_transaction_update_for_order_missing_permission_by_app():# giventransaction = transaction_item_created_by_app- status = "Authorized for 10$"- type = "Credit Card"+ message = "Authorized for 10$"+ name = "Credit Card"variables = {"id": graphene.Node.to_global_id("TransactionItem", transaction.token),"transaction": {- "status": status,- "type": type,+ "message": message,+ "name": name,},}@@ -885,7 +819,6 @@ def test_transaction_update_for_order_missing_permission_by_app([("amountAuthorized", "authorized_value"),("amountCharged", "charged_value"),- ("amountVoided", "canceled_value"),("amountCanceled", "canceled_value"),("amountRefunded", "refunded_value"),],@@ -933,14 +866,12 @@ def test_transaction_update_adds_transaction_event_to_order_by_app():# giventransaction = transaction_item_created_by_app- transaction_status = "PENDING"transaction_reference = "transaction reference"transaction_name = "Processing transaction"variables = {"id": graphene.Node.to_global_id("TransactionItem", transaction.token),"transaction_event": {- "status": transaction_status,"pspReference": transaction_reference,"message": transaction_name,},@@ -960,7 +891,6 @@ def test_transaction_update_adds_transaction_event_to_order_by_app(assert event.parameters == {"message": transaction_name,"reference": transaction_reference,- "status": transaction_status.lower(),}@@ -973,15 +903,13 @@ def test_creates_transaction_event_for_order_by_app(# giventransaction = order_with_lines.payment_transactions.first()- event_status = TransactionEventStatus.FAILUREevent_reference = "PSP-ref"- event_name = "Failed authorization"+ event_message = "Failed authorization"variables = {"id": graphene.Node.to_global_id("TransactionItem", transaction.token),"transaction_event": {- "status": TransactionEventStatusEnum.FAILURE.name,"pspReference": event_reference,- "message": event_name,+ "message": event_message,},}@@ -999,15 +927,12 @@ def test_creates_transaction_event_for_order_by_app(event_data = [event for event in events_data if event["pspReference"] == event_reference][0]- assert event_data["message"] == event_name- assert event_data["name"] == event_name- assert event_data["status"] == TransactionEventStatusEnum.FAILURE.name+ assert event_data["message"] == event_messageassert event_data["createdBy"]["id"] == to_global_id_or_none(app_api_client.app)assert transaction.events.count() == 2event = transaction.events.filter(psp_reference=event_reference).first()- assert event.message == event_name- assert event.status == event_status+ assert event.message == event_messageassert event.app_identifier == app_api_client.app.identifierassert event.user is None@@ -1023,15 +948,13 @@ def test_creates_transaction_event_by_reinstalled_app(transaction_item_created_by_app.save()transaction = order_with_lines.payment_transactions.first()- event_status = TransactionEventStatus.FAILUREevent_reference = "PSP-ref"- event_name = "Failed authorization"+ event_message = "Failed authorization"variables = {"id": graphene.Node.to_global_id("TransactionItem", transaction.token),"transaction_event": {- "status": TransactionEventStatusEnum.FAILURE.name,"pspReference": event_reference,- "message": event_name,+ "message": event_message,},}@@ -1045,8 +968,7 @@ def test_creates_transaction_event_by_reinstalled_app(assert transaction.events.count() == 2event = transaction.events.filter(psp_reference=event_reference).first()- assert event.message == event_name- assert event.status == event_status+ assert event.message == event_messageassert event.app_identifier == app_api_client.app.identifierassert event.user is None@@ -1059,12 +981,12 @@ def test_only_app_owner_can_update_its_transaction_by_staff(# giventransaction = transaction_item_created_by_app- status = "Captured for 10$"+ message = "Captured for 10$"variables = {"id": graphene.Node.to_global_id("TransactionItem", transaction.token),"transaction": {- "status": status,+ "message": message,},}# when@@ -1076,33 +998,6 @@ def test_only_app_owner_can_update_its_transaction_by_staff(assert_no_permission(response)-def test_transaction_update_status_by_staff(- transaction_item_created_by_user, permission_manage_payments, staff_api_client-):- # given- transaction = transaction_item_created_by_user- status = "Captured for 10$"-- variables = {- "id": graphene.Node.to_global_id("TransactionItem", transaction.token),- "transaction": {- "status": status,- },- }-- # when- response = staff_api_client.post_graphql(- MUTATION_TRANSACTION_UPDATE, variables, permissions=[permission_manage_payments]- )-- # then- transaction.refresh_from_db()- content = get_graphql_content(response)- data = content["data"]["transactionUpdate"]["transaction"]- assert data["status"] == status- assert transaction_item_created_by_user.status == status--def test_transaction_update_by_another_staff(transaction_item_created_by_user,permission_manage_payments,@@ -1114,12 +1009,12 @@ def test_transaction_update_by_another_staff(transaction.user = admin_usertransaction.save()- status = "Captured for 10$"+ message = "Captured for 10$"variables = {"id": graphene.Node.to_global_id("TransactionItem", transaction.token),"transaction": {- "status": status,+ "message": message,},}@@ -1258,34 +1153,6 @@ def test_transaction_update_private_metadata_incorrect_key_by_staff(assert error["code"] == TransactionUpdateErrorCode.METADATA_KEY_REQUIRED.name-def test_transaction_update_type_by_staff(- transaction_item_created_by_user, permission_manage_payments, staff_api_client-):- # given- transaction = transaction_item_created_by_user- type = "New credit card"-- variables = {- "id": graphene.Node.to_global_id("TransactionItem", transaction.token),- "transaction": {- "type": type,- },- }-- # when- response = staff_api_client.post_graphql(- MUTATION_TRANSACTION_UPDATE, variables, permissions=[permission_manage_payments]- )-- # then- transaction.refresh_from_db()- content = get_graphql_content(response)- data = content["data"]["transactionUpdate"]["transaction"]- assert data["type"] == type- assert data["name"] == type- assert transaction.name == type--def test_transaction_update_name_by_staff(transaction_item_created_by_user, permission_manage_payments, staff_api_client):@@ -1309,7 +1176,6 @@ def test_transaction_update_name_by_staff(transaction.refresh_from_db()content = get_graphql_content(response)data = content["data"]["transactionUpdate"]["transaction"]- assert data["type"] == nameassert data["name"] == nameassert transaction.name == name@@ -1400,7 +1266,6 @@ def test_transaction_update_available_actions_by_staff([("amountAuthorized", "authorizedAmount", "authorized_value", Decimal("12")),("amountCharged", "chargedAmount", "charged_value", Decimal("13")),- ("amountVoided", "voidedAmount", "canceled_value", Decimal("14")),("amountCanceled", "canceledAmount", "canceled_value", Decimal("14")),("amountRefunded", "refundedAmount", "refunded_value", Decimal("15")),],@@ -1777,7 +1642,6 @@ def test_transaction_update_multiple_amounts_provided_by_staff(assert data["authorizedAmount"]["amount"] == authorized_valueassert data["chargedAmount"]["amount"] == charged_valueassert data["refundedAmount"]["amount"] == refunded_value- assert data["voidedAmount"]["amount"] == canceled_valueassert data["canceledAmount"]["amount"] == canceled_valueassert transaction@@ -1792,14 +1656,14 @@ def test_transaction_update_for_order_missing_permission_by_staff():# giventransaction = transaction_item_created_by_user- status = "Authorized for 10$"- type = "Credit Card"+ message = "Authorized for 10$"+ name = "Credit Card"variables = {"id": graphene.Node.to_global_id("TransactionItem", transaction.token),"transaction": {- "status": status,- "type": type,+ "message": message,+ "name": name,},}@@ -1815,7 +1679,6 @@ def test_transaction_update_for_order_missing_permission_by_staff([("amountAuthorized", "authorized_value"),("amountCharged", "charged_value"),- ("amountVoided", "canceled_value"),("amountCanceled", "canceled_value"),("amountRefunded", "refunded_value"),],@@ -1863,14 +1726,12 @@ def test_transaction_update_adds_transaction_event_to_order_by_staff():# giventransaction = transaction_item_created_by_user- transaction_status = "PENDING"transaction_reference = "transaction reference"transaction_name = "Processing transaction"variables = {"id": graphene.Node.to_global_id("TransactionItem", transaction.token),"transaction_event": {- "status": transaction_status,"pspReference": transaction_reference,"message": transaction_name,},@@ -1890,7 +1751,6 @@ def test_transaction_update_adds_transaction_event_to_order_by_staff(assert event.parameters == {"message": transaction_name,"reference": transaction_reference,- "status": transaction_status.lower(),}@@ -1903,15 +1763,13 @@ def test_creates_transaction_event_for_order_by_staff(# giventransaction = order_with_lines.payment_transactions.first()- event_status = TransactionEventStatus.FAILUREevent_reference = "PSP-ref"- event_name = "Failed authorization"+ event_message = "Failed authorization"variables = {"id": graphene.Node.to_global_id("TransactionItem", transaction.token),"transaction_event": {- "status": TransactionEventStatusEnum.FAILURE.name,"pspReference": event_reference,- "name": event_name,+ "message": event_message,},}@@ -1929,15 +1787,12 @@ def test_creates_transaction_event_for_order_by_staff(event_data = [event for event in events_data if event["pspReference"] == event_reference][0]- assert event_data["message"] == event_name- assert event_data["name"] == event_name- assert event_data["status"] == TransactionEventStatusEnum.FAILURE.name+ assert event_data["message"] == event_messageassert event_data["createdBy"]["id"] == to_global_id_or_none(staff_api_client.user)assert transaction.events.count() == 2event = transaction.events.filter(psp_reference=event_reference).first()- assert event.message == event_name- assert event.status == event_status+ assert event.message == event_messageassert event.psp_reference == event_referenceassert event.app_identifier is Noneassert event.user == staff_api_client.user@@ -2399,16 +2254,6 @@ def test_transaction_update_creates_calculation_event(Decimal("3"),Decimal("4"),),- (- "amountVoided",- "voidedAmount",- "canceled_value",- Decimal("14"),- Decimal("1"),- Decimal("2"),- Decimal("3"),- Decimal("4"),- ),("amountRefunded","refundedAmount",@@ -2625,12 +2470,12 @@ def test_transaction_update_accepts_old_id_for_old_transaction():# giventransaction = transaction_item_generator(use_old_id=True)- status = "Captured for 10$"+ message = "Captured for 10$"variables = {"id": graphene.Node.to_global_id("TransactionItem", transaction.pk),"transaction": {- "status": status,+ "message": message,},}@@ -2643,8 +2488,8 @@ def test_transaction_update_accepts_old_id_for_old_transaction(transaction.refresh_from_db()content = get_graphql_content(response)data = content["data"]["transactionUpdate"]["transaction"]- assert data["status"] == status- assert transaction.status == status+ assert data["message"] == message+ assert transaction.message == messagedef test_transaction_update_doesnt_accept_old_id_for_new_transactions(@@ -2652,12 +2497,12 @@ def test_transaction_update_doesnt_accept_old_id_for_new_transactions():# giventransaction = transaction_item_generator(use_old_id=False)- status = "Captured for 10$"+ message = "Captured for 10$"variables = {"id": graphene.Node.to_global_id("TransactionItem", transaction.pk),"transaction": {- "status": status,+ "message": message,},}@@ -2917,12 +2762,12 @@ def test_transaction_update_by_app_assign_app_owner():# giventransaction = transaction_item_generator()- status = "Captured for 10$"+ name = "Captured for 10$"variables = {"id": graphene.Node.to_global_id("TransactionItem", transaction.token),"transaction": {- "status": status,+ "name": name,},}diff --git a/saleor/graphql/payment/tests/queries/test_transaction.py b/saleor/graphql/payment/tests/queries/test_transaction.pyindex 413ae7add4..1452fa9fb2 100644--- a/saleor/graphql/payment/tests/queries/test_transaction.py+++ b/saleor/graphql/payment/tests/queries/test_transaction.py@@ -3,7 +3,7 @@ from decimal import Decimalimport grapheneimport pytest-from .....payment import TransactionEventStatus, TransactionEventType+from .....payment import TransactionEventTypefrom .....payment.models import TransactionEventfrom ....core.utils import to_global_id_or_nonefrom ....tests.utils import assert_no_permission, get_graphql_content@@ -28,10 +28,6 @@ TRANSACTION_QUERY = """currencyamount}- voidedAmount{- currency- amount- }chargedAmount{currencyamount@@ -55,9 +51,7 @@ TRANSACTION_QUERY = """events{idcreatedAt- statuspspReference- namemessageexternalUrlamount{@@ -74,11 +68,9 @@ TRANSACTION_QUERY = """}}}- status- typenamemessage- reference+ pspReferenceorder {id}@@ -108,14 +100,11 @@ def _assert_transaction_fields(content, transaction_item, event):data["authorizedAmount"]["amount"] == transaction_item.amount_authorized.amount)assert data["refundedAmount"]["amount"] == transaction_item.amount_refunded.amount- assert data["voidedAmount"]["amount"] == transaction_item.amount_canceled.amountassert data["canceledAmount"]["amount"] == transaction_item.amount_canceled.amountassert data["chargedAmount"]["amount"] == transaction_item.amount_charged.amountevents_data = [e for e in data["events"] if e["type"] == event.type.upper()]assert len(events_data) == 1assert events_data[0]["id"] == to_global_id_or_none(event)- assert data["status"] == transaction_item.status- assert data["type"] == transaction_item.nameassert data["name"] == transaction_item.nameassert data["message"] == transaction_item.messageif transaction_item.order_id:@@ -531,9 +520,7 @@ def test_transaction_event_by_user(]assert event_data["id"] == to_global_id_or_none(event)assert event_data["createdAt"] == event.created_at.isoformat()- assert event_data["status"] == event.status.upper()assert event_data["pspReference"] == event.psp_reference- assert event_data["name"] == event.messageassert event_data["message"] == event.messageassert event_data["externalUrl"] == event.external_urlassert event_data["amount"]["amount"] == event.amount_value@@ -552,7 +539,6 @@ def test_transaction_event_by_app(psp_reference = "psp-ref-123"event = TransactionEvent.objects.create(transaction=transaction_item_created_by_app,- status=TransactionEventStatus.SUCCESS,psp_reference=psp_reference,message="Sucesfull charge",currency="USD",@@ -585,9 +571,7 @@ def test_transaction_event_by_app(]assert event_data["id"] == to_global_id_or_none(event)assert event_data["createdAt"] == event.created_at.isoformat()- assert event_data["status"] == event.status.upper()assert event_data["pspReference"] == event.psp_reference- assert event_data["name"] == event.messageassert event_data["message"] == event.messageassert event_data["externalUrl"] == event.external_urlassert event_data["amount"]["amount"] == event.amount_value@@ -606,7 +590,6 @@ def test_transaction_event_by_reinstalled_app(psp_reference = "psp-ref-123"event = TransactionEvent.objects.create(transaction=transaction_item_created_by_app,- status=TransactionEventStatus.SUCCESS,psp_reference=psp_reference,message="Sucesfull charge",currency="USD",@@ -639,9 +622,7 @@ def test_transaction_event_by_reinstalled_app(]assert event_data["id"] == to_global_id_or_none(event)assert event_data["createdAt"] == event.created_at.isoformat()- assert event_data["status"] == event.status.upper()assert event_data["pspReference"] == event.psp_reference- assert event_data["name"] == event.messageassert event_data["message"] == event.messageassert event_data["externalUrl"] == event.external_urlassert event_data["amount"]["amount"] == event.amount_valuediff --git a/saleor/graphql/payment/types.py b/saleor/graphql/payment/types.pyindex 4a11995169..51e515d21e 100644--- a/saleor/graphql/payment/types.py+++ b/saleor/graphql/payment/types.py@@ -19,7 +19,6 @@ from ..core.descriptions import (ADDED_IN_36,ADDED_IN_313,PREVIEW_FEATURE,- PREVIEW_FEATURE_DEPRECATED_IN_313_FIELD,)from ..core.doc_category import DOC_CATEGORY_PAYMENTSfrom ..core.fields import JSONString, PermissionsField@@ -38,7 +37,6 @@ from .enums import (OrderAction,PaymentChargeStatusEnum,TransactionActionEnum,- TransactionEventStatusEnum,TransactionEventTypeEnum,TransactionKindEnum,)@@ -269,30 +267,9 @@ class PaymentInitialized(BaseObjectType):class TransactionEvent(ModelObjectType[models.TransactionEvent]):created_at = graphene.DateTime(required=True)- status = graphene.Field(- TransactionEventStatusEnum,- description="Status of transaction's event.",- required=False,- deprecation_reason=(- f"{PREVIEW_FEATURE_DEPRECATED_IN_313_FIELD} Use `type` instead."- ),- )- reference = graphene.String(- description="Reference of transaction's event.",- required=True,- deprecation_reason=(- f"{PREVIEW_FEATURE_DEPRECATED_IN_313_FIELD}" "Use `pspReference` instead."- ),- )psp_reference = graphene.String(description="PSP reference of transaction." + ADDED_IN_313, required=True)- name = graphene.String(- description="Name of the transaction's event.",- deprecation_reason=(- f"{PREVIEW_FEATURE_DEPRECATED_IN_313_FIELD} Use `message` instead."- ),- )message = graphene.String(description="Message related to the transaction's event." + ADDED_IN_313,required=True,@@ -324,10 +301,6 @@ class TransactionEvent(ModelObjectType[models.TransactionEvent]):interfaces = [relay.Node]model = models.TransactionEvent- @staticmethod- def resolve_reference(root: models.TransactionEvent, info):- return root.psp_reference or ""-@staticmethoddef resolve_psp_reference(root: models.TransactionEvent, info):return root.psp_reference or ""@@ -336,10 +309,6 @@ class TransactionEvent(ModelObjectType[models.TransactionEvent]):def resolve_external_url(root: models.TransactionEvent, info):return root.external_url or ""- @staticmethod- def resolve_name(root: models.TransactionEvent, info):- return root.message or ""-@staticmethoddef resolve_message(root: models.TransactionEvent, info):return root.message or ""@@ -405,14 +374,6 @@ class TransactionItem(ModelObjectType[models.TransactionItem]):+ ADDED_IN_313),)- voided_amount = graphene.Field(- Money,- required=True,- description=("Total amount voided for this payment."),- deprecation_reason=(- PREVIEW_FEATURE_DEPRECATED_IN_313_FIELD + "Use `canceledAmount` instead."- ),- )canceled_amount = graphene.Field(Money,@@ -438,24 +399,6 @@ class TransactionItem(ModelObjectType[models.TransactionItem]):+ ADDED_IN_313),)- status = graphene.String(- description="Status of transaction.",- deprecation_reason=(- PREVIEW_FEATURE_DEPRECATED_IN_313_FIELD- + " The `status` is not needed. The amounts can be used to define "- "the current status of transactions."- ),- required=True,- )-- type = graphene.String(- description="Type of transaction.",- deprecation_reason=(- PREVIEW_FEATURE_DEPRECATED_IN_313_FIELD- + " Use `name` or `message` instead."- ),- required=True,- )name = graphene.String(description="Name of the transaction." + ADDED_IN_313, required=True)@@ -463,13 +406,6 @@ class TransactionItem(ModelObjectType[models.TransactionItem]):description="Message related to the transaction." + ADDED_IN_313, required=True)- reference = graphene.String(- description="Reference of transaction.",- required=True,- deprecation_reason=(- PREVIEW_FEATURE_DEPRECATED_IN_313_FIELD + "Use `pspReference` instead."- ),- )psp_reference = graphene.String(description="PSP reference of transaction." + ADDED_IN_313, required=True)@@ -523,10 +459,6 @@ class TransactionItem(ModelObjectType[models.TransactionItem]):def resolve_authorize_pending_amount(root: models.TransactionItem, _info):return root.amount_authorize_pending- @staticmethod- def resolve_voided_amount(root: models.TransactionItem, _info):- return root.amount_canceled-@staticmethoddef resolve_canceled_amount(root: models.TransactionItem, _info):return root.amount_canceled@@ -582,10 +514,6 @@ class TransactionItem(ModelObjectType[models.TransactionItem]):return UserByUserIdLoader(info.context).load(root.user_id)return None- @staticmethod- def resolve_reference(root: models.TransactionItem, info):- return root.psp_reference or ""-@staticmethoddef resolve_psp_reference(root: models.TransactionItem, info):return root.psp_reference or ""diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 62ef715d94..af70e9326b 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -2100,13 +2100,6 @@ enum WebhookEventTypeEnum @doc(category: "Webhooks") {"""A staff user is deleted."""STAFF_DELETED- """- An action requested for transaction.-- DEPRECATED: this subscription will be removed in Saleor 3.14 (Preview Feature). Use `TRANSACTION_CHARGE_REQUESTED`, `TRANSACTION_REFUND_REQUESTED`, `TRANSACTION_CANCELATION_REQUESTED` instead.- """- TRANSACTION_ACTION_REQUEST-"""Transaction item metadata is updated.@@ -2740,13 +2733,6 @@ enum WebhookEventTypeAsyncEnum @doc(category: "Webhooks") {"""A staff user is deleted."""STAFF_DELETED- """- An action requested for transaction.-- DEPRECATED: this subscription will be removed in Saleor 3.14 (Preview Feature). Use `TRANSACTION_CHARGE_REQUESTED`, `TRANSACTION_REFUND_REQUESTED`, `TRANSACTION_CANCELATION_REQUESTED` instead.- """- TRANSACTION_ACTION_REQUEST-"""Transaction item metadata is updated.@@ -3451,7 +3437,6 @@ enum WebhookSampleEventTypeEnum @doc(category: "Webhooks") {STAFF_CREATEDSTAFF_UPDATEDSTAFF_DELETED- TRANSACTION_ACTION_REQUESTTRANSACTION_ITEM_METADATA_UPDATEDTRANSLATION_CREATEDTRANSLATION_UPDATED@@ -10350,9 +10335,6 @@ type TransactionItem implements Node & ObjectWithMetadata @doc(category: "Paymen"""refundPendingAmount: Money!- """Total amount voided for this payment."""- voidedAmount: Money! @deprecated(reason: "This field will be removed in Saleor 3.15 (Preview Feature).Use `canceledAmount` instead.")-"""Total amount canceled for this payment.@@ -10377,12 +10359,6 @@ type TransactionItem implements Node & ObjectWithMetadata @doc(category: "Paymen"""chargePendingAmount: Money!- """Status of transaction."""- status: String! @deprecated(reason: "This field will be removed in Saleor 3.15 (Preview Feature). The `status` is not needed. The amounts can be used to define the current status of transactions.")-- """Type of transaction."""- type: String! @deprecated(reason: "This field will be removed in Saleor 3.15 (Preview Feature). Use `name` or `message` instead.")-"""Name of the transaction.@@ -10397,9 +10373,6 @@ type TransactionItem implements Node & ObjectWithMetadata @doc(category: "Paymen"""message: String!- """Reference of transaction."""- reference: String! @deprecated(reason: "This field will be removed in Saleor 3.15 (Preview Feature).Use `pspReference` instead.")-"""PSP reference of transaction.@@ -10438,14 +10411,11 @@ Represents possible actions on payment transaction.The following actions are possible:CHARGE - Represents the charge action.REFUND - Represents a refund action.- VOID - Represents a void action. This field will be removed- in Saleor 3.14 (Preview Feature). Use `CANCEL` instead.CANCEL - Represents a cancel action. Added in Saleor 3.12."""enum TransactionActionEnum @doc(category: "Payments") {CHARGEREFUND- VOIDCANCEL}@@ -11529,9 +11499,6 @@ type OrderEvent implements Node @doc(category: "Orders") {"""The discount applied to the order."""discount: OrderEventDiscountObject- """The status of payment's transaction."""- status: TransactionStatus @deprecated(reason: "This field will be removed in Saleor 3.15 (Preview Feature).Use `TransactionEvent` to track the status of `TransactionItem`.")-"""The reference of payment's transaction."""reference: String}@@ -11569,17 +11536,7 @@ enum OrderEventsEnum @doc(category: "Orders") {PAYMENT_FAILEDTRANSACTION_EVENTTRANSACTION_CHARGE_REQUESTED-- """- This field will be removed in Saleor 3.15 (Preview Feature). Use `TRANSACTION_CHARGE_REQUESTED` instead.- """- TRANSACTION_CAPTURE_REQUESTEDTRANSACTION_REFUND_REQUESTED-- """- This field will be removed in Saleor 3.15 (Preview Feature). Use `TRANSACTION_CANCEL_REQUESTED` instead.- """- TRANSACTION_VOID_REQUESTEDTRANSACTION_CANCEL_REQUESTEDTRANSACTION_MARK_AS_PAID_FAILEDINVOICE_REQUESTED@@ -11649,20 +11606,6 @@ type OrderEventDiscountObject @doc(category: "Orders") {oldAmount: Money}-"""-Represents a status of payment transaction.-- The following statuses are possible:- SUCCESS - Represents a sucess action.- FAILURE - Represents a failure action.- PENDING - Represents a pending action.-"""-enum TransactionStatus @doc(category: "Payments") {- PENDING- SUCCESS- FAILURE-}-"""Contains all details related to the applied discount to the order."""type OrderDiscount implements Node @doc(category: "Discounts") {id: ID!@@ -11836,12 +11779,6 @@ type TransactionEvent implements Node @doc(category: "Payments") {id: ID!createdAt: DateTime!- """Status of transaction's event."""- status: TransactionStatus @deprecated(reason: "This field will be removed in Saleor 3.15 (Preview Feature). Use `type` instead.")-- """Reference of transaction's event."""- reference: String! @deprecated(reason: "This field will be removed in Saleor 3.15 (Preview Feature).Use `pspReference` instead.")-"""PSP reference of transaction.@@ -11849,9 +11786,6 @@ type TransactionEvent implements Node @doc(category: "Payments") {"""pspReference: String!- """Name of the transaction's event."""- name: String @deprecated(reason: "This field will be removed in Saleor 3.15 (Preview Feature). Use `message` instead.")-"""Message related to the transaction's event.@@ -21884,20 +21818,6 @@ enum TransactionCreateErrorCode @doc(category: "Payments") {}input TransactionCreateInput @doc(category: "Payments") {- """- Status of the transaction.-- DEPRECATED: this field will be removed in Saleor 3.15 (Preview Feature). The `status` is not needed. The amounts can be used to define the current status of transactions.- """- status: String-- """- Payment type used for this transaction.-- DEPRECATED: this field will be removed in Saleor 3.15 (Preview Feature). Use `name` and `message` instead.- """- type: String-"""Payment name of the transaction.@@ -21912,13 +21832,6 @@ input TransactionCreateInput @doc(category: "Payments") {"""message: String- """- Reference of the transaction.-- DEPRECATED: this field will be removed in Saleor 3.15 (Preview Feature). Use `pspReference` instead.- """- reference: String-"""PSP Reference of the transaction.@@ -21938,13 +21851,6 @@ input TransactionCreateInput @doc(category: "Payments") {"""Amount refunded by this transaction."""amountRefunded: MoneyInput- """- Amount voided by this transaction.-- DEPRECATED: this field will be removed in Saleor 3.15 (Preview Feature). Use `amountCanceled` instead.- """- amountVoided: MoneyInput-"""Amount canceled by this transaction.@@ -21967,20 +21873,6 @@ input TransactionCreateInput @doc(category: "Payments") {}input TransactionEventInput @doc(category: "Payments") {- """- Current status of the payment transaction.-- DEPRECATED: this field will be removed in Saleor 3.15 (Preview Feature). Status will be calculated by Saleor.- """- status: TransactionStatus-- """- Reference of the transaction.-- DEPRECATED: this field will be removed in Saleor 3.15 (Preview Feature). Use `pspReference` instead.- """- reference: String-"""PSP Reference related to this action.@@ -21988,13 +21880,6 @@ input TransactionEventInput @doc(category: "Payments") {"""pspReference: String- """- Name of the transaction.-- DEPRECATED: this field will be removed in Saleor 3.15 (Preview Feature). Use `message` instead. `name` field will be added to `message`.- """- name: String-"""The message related to the event.@@ -22041,20 +21926,6 @@ enum TransactionUpdateErrorCode @doc(category: "Payments") {}input TransactionUpdateInput @doc(category: "Payments") {- """- Status of the transaction.-- DEPRECATED: this field will be removed in Saleor 3.15 (Preview Feature). The `status` is not needed. The amounts can be used to define the current status of transactions.- """- status: String-- """- Payment type used for this transaction.-- DEPRECATED: this field will be removed in Saleor 3.15 (Preview Feature). Use `name` and `message` instead.- """- type: String-"""Payment name of the transaction.@@ -22069,13 +21940,6 @@ input TransactionUpdateInput @doc(category: "Payments") {"""message: String- """- Reference of the transaction.-- DEPRECATED: this field will be removed in Saleor 3.15 (Preview Feature). Use `pspReference` instead.- """- reference: String-"""PSP Reference of the transaction.@@ -22095,13 +21959,6 @@ input TransactionUpdateInput @doc(category: "Payments") {"""Amount refunded by this transaction."""amountRefunded: MoneyInput- """- Amount voided by this transaction.-- DEPRECATED: this field will be removed in Saleor 3.15 (Preview Feature). Use `amountCanceled` instead.- """- amountVoided: MoneyInput-"""Amount canceled by this transaction.@@ -30889,41 +30746,6 @@ type StaffDeleted implements Event @doc(category: "Users") {user: User}-"""-Event sent when transaction action is requested.--Added in Saleor 3.4.--DEPRECATED: this subscription will be removed in Saleor 3.14 (Preview Feature). Use `TransactionChargeRequested`, `TransactionRefundRequested`, `TransactionCancelationRequested` instead.-"""-type TransactionActionRequest implements Event @doc(category: "Payments") {- """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 transaction."""- transaction: TransactionItem-- """Requested action data."""- action: TransactionAction!-}--type TransactionAction @doc(category: "Payments") {- """Determines the action type."""- actionType: TransactionActionEnum!-- """Transaction request amount. Null when action type is VOID."""- amount: PositiveDecimal-}-"""Event sent when transaction item metadata is updated.@@ -31408,6 +31230,14 @@ type TransactionCancelationRequested implements Event @doc(category: "Payments")action: TransactionAction!}+type TransactionAction @doc(category: "Payments") {+ """Determines the action type."""+ actionType: TransactionActionEnum!++ """Transaction request amount. Null when action type is VOID."""+ amount: PositiveDecimal+}+"""Event sent when transaction charge is requested.diff --git a/saleor/graphql/tests/queries/fragments.py b/saleor/graphql/tests/queries/fragments.pyindex 70cec347af..95b633fa19 100644--- a/saleor/graphql/tests/queries/fragments.py+++ b/saleor/graphql/tests/queries/fragments.py@@ -453,7 +453,7 @@ fragment TransactionFragment on TransactionItem {currencyamount}- voidedAmount {+ canceledAmount {currencyamount}@@ -464,10 +464,7 @@ fragment TransactionFragment on TransactionItem {events {id}- status- typepspReference- referenceorder {id}diff --git a/saleor/graphql/webhook/enums.py b/saleor/graphql/webhook/enums.pyindex 3b38baa5b9..18fd88441c 100644--- a/saleor/graphql/webhook/enums.py+++ b/saleor/graphql/webhook/enums.py@@ -186,12 +186,6 @@ WEBHOOK_EVENT_DESCRIPTION = {WebhookEventAsyncType.STAFF_CREATED: "A new staff user is created.",WebhookEventAsyncType.STAFF_UPDATED: "A staff user is updated.",WebhookEventAsyncType.STAFF_DELETED: "A staff user is deleted.",- WebhookEventAsyncType.TRANSACTION_ACTION_REQUEST: (- "An action requested for transaction."- + "\n\nDEPRECATED: this subscription will be removed in Saleor 3.14 "- + "(Preview Feature). Use `TRANSACTION_CHARGE_REQUESTED`, "- + "`TRANSACTION_REFUND_REQUESTED`, `TRANSACTION_CANCELATION_REQUESTED` instead."- ),WebhookEventAsyncType.TRANSACTION_ITEM_METADATA_UPDATED: ("Transaction item metadata is updated." + ADDED_IN_38),diff --git a/saleor/graphql/webhook/subscription_types.py b/saleor/graphql/webhook/subscription_types.pyindex dbc4ad29e4..abd69148bb 100644--- a/saleor/graphql/webhook/subscription_types.py+++ b/saleor/graphql/webhook/subscription_types.py@@ -1549,21 +1549,6 @@ class TransactionActionBase(AbstractType):return transaction_action_data-class TransactionActionRequest(TransactionActionBase, SubscriptionObjectType):- class Meta:- root_type = None- enable_dry_run = False- interfaces = (Event,)- description = (- "Event sent when transaction action is requested."- + ADDED_IN_34- + "\n\nDEPRECATED: this subscription will be removed in Saleor 3.14 "- + "(Preview Feature). Use `TransactionChargeRequested`, "- + "`TransactionRefundRequested`, `TransactionCancelationRequested` instead."- )- doc_category = DOC_CATEGORY_PAYMENTS--class TransactionChargeRequested(TransactionActionBase, SubscriptionObjectType):class Meta:interfaces = (Event,)@@ -2231,7 +2216,6 @@ WEBHOOK_TYPES_MAP = {WebhookEventAsyncType.STAFF_CREATED: StaffCreated,WebhookEventAsyncType.STAFF_UPDATED: StaffUpdated,WebhookEventAsyncType.STAFF_DELETED: StaffDeleted,- WebhookEventAsyncType.TRANSACTION_ACTION_REQUEST: TransactionActionRequest,WebhookEventAsyncType.TRANSACTION_ITEM_METADATA_UPDATED: (TransactionItemMetadataUpdated),diff --git a/saleor/order/__init__.py b/saleor/order/__init__.pyindex dbe830beb5..3e17d734bc 100644--- a/saleor/order/__init__.py+++ b/saleor/order/__init__.py@@ -119,10 +119,8 @@ class OrderEvents:PAYMENT_FAILED = "payment_failed"TRANSACTION_EVENT = "transaction_event"- TRANSACTION_CAPTURE_REQUESTED = "transaction_capture_requested"TRANSACTION_CHARGE_REQUESTED = "transaction_charge_requested"TRANSACTION_REFUND_REQUESTED = "transaction_refund_requested"- TRANSACTION_VOID_REQUESTED = "transaction_void_requested"TRANSACTION_CANCEL_REQUESTED = "transaction_cancel_requested"TRANSACTION_MARK_AS_PAID_FAILED = "transaction_mark_as_paid_failed"@@ -182,9 +180,7 @@ class OrderEvents:(PAYMENT_FAILED, "The payment was failed"),(TRANSACTION_EVENT, "The transaction event"),(TRANSACTION_CHARGE_REQUESTED, "The charge requested for transaction"),- (TRANSACTION_CAPTURE_REQUESTED, "The capture requested for transaction"),(TRANSACTION_REFUND_REQUESTED, "The refund requested for transaction"),- (TRANSACTION_VOID_REQUESTED, "The void requested for transaction"),(TRANSACTION_CANCEL_REQUESTED, "The cancel requested for transaction"),(TRANSACTION_MARK_AS_PAID_FAILED, "The mark as paid failed for transaction"),(INVOICE_REQUESTED, "An invoice was requested"),diff --git a/saleor/order/events.py b/saleor/order/events.pyindex c97777ea5a..979f209d39 100644--- a/saleor/order/events.py+++ b/saleor/order/events.py@@ -503,10 +503,9 @@ def transaction_event(user: Optional[User],app: Optional[App],reference: str,- status: Optional[str],message: str) -> OrderEvent:- parameters = {"message": message, "reference": reference, "status": status}+ parameters = {"message": message, "reference": reference}return OrderEvent.objects.create(order=order,type=OrderEvents.TRANSACTION_EVENT,diff --git a/saleor/order/migrations/0172_auto_20230627_0816.py b/saleor/order/migrations/0172_auto_20230627_0816.pynew file mode 100644index 0000000000..a2f3cafad2--- /dev/null+++ b/saleor/order/migrations/0172_auto_20230627_0816.py@@ -0,0 +1,92 @@+# Generated by Django 3.2.19 on 2023-06-01 08:15++from django.apps import apps as registry+from django.db import migrations, models+from django.db.models.signals import post_migrate++from .tasks.saleor3_15 import drop_status_field_from_transaction_event_task+++def drop_status_field_from_transaction_event(apps, _schema_editor):+ def on_migrations_complete(sender=None, **kwargs):+ drop_status_field_from_transaction_event_task.delay()++ sender = registry.get_app_config("order")+ post_migrate.connect(on_migrations_complete, weak=False, sender=sender)+++class Migration(migrations.Migration):+ dependencies = [+ ("order", "0171_auto_20230518_0854"),+ ]++ operations = [+ migrations.AlterField(+ model_name="orderevent",+ name="type",+ field=models.CharField(+ choices=[+ ("DRAFT_CREATED", "draft_created"),+ ("DRAFT_CREATED_FROM_REPLACE", "draft_created_from_replace"),+ ("ADDED_PRODUCTS", "added_products"),+ ("REMOVED_PRODUCTS", "removed_products"),+ ("PLACED", "placed"),+ ("PLACED_FROM_DRAFT", "placed_from_draft"),+ ("OVERSOLD_ITEMS", "oversold_items"),+ ("CANCELED", "canceled"),+ ("EXPIRED", "expired"),+ ("ORDER_MARKED_AS_PAID", "order_marked_as_paid"),+ ("ORDER_FULLY_PAID", "order_fully_paid"),+ ("ORDER_REPLACEMENT_CREATED", "order_replacement_created"),+ ("ORDER_DISCOUNT_ADDED", "order_discount_added"),+ (+ "ORDER_DISCOUNT_AUTOMATICALLY_UPDATED",+ "order_discount_automatically_updated",+ ),+ ("ORDER_DISCOUNT_UPDATED", "order_discount_updated"),+ ("ORDER_DISCOUNT_DELETED", "order_discount_deleted"),+ ("ORDER_LINE_DISCOUNT_UPDATED", "order_line_discount_updated"),+ ("ORDER_LINE_DISCOUNT_REMOVED", "order_line_discount_removed"),+ ("ORDER_LINE_PRODUCT_DELETED", "order_line_product_deleted"),+ ("ORDER_LINE_VARIANT_DELETED", "order_line_variant_deleted"),+ ("UPDATED_ADDRESS", "updated_address"),+ ("EMAIL_SENT", "email_sent"),+ ("CONFIRMED", "confirmed"),+ ("PAYMENT_AUTHORIZED", "payment_authorized"),+ ("PAYMENT_CAPTURED", "payment_captured"),+ ("EXTERNAL_SERVICE_NOTIFICATION", "external_service_notification"),+ ("PAYMENT_REFUNDED", "payment_refunded"),+ ("PAYMENT_VOIDED", "payment_voided"),+ ("PAYMENT_FAILED", "payment_failed"),+ ("TRANSACTION_EVENT", "transaction_event"),+ ("TRANSACTION_CHARGE_REQUESTED", "transaction_charge_requested"),+ ("TRANSACTION_REFUND_REQUESTED", "transaction_refund_requested"),+ ("TRANSACTION_CANCEL_REQUESTED", "transaction_cancel_requested"),+ (+ "TRANSACTION_MARK_AS_PAID_FAILED",+ "transaction_mark_as_paid_failed",+ ),+ ("INVOICE_REQUESTED", "invoice_requested"),+ ("INVOICE_GENERATED", "invoice_generated"),+ ("INVOICE_UPDATED", "invoice_updated"),+ ("INVOICE_SENT", "invoice_sent"),+ ("FULFILLMENT_CANCELED", "fulfillment_canceled"),+ ("FULFILLMENT_RESTOCKED_ITEMS", "fulfillment_restocked_items"),+ ("FULFILLMENT_FULFILLED_ITEMS", "fulfillment_fulfilled_items"),+ ("FULFILLMENT_REFUNDED", "fulfillment_refunded"),+ ("FULFILLMENT_RETURNED", "fulfillment_returned"),+ ("FULFILLMENT_REPLACED", "fulfillment_replaced"),+ ("FULFILLMENT_AWAITS_APPROVAL", "fulfillment_awaits_approval"),+ ("TRACKING_UPDATED", "tracking_updated"),+ ("NOTE_ADDED", "note_added"),+ ("NOTE_UPDATED", "note_updated"),+ ("OTHER", "other"),+ ],+ max_length=255,+ ),+ ),+ migrations.RunPython(+ drop_status_field_from_transaction_event,+ reverse_code=migrations.RunPython.noop,+ ),+ ]diff --git a/saleor/order/migrations/tasks/saleor3_15.py b/saleor/order/migrations/tasks/saleor3_15.pynew file mode 100644index 0000000000..49ee4cdd32--- /dev/null+++ b/saleor/order/migrations/tasks/saleor3_15.py@@ -0,0 +1,30 @@+from django.db.models import Exists, OuterRef++from ....celeryconf import app+from ....payment.models import TransactionItem+from ...models import OrderEvent++# Batch size of size 5000 is about 5MB memory usage in task+BATCH_SIZE = 5000+++def drop_status_field_from_transaction_event_task():+ orders = TransactionItem.objects.filter(order_id__isnull=False)++ qs = OrderEvent.objects.filter(+ Exists(orders.filter(order_id=OuterRef("order_id"))),+ type="transaction_event",+ parameters__has_key="status",+ )++ event_ids = qs.values_list("pk", flat=True)[:BATCH_SIZE]+ if event_ids:+ events_to_update = []+ events = OrderEvent.objects.filter(id__in=event_ids)+ for event in events:+ if "status" in event.parameters:+ del event.parameters["status"]+ events_to_update.append(event)+ OrderEvent.objects.bulk_update(events_to_update, ["parameters"])+ drop_status_field_from_transaction_event_task.delay()diff --git a/saleor/payment/__init__.py b/saleor/payment/__init__.pyindex 9a9f57e772..9a5b311f28 100644--- a/saleor/payment/__init__.py+++ b/saleor/payment/__init__.py@@ -149,20 +149,16 @@ class TransactionAction:The following actions are possible:CHARGE - Represents the charge action.REFUND - Represents a refund action.- VOID - Represents a void action. This field will be removed- in Saleor 3.14 (Preview Feature). Use `CANCEL` instead.CANCEL - Represents a cancel action. Added in Saleor 3.12."""CHARGE = "charge"REFUND = "refund"- VOID = "void"CANCEL = "cancel"CHOICES = [(CHARGE, "Charge payment"),(REFUND, "Refund payment"),- (VOID, "Void payment"),(CANCEL, "Cancel payment"),]@@ -237,23 +233,3 @@ class TransactionEventType:(CANCEL_REQUEST, "Represents cancel request"),(INFO, "Represents an info event"),]---class TransactionEventStatus:- """Represents a status of payment transaction.-- The following statuses are possible:- SUCCESS - Represents a sucess action.- FAILURE - Represents a failure action.- PENDING - Represents a pending action.- """-- PENDING = "pending"- SUCCESS = "success"- FAILURE = "failure"-- CHOICES = [- (PENDING, "Pending"),- (SUCCESS, "Success"),- (FAILURE, "Failure"),- ]diff --git a/saleor/payment/gateway.py b/saleor/payment/gateway.pyindex 2e92ff2efd..180e9219bc 100644--- a/saleor/payment/gateway.py+++ b/saleor/payment/gateway.py@@ -192,7 +192,7 @@ def request_cancelation_action(def _create_transaction_data(transaction: TransactionItem,- action_type: "str",+ action_type: str,action_value: Optional[Decimal],request_event: TransactionEvent,granted_refund: Optional[OrderGrantedRefund] = None,@@ -221,10 +221,6 @@ def _request_payment_action(transaction_request_func: Callable[[TransactionActionData, str], None],plugin_func_name: str,):- transaction_action_request_event_active = manager.is_event_active_for_any_plugin(- "transaction_action_request", channel_slug=channel_slug- )-transaction_request_event_active = manager.is_event_active_for_any_plugin(plugin_func_name, channel_slug=channel_slug)@@ -236,11 +232,7 @@ def _request_payment_action(apps_ids=[transaction_action_data.transaction_app_owner.pk],)- if (- not transaction_action_request_event_active- and not transaction_request_event_active- and not webhooks- ):+ if not transaction_request_event_active and not webhooks:create_failed_transaction_event(transaction_action_data.event,cause="No app or plugin is configured to handle payment action requests.",@@ -249,15 +241,7 @@ def _request_payment_action("No app or plugin is configured to handle payment action requests.")- if transaction_request_event_active or webhooks:- # This if can be dropped in future releases as VOID will be dropped.- if transaction_action_data.action_type == TransactionAction.VOID:- transaction_action_data.action_type = TransactionAction.CANCEL- transaction_request_func(transaction_action_data, channel_slug)- else:- manager.transaction_action_request(- transaction_action_data, channel_slug=channel_slug- )+ transaction_request_func(transaction_action_data, channel_slug)@raise_payment_errordiff --git a/saleor/payment/migrations/0051_alter_transactionitem_available_actions.py b/saleor/payment/migrations/0051_alter_transactionitem_available_actions.pynew file mode 100644index 0000000000..89c3c5982a--- /dev/null+++ b/saleor/payment/migrations/0051_alter_transactionitem_available_actions.py@@ -0,0 +1,67 @@+# Generated by Django 3.2.19 on 2023-06-05 11:14++import django.contrib.postgres.fields+from django.db import migrations, models++BATCH_SIZE = 1000+++def queryset_in_batches(queryset):+ """Slice a queryset into batches.++ Input queryset should be sorted be pk.+ """+ start_pk = 0++ while True:+ qs = queryset.order_by("pk").filter(pk__gt=start_pk)[:BATCH_SIZE]+ pks = list(qs.values_list("pk", flat=True))++ if not pks:+ break++ yield pks++ start_pk = pks[-1]+++def convert_void_to_cancel(apps, schema_editor):+ TransactionItem = apps.get_model("payment", "TransactionItem")+ qs = TransactionItem.objects.filter(available_actions__contains=["void"]).order_by(+ "pk"+ )+ for batch_pks in queryset_in_batches(qs):+ transactions = TransactionItem.objects.filter(pk__in=batch_pks)+ for transaction_item in transactions:+ current_available_actions = transaction_item.available_actions+ if "void" in current_available_actions:+ current_available_actions.remove("void")+ if "cancel" not in current_available_actions:+ current_available_actions.append("cancel")+ TransactionItem.objects.bulk_update(transactions, ["available_actions"])+++class Migration(migrations.Migration):+ dependencies = [+ ("payment", "0050_drop_unused_transaction_fields"),+ ]++ operations = [+ migrations.RunPython(convert_void_to_cancel, migrations.RunPython.noop),+ migrations.AlterField(+ model_name="transactionitem",+ name="available_actions",+ field=django.contrib.postgres.fields.ArrayField(+ base_field=models.CharField(+ choices=[+ ("charge", "Charge payment"),+ ("refund", "Refund payment"),+ ("cancel", "Cancel payment"),+ ],+ max_length=128,+ ),+ default=list,+ size=None,+ ),+ ),+ ]diff --git a/saleor/payment/migrations/0052_auto_20230601_0818.py b/saleor/payment/migrations/0052_auto_20230601_0818.pynew file mode 100644index 0000000000..147be61857--- /dev/null+++ b/saleor/payment/migrations/0052_auto_20230601_0818.py@@ -0,0 +1,28 @@+# Generated by Django 3.2.19 on 2023-06-01 08:18++from django.db import migrations+++class Migration(migrations.Migration):+ dependencies = [+ ("payment", "0051_alter_transactionitem_available_actions"),+ ]++ operations = [+ migrations.RemoveIndex(+ model_name="transactionitem",+ name="payment_tra_order_i_e783c4_gin",+ ),+ migrations.SeparateDatabaseAndState(+ state_operations=[+ migrations.RemoveField(+ model_name="transactionitem",+ name="status",+ ),+ migrations.RemoveField(+ model_name="transactionevent",+ name="status",+ ),+ ]+ ),+ ]diff --git a/saleor/payment/models.py b/saleor/payment/models.pyindex 39d7a741b8..4e8d13a6e3 100644--- a/saleor/payment/models.py+++ b/saleor/payment/models.py@@ -22,7 +22,6 @@ from . import (CustomPaymentChoices,StorePaymentMethod,TransactionAction,- TransactionEventStatus,TransactionEventType,TransactionKind,)@@ -33,7 +32,7 @@ class TransactionItem(ModelWithMetadata):use_old_id = models.BooleanField(default=False)created_at = models.DateTimeField(auto_now_add=True)modified_at = models.DateTimeField(auto_now=True)- status = models.CharField(max_length=512, blank=True, null=True, default="")+name = models.CharField(max_length=512, blank=True, null=True, default="")message = models.CharField(max_length=512, blank=True, null=True, default="")psp_reference = models.CharField(max_length=512, blank=True, null=True)@@ -150,20 +149,11 @@ class TransactionItem(ModelWithMetadata):ordering = ("pk",)indexes = [*ModelWithMetadata.Meta.indexes,- # Orders filtering by status index- GinIndex(fields=["order_id", "status"]),]class TransactionEvent(models.Model):created_at = models.DateTimeField(default=timezone.now)- status = models.CharField(- max_length=128,- choices=TransactionEventStatus.CHOICES,- default=TransactionEventStatus.SUCCESS,- blank=True,- null=True,- )psp_reference = models.CharField(max_length=512, blank=True, null=True)message = models.CharField(max_length=512, blank=True, null=True, default="")transaction = models.ForeignKey(diff --git a/saleor/payment/tests/test_gateway.py b/saleor/payment/tests/test_gateway.pyindex f271a36995..86b7a678d0 100644--- a/saleor/payment/tests/test_gateway.py+++ b/saleor/payment/tests/test_gateway.py@@ -5,6 +5,7 @@ import pytestfrom ...order import OrderEventsfrom ...plugins.manager import get_plugins_manager+from ...webhook.event_types import WebhookEventSyncTypefrom .. import (ChargeStatus,CustomPaymentChoices,@@ -338,10 +339,9 @@ def test_request_charge_action_missing_active_event():# giventransaction = TransactionItem.objects.create(- status="Authorized",name="Credit card",psp_reference="PSP ref",- available_actions=["capture", "void"],+ available_actions=["capture", "cancel"],currency="USD",order_id=order.pk,authorized_value=Decimal("10"),@@ -367,74 +367,31 @@ def test_request_charge_action_missing_active_event()-@patch("saleor.plugins.manager.PluginsManager.is_event_active_for_any_plugin")-@patch("saleor.plugins.manager.PluginsManager.transaction_action_request")-def test_request_charge_action_with_transaction_action_request(- mocked_transaction_request, mocked_is_active, order, staff_user-):- # given- transaction = TransactionItem.objects.create(- status="Authorized",- name="Credit card",- psp_reference="PSP ref",- available_actions=["capture", "void"],- currency="USD",- order_id=order.pk,- authorized_value=Decimal("10"),- )- action_value = Decimal("5.00")- requested_event = transaction.events.create(- amount_value=action_value,- currency=transaction.currency,- type=TransactionEventType.CHARGE_REQUEST,- )- mocked_is_active.side_effect = [True, False]-- # when- request_charge_action(- transaction=transaction,- manager=get_plugins_manager(),- charge_value=action_value,- channel_slug=order.channel.slug,- user=staff_user,- app=None,- request_event=requested_event,- )-- # then- assert mocked_is_active.called- mocked_transaction_request.assert_called_once_with(- TransactionActionData(- transaction=transaction,- action_type=TransactionAction.CHARGE,- action_value=action_value,- event=requested_event,- transaction_app_owner=None,- ),- channel_slug=order.channel.slug,- )-- event = order.events.first()- assert event.type == OrderEvents.TRANSACTION_CHARGE_REQUESTED- assert Decimal(event.parameters["amount"]) == action_value- assert event.parameters["reference"] == transaction.psp_reference- assert event.user == staff_user--@patch("saleor.plugins.manager.PluginsManager.is_event_active_for_any_plugin")@patch("saleor.plugins.manager.PluginsManager.transaction_charge_requested")def test_request_charge_action_on_order(- mocked_transaction_request, mocked_is_active, order, staff_user+ mocked_transaction_request,+ mocked_is_active,+ order,+ staff_user,+ permission_manage_payments,+ app,):# given+ app.permissions.add(permission_manage_payments)+ webhook = app.webhooks.create(+ name="Simple webhook", app=app, target_url="http://127.0.0.1"+ )+ webhook.events.create(event_type=WebhookEventSyncType.TRANSACTION_CHARGE_REQUESTED)+transaction = TransactionItem.objects.create(- status="Authorized",name="Credit card",psp_reference="PSP ref",- available_actions=["capture", "void"],+ available_actions=["capture", "cancel"],currency="USD",order_id=order.pk,authorized_value=Decimal("10"),+ app=app,)action_value = Decimal("5.00")requested_event = transaction.events.create(@@ -463,7 +420,7 @@ def test_request_charge_action_on_order(action_type=TransactionAction.CHARGE,action_value=action_value,event=requested_event,- transaction_app_owner=None,+ transaction_app_owner=app,),order.channel.slug,)@@ -478,17 +435,27 @@ def test_request_charge_action_on_order(@patch("saleor.plugins.manager.PluginsManager.is_event_active_for_any_plugin")@patch("saleor.plugins.manager.PluginsManager.transaction_charge_requested")def test_request_charge_action_by_app(- mocked_transaction_request, mocked_is_active, order, app+ mocked_transaction_request,+ mocked_is_active,+ order,+ app,+ webhook_app,+ permission_manage_payments,):# given+ webhook_app.permissions.add(permission_manage_payments)+ webhook = webhook_app.webhooks.create(+ name="Simple webhook", target_url="http://127.0.0.1"+ )+ webhook.events.create(event_type=WebhookEventSyncType.TRANSACTION_CHARGE_REQUESTED)transaction = TransactionItem.objects.create(- status="Authorized",name="Credit card",psp_reference="PSP ref",- available_actions=["capture", "void"],+ available_actions=["capture", "cancel"],currency="USD",order_id=order.pk,authorized_value=Decimal("10"),+ app=webhook_app,)action_value = Decimal("5.00")requested_event = transaction.events.create(@@ -517,7 +484,7 @@ def test_request_charge_action_by_app(action_type=TransactionAction.CHARGE,action_value=action_value,event=requested_event,- transaction_app_owner=None,+ transaction_app_owner=webhook_app,),order.channel.slug,)@@ -532,17 +499,28 @@ def test_request_charge_action_by_app(@patch("saleor.plugins.manager.PluginsManager.is_event_active_for_any_plugin")@patch("saleor.plugins.manager.PluginsManager.transaction_charge_requested")def test_request_charge_action_on_checkout(- mocked_transaction_request, mocked_is_active, checkout, staff_user+ mocked_transaction_request,+ mocked_is_active,+ checkout,+ staff_user,+ app,+ permission_manage_payments,):# given+ app.permissions.add(permission_manage_payments)+ webhook = app.webhooks.create(+ name="Simple webhook", app=app, target_url="http://127.0.0.1"+ )+ webhook.events.create(event_type=WebhookEventSyncType.TRANSACTION_CHARGE_REQUESTED)+transaction = TransactionItem.objects.create(- status="Authorized",name="Credit card",psp_reference="PSP ref",- available_actions=["capture", "void"],+ available_actions=["capture", "cancel"],currency="USD",checkout_id=checkout.pk,authorized_value=Decimal("10"),+ app=app,)action_value = Decimal("5.00")requested_event = transaction.events.create(@@ -571,7 +549,7 @@ def test_request_charge_action_on_checkout(action_type=TransactionAction.CHARGE,action_value=action_value,event=requested_event,- transaction_app_owner=None,+ transaction_app_owner=app,),checkout.channel.slug,)@@ -583,7 +561,6 @@ def test_request_refund_action_missing_active_event():# giventransaction = TransactionItem.objects.create(- status="Captured",name="Credit card",psp_reference="PSP ref",available_actions=["refund"],@@ -612,74 +589,31 @@ def test_request_refund_action_missing_active_event()-@patch("saleor.plugins.manager.PluginsManager.is_event_active_for_any_plugin")-@patch("saleor.plugins.manager.PluginsManager.transaction_action_request")-def test_request_refund_action_with_transaction_action_request(- mocked_transaction_request, mocked_is_active, order, staff_user-):- # given- transaction = TransactionItem.objects.create(- status="Captured",- name="Credit card",- psp_reference="PSP ref",- available_actions=["refund"],- currency="USD",- order_id=order.pk,- charged_value=Decimal("10"),- )- action_value = Decimal("5.00")- requested_event = transaction.events.create(- amount_value=action_value,- currency=transaction.currency,- type=TransactionEventType.REFUND_REQUEST,- )- mocked_is_active.side_effect = [True, False]-- # when- request_refund_action(- transaction=transaction,- manager=get_plugins_manager(),- refund_value=action_value,- channel_slug=order.channel.slug,- user=staff_user,- app=None,- request_event=requested_event,- )-- # then- assert mocked_is_active.called- mocked_transaction_request.assert_called_once_with(- TransactionActionData(- transaction=transaction,- action_type=TransactionAction.REFUND,- action_value=action_value,- event=requested_event,- transaction_app_owner=None,- ),- channel_slug=order.channel.slug,- )-- event = order.events.first()- assert event.type == OrderEvents.TRANSACTION_REFUND_REQUESTED- assert Decimal(event.parameters["amount"]) == action_value- assert event.parameters["reference"] == transaction.psp_reference- assert event.user == staff_user--@patch("saleor.plugins.manager.PluginsManager.is_event_active_for_any_plugin")@patch("saleor.plugins.manager.PluginsManager.transaction_refund_requested")def test_request_refund_action_on_order(- mocked_transaction_request, mocked_is_active, order, staff_user+ mocked_transaction_request,+ mocked_is_active,+ order,+ staff_user,+ app,+ permission_manage_payments,):# given+ app.permissions.add(permission_manage_payments)+ webhook = app.webhooks.create(+ name="Simple webhook", app=app, target_url="http://127.0.0.1"+ )+ webhook.events.create(event_type=WebhookEventSyncType.TRANSACTION_REFUND_REQUESTED)+transaction = TransactionItem.objects.create(- status="Captured",name="Credit card",psp_reference="PSP ref",available_actions=["refund"],currency="USD",order_id=order.pk,charged_value=Decimal("10"),+ app=app,)action_value = Decimal("5.00")requested_event = transaction.events.create(@@ -708,7 +642,7 @@ def test_request_refund_action_on_order(action_type=TransactionAction.REFUND,action_value=action_value,event=requested_event,- transaction_app_owner=None,+ transaction_app_owner=app,),order.channel.slug,)@@ -723,9 +657,20 @@ def test_request_refund_action_on_order(@patch("saleor.plugins.manager.PluginsManager.is_event_active_for_any_plugin")@patch("saleor.plugins.manager.PluginsManager.transaction_refund_requested")def test_request_refund_action_with_granted_refund(- mocked_transaction_request, mocked_is_active, order_with_lines, staff_user+ mocked_transaction_request,+ mocked_is_active,+ order_with_lines,+ staff_user,+ permission_manage_payments,+ app,):# given+ app.permissions.add(permission_manage_payments)+ webhook = app.webhooks.create(+ name="Simple webhook", app=app, target_url="http://127.0.0.1"+ )+ webhook.events.create(event_type=WebhookEventSyncType.TRANSACTION_REFUND_REQUESTED)+order_line = order_with_lines.lines.first()granted_refund = order_with_lines.granted_refunds.create(amount_value=order_line.unit_price_gross_amount@@ -736,13 +681,13 @@ def test_request_refund_action_with_granted_refund()transaction = TransactionItem.objects.create(- status="Captured",name="Credit card",psp_reference="PSP ref",available_actions=["refund"],currency="USD",order_id=order_with_lines.pk,charged_value=Decimal("10"),+ app=app,)action_value = order_line.unit_price_gross_amountrequested_event = transaction.events.create(@@ -772,7 +717,7 @@ def test_request_refund_action_with_granted_refund(action_type=TransactionAction.REFUND,action_value=action_value,event=requested_event,- transaction_app_owner=None,+ transaction_app_owner=app,granted_refund=granted_refund,),order_with_lines.channel.slug,@@ -788,17 +733,28 @@ def test_request_refund_action_with_granted_refund(@patch("saleor.plugins.manager.PluginsManager.is_event_active_for_any_plugin")@patch("saleor.plugins.manager.PluginsManager.transaction_refund_requested")def test_request_refund_action_by_app(- mocked_transaction_request, mocked_is_active, order, app+ mocked_transaction_request,+ mocked_is_active,+ order,+ app,+ webhook_app,+ permission_manage_payments,):# given+ webhook_app.permissions.add(permission_manage_payments)+ webhook = webhook_app.webhooks.create(+ name="Simple webhook", app=app, target_url="http://127.0.0.1"+ )+ webhook.events.create(event_type=WebhookEventSyncType.TRANSACTION_REFUND_REQUESTED)+transaction = TransactionItem.objects.create(- status="Captured",name="Credit card",psp_reference="PSP ref",available_actions=["refund"],currency="USD",order_id=order.pk,charged_value=Decimal("10"),+ app=webhook_app,)action_value = Decimal("5.00")requested_event = transaction.events.create(@@ -827,7 +783,7 @@ def test_request_refund_action_by_app(action_type=TransactionAction.REFUND,action_value=action_value,event=requested_event,- transaction_app_owner=None,+ transaction_app_owner=webhook_app,),order.channel.slug,)@@ -843,17 +799,28 @@ def test_request_refund_action_by_app(@patch("saleor.plugins.manager.PluginsManager.is_event_active_for_any_plugin")@patch("saleor.plugins.manager.PluginsManager.transaction_refund_requested")def test_request_refund_action_on_checkout(- mocked_transaction_request, mocked_is_active, checkout, staff_user+ mocked_transaction_request,+ mocked_is_active,+ checkout,+ staff_user,+ app,+ permission_manage_payments,):# given+ app.permissions.add(permission_manage_payments)+ webhook = app.webhooks.create(+ name="Simple webhook", app=app, target_url="http://127.0.0.1"+ )+ webhook.events.create(event_type=WebhookEventSyncType.TRANSACTION_REFUND_REQUESTED)+transaction = TransactionItem.objects.create(- status="Captured",name="Credit card",psp_reference="PSP ref",available_actions=["refund"],currency="USD",checkout_id=checkout.pk,charged_value=Decimal("10"),+ app=app,)action_value = Decimal("5.00")requested_event = transaction.events.create(@@ -882,7 +849,7 @@ def test_request_refund_action_on_checkout(action_type=TransactionAction.REFUND,action_value=action_value,event=requested_event,- transaction_app_owner=None,+ transaction_app_owner=app,),checkout.channel.slug,)@@ -894,10 +861,9 @@ def test_request_cancelation_action_missing_active_event():# giventransaction = TransactionItem.objects.create(- status="Authorized",name="Credit card",psp_reference="PSP ref",- available_actions=["capture", "void"],+ available_actions=["capture", "cancel"],currency="USD",order_id=order.pk,authorized_value=Decimal("10"),@@ -926,17 +892,30 @@ def test_request_cancelation_action_missing_active_event(@patch("saleor.plugins.manager.PluginsManager.is_event_active_for_any_plugin")@patch("saleor.plugins.manager.PluginsManager.transaction_cancelation_requested")def test_request_cancelation_action_on_order(- mocked_transaction_request, mocked_is_active, order, staff_user+ mocked_transaction_request,+ mocked_is_active,+ order,+ staff_user,+ app,+ permission_manage_payments,):# given+ app.permissions.add(permission_manage_payments)+ webhook = app.webhooks.create(+ name="Simple webhook", app=app, target_url="http://127.0.0.1"+ )+ webhook.events.create(+ event_type=WebhookEventSyncType.TRANSACTION_CANCELATION_REQUESTED+ )+transaction = TransactionItem.objects.create(- status="Authorized",name="Credit card",psp_reference="PSP ref",- available_actions=["capture", "void"],+ available_actions=["capture", "cancel"],currency="USD",order_id=order.pk,authorized_value=Decimal("10"),+ app=app,)requested_event = transaction.events.create(currency=transaction.currency,@@ -964,7 +943,7 @@ def test_request_cancelation_action_on_order(action_type=TransactionAction.CANCEL,action_value=None,event=requested_event,- transaction_app_owner=None,+ transaction_app_owner=app,),order.channel.slug,)@@ -976,70 +955,32 @@ def test_request_cancelation_action_on_order(@patch("saleor.plugins.manager.PluginsManager.is_event_active_for_any_plugin")-@patch("saleor.plugins.manager.PluginsManager.transaction_action_request")-def test_request_cancelation_action_with_transaction_action_request(- mocked_transaction_request, mocked_is_active, order, staff_user+@patch("saleor.plugins.manager.PluginsManager.transaction_cancelation_requested")+def test_request_cancelation_action_by_app(+ mocked_transaction_request,+ mocked_is_active,+ order,+ app,+ webhook_app,+ permission_manage_payments,):# given- transaction = TransactionItem.objects.create(- status="Authorized",- name="Credit card",- psp_reference="PSP ref",- available_actions=["capture", "void"],- currency="USD",- order_id=order.pk,- authorized_value=Decimal("10"),+ webhook_app.permissions.add(permission_manage_payments)+ webhook = webhook_app.webhooks.create(+ name="Simple webhook", target_url="http://127.0.0.1")- requested_event = transaction.events.create(- currency=transaction.currency, type=TransactionEventType.CANCEL_REQUEST+ webhook.events.create(+ event_type=WebhookEventSyncType.TRANSACTION_CANCELATION_REQUESTED)- mocked_is_active.side_effect = [True, False]- # when- request_cancelation_action(- transaction=transaction,- manager=get_plugins_manager(),- cancel_value=None,- channel_slug=order.channel.slug,- user=staff_user,- app=None,- request_event=requested_event,- action=TransactionAction.CANCEL,- )-- # then- assert mocked_is_active.called- mocked_transaction_request.assert_called_once_with(- TransactionActionData(- transaction=transaction,- action_type=TransactionAction.CANCEL,- action_value=None,- event=requested_event,- transaction_app_owner=None,- ),- channel_slug=order.channel.slug,- )-- event = order.events.first()- assert event.type == OrderEvents.TRANSACTION_CANCEL_REQUESTED- assert event.parameters["reference"] == transaction.psp_reference- assert event.user == staff_user---@patch("saleor.plugins.manager.PluginsManager.is_event_active_for_any_plugin")-@patch("saleor.plugins.manager.PluginsManager.transaction_cancelation_requested")-def test_request_cancelation_action_by_app(- mocked_transaction_request, mocked_is_active, order, app-):- # giventransaction = TransactionItem.objects.create(- status="Authorized",name="Credit card",psp_reference="PSP ref",- available_actions=["capture", "void"],+ available_actions=["capture", "cancel"],currency="USD",order_id=order.pk,authorized_value=Decimal("10"),+ app=webhook_app,)requested_event = transaction.events.create(currency=transaction.currency, type=TransactionEventType.CANCEL_REQUEST@@ -1066,7 +1007,7 @@ def test_request_cancelation_action_by_app(action_type=TransactionAction.CANCEL,action_value=None,event=requested_event,- transaction_app_owner=None,+ transaction_app_owner=webhook_app,),order.channel.slug,)@@ -1081,17 +1022,30 @@ def test_request_cancelation_action_by_app(@patch("saleor.plugins.manager.PluginsManager.is_event_active_for_any_plugin")@patch("saleor.plugins.manager.PluginsManager.transaction_cancelation_requested")def test_request_cancelation_action_on_checkout(- mocked_transaction_request, mocked_is_active, checkout, staff_user+ mocked_transaction_request,+ mocked_is_active,+ checkout,+ staff_user,+ app,+ permission_manage_payments,):# given+ app.permissions.add(permission_manage_payments)+ webhook = app.webhooks.create(+ name="Simple webhook", app=app, target_url="http://127.0.0.1"+ )+ webhook.events.create(+ event_type=WebhookEventSyncType.TRANSACTION_CANCELATION_REQUESTED+ )+transaction = TransactionItem.objects.create(- status="Authorized",name="Credit card",psp_reference="PSP ref",- available_actions=["capture", "void"],+ available_actions=["capture", "cancel"],currency="USD",checkout_id=checkout.pk,authorized_value=Decimal("10"),+ app=app,)requested_event = transaction.events.create(currency=transaction.currency,@@ -1119,7 +1073,7 @@ def test_request_cancelation_action_on_checkout(action_type=TransactionAction.CANCEL,action_value=None,event=requested_event,- transaction_app_owner=None,+ transaction_app_owner=app,),checkout.channel.slug,)diff --git a/saleor/plugins/base_plugin.py b/saleor/plugins/base_plugin.pyindex cd7901c974..8b1adb96e7 100644--- a/saleor/plugins/base_plugin.py+++ b/saleor/plugins/base_plugin.py@@ -831,8 +831,6 @@ class BasePlugin:process_payment: Callable[["PaymentData", Any], Any]- transaction_action_request: Callable[["TransactionActionData", None], None]-transaction_charge_requested: Callable[["TransactionActionData", None], None]transaction_cancelation_requested: Callable[["TransactionActionData", None], None]diff --git a/saleor/plugins/manager.py b/saleor/plugins/manager.pyindex e10e5a3eea..6553b892dc 100644--- a/saleor/plugins/manager.py+++ b/saleor/plugins/manager.py@@ -971,17 +971,6 @@ class PluginsManager(PaymentInterface):"permission_group_deleted", default_value, group)- def transaction_action_request(- self, payment_data: "TransactionActionData", channel_slug: str- ):- default_value = None- return self.__run_method_on_plugins(- "transaction_action_request",- default_value,- payment_data,- channel_slug=channel_slug,- )-def transaction_charge_requested(self, payment_data: "TransactionActionData", channel_slug: str):diff --git a/saleor/plugins/webhook/plugin.py b/saleor/plugins/webhook/plugin.pyindex dc27a34c6e..51b21cb11b 100644--- a/saleor/plugins/webhook/plugin.py+++ b/saleor/plugins/webhook/plugin.py@@ -52,7 +52,6 @@ from ...webhook.payloads import (generate_sale_payload,generate_sale_toggle_payload,generate_thumbnail_payload,- generate_transaction_action_request_payload,generate_transaction_session_payload,generate_translation_payload,)@@ -1538,24 +1537,6 @@ class WebhookPlugin(BasePlugin):delivery_update(delivery, status=EventDeliveryStatus.PENDING)send_webhook_request_async.delay(delivery.pk)- def transaction_action_request(- self, transaction_data: "TransactionActionData", previous_value: None- ) -> None:- if not self.active:- return previous_value- event_type = WebhookEventAsyncType.TRANSACTION_ACTION_REQUEST- if webhooks := get_webhooks_for_event(event_type):- payload = generate_transaction_action_request_payload(- transaction_data, self.requestor- )- trigger_webhooks_async(- payload,- event_type,- webhooks,- subscribable_object=transaction_data,- requestor=self.requestor,- )-def _request_transaction_action(self,transaction_data: "TransactionActionData",@@ -2095,9 +2076,6 @@ class WebhookPlugin(BasePlugin):def is_event_active(self, event: str, channel=Optional[str]):map_event = {"invoice_request": WebhookEventAsyncType.INVOICE_REQUESTED,- "transaction_action_request": (- WebhookEventAsyncType.TRANSACTION_ACTION_REQUEST- ),}if event in map_event:diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/test_create_deliveries_for_transaction_action_request_subscription.py b/saleor/plugins/webhook/tests/subscription_webhooks/test_create_deliveries_for_transaction_action_request_subscription.pydeleted file mode 100644index 7c54719a1e..0000000000--- a/saleor/plugins/webhook/tests/subscription_webhooks/test_create_deliveries_for_transaction_action_request_subscription.py+++ /dev/null@@ -1,272 +0,0 @@-import json-from decimal import Decimal--import graphene-from freezegun import freeze_time--from .....core.prices import quantize_price-from .....payment import TransactionAction, TransactionEventType-from .....payment.interface import TransactionActionData-from .....payment.models import TransactionItem-from .....webhook.event_types import WebhookEventAsyncType-from .....webhook.models import Webhook-from ...tasks import create_deliveries_for_subscriptions--TRANSACTION_ACTION_REQUEST_SUBSCRIPTION_QUERY = """-subscription{- event{- ... on TransactionActionRequest{- transaction{- id- createdAt- actions- authorizedAmount{- currency- amount- }- refundedAmount{- currency- amount- }- voidedAmount{- currency- amount- }- chargedAmount{- currency- amount- }- events{- id- }- status- type- pspReference- reference- order {- id- }- }- action{- actionType- amount- }- }- }-}-"""---@freeze_time("2020-03-18 12:00:00")-def test_transaction_refund_action_request(- order, webhook_app, permission_manage_payments-):- # given- charged_value = Decimal("10")- webhook_app.permissions.add(permission_manage_payments)- transaction = TransactionItem.objects.create(- status="Captured",- name="Credit card",- psp_reference="PSP ref",- available_actions=["refund"],- currency="USD",- order_id=order.pk,- charged_value=charged_value,- )- action_value = Decimal("5.00")- request_event = transaction.events.create(- amount_value=action_value,- currency=transaction.currency,- type=TransactionEventType.REFUND_REQUEST,- )- webhook = Webhook.objects.create(- name="Webhook",- app=webhook_app,- target_url="http://www.example.com/any",- subscription_query=TRANSACTION_ACTION_REQUEST_SUBSCRIPTION_QUERY,- )- event_type = WebhookEventAsyncType.TRANSACTION_ACTION_REQUEST- webhook.events.create(event_type=event_type)-- transaction_id = graphene.Node.to_global_id("TransactionItem", transaction.token)- transaction_data = TransactionActionData(- transaction=transaction,- action_type=TransactionAction.REFUND,- action_value=action_value,- event=request_event,- transaction_app_owner=None,- )- # when- deliveries = create_deliveries_for_subscriptions(- event_type, transaction_data, [webhook]- )-- # then- assert json.loads(deliveries[0].payload.payload) == {- "transaction": {- "id": transaction_id,- "createdAt": "2020-03-18T12:00:00+00:00",- "actions": ["REFUND"],- "authorizedAmount": {"currency": "USD", "amount": 0.0},- "refundedAmount": {"currency": "USD", "amount": 0.0},- "voidedAmount": {"currency": "USD", "amount": 0.0},- "chargedAmount": {- "currency": "USD",- "amount": float(quantize_price(charged_value, "USD")),- },- "events": [- {"id": graphene.Node.to_global_id("TransactionEvent", request_event.id)}- ],- "status": "Captured",- "type": "Credit card",- "reference": "PSP ref",- "pspReference": "PSP ref",- "order": {"id": graphene.Node.to_global_id("Order", order.id)},- },- "action": {- "actionType": "REFUND",- "amount": float(quantize_price(action_value, "USD")),- },- }---@freeze_time("2020-03-18 12:00:00")-def test_transaction_charge_action_request(- order, webhook_app, permission_manage_payments-):- # given- authorized_value = Decimal("10")- webhook_app.permissions.add(permission_manage_payments)- transaction = TransactionItem.objects.create(- status="Authorized",- name="Credit card",- psp_reference="PSP ref",- available_actions=["charge"],- currency="USD",- order_id=order.pk,- authorized_value=authorized_value,- )- request_event = transaction.events.create(- amount_value=authorized_value,- currency=transaction.currency,- type=TransactionEventType.CHARGE_REQUEST,- )- webhook = Webhook.objects.create(- name="Webhook",- app=webhook_app,- target_url="http://www.example.com/any",- subscription_query=TRANSACTION_ACTION_REQUEST_SUBSCRIPTION_QUERY,- )- event_type = WebhookEventAsyncType.TRANSACTION_ACTION_REQUEST- webhook.events.create(event_type=event_type)-- transaction_id = graphene.Node.to_global_id("TransactionItem", transaction.token)- action_value = Decimal("5.00")- transaction_data = TransactionActionData(- transaction=transaction,- action_type=TransactionAction.CHARGE,- action_value=action_value,- event=request_event,- transaction_app_owner=None,- )- # when- deliveries = create_deliveries_for_subscriptions(- event_type, transaction_data, [webhook]- )-- # then- assert json.loads(deliveries[0].payload.payload) == {- "transaction": {- "id": transaction_id,- "createdAt": "2020-03-18T12:00:00+00:00",- "actions": ["CHARGE"],- "authorizedAmount": {- "currency": "USD",- "amount": quantize_price(authorized_value, "USD"),- },- "refundedAmount": {"currency": "USD", "amount": 0.0},- "voidedAmount": {"currency": "USD", "amount": 0.0},- "chargedAmount": {"currency": "USD", "amount": 0.0},- "events": [- {"id": graphene.Node.to_global_id("TransactionEvent", request_event.id)}- ],- "status": "Authorized",- "type": "Credit card",- "reference": "PSP ref",- "pspReference": "PSP ref",- "order": {"id": graphene.Node.to_global_id("Order", order.id)},- },- "action": {- "actionType": "CHARGE",- "amount": quantize_price(action_value, "USD"),- },- }---@freeze_time("2020-03-18 12:00:00")-def test_transaction_void_action_request(- order, webhook_app, permission_manage_payments-):- # given- authorized_value = Decimal("10")- webhook_app.permissions.add(permission_manage_payments)- transaction = TransactionItem.objects.create(- status="Captured",- name="Credit card",- psp_reference="PSP ref",- available_actions=["void"],- currency="USD",- order_id=order.pk,- authorized_value=authorized_value,- )- request_event = transaction.events.create(- amount_value=authorized_value,- currency=transaction.currency,- type=TransactionEventType.CANCEL_REQUEST,- )- webhook = Webhook.objects.create(- name="Webhook",- app=webhook_app,- target_url="http://www.example.com/any",- subscription_query=TRANSACTION_ACTION_REQUEST_SUBSCRIPTION_QUERY,- )- event_type = WebhookEventAsyncType.TRANSACTION_ACTION_REQUEST- webhook.events.create(event_type=event_type)-- transaction_id = graphene.Node.to_global_id("TransactionItem", transaction.token)-- transaction_data = TransactionActionData(- transaction=transaction,- action_type=TransactionAction.VOID,- event=request_event,- transaction_app_owner=None,- )- # when- deliveries = create_deliveries_for_subscriptions(- event_type, transaction_data, [webhook]- )-- # then- assert json.loads(deliveries[0].payload.payload) == {- "transaction": {- "id": transaction_id,- "createdAt": "2020-03-18T12:00:00+00:00",- "actions": ["VOID"],- "authorizedAmount": {- "currency": "USD",- "amount": quantize_price(authorized_value, "USD"),- },- "refundedAmount": {"currency": "USD", "amount": 0.0},- "voidedAmount": {"currency": "USD", "amount": 0.0},- "chargedAmount": {"currency": "USD", "amount": 0.0},- "events": [- {"id": graphene.Node.to_global_id("TransactionEvent", request_event.id)}- ],- "status": "Captured",- "type": "Credit card",- "reference": "PSP ref",- "pspReference": "PSP ref",- "order": {"id": graphene.Node.to_global_id("Order", order.id)},- },- "action": {"actionType": "VOID", "amount": None},- }diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/test_create_deliveries_for_transaction_cancelation_requested.py b/saleor/plugins/webhook/tests/subscription_webhooks/test_create_deliveries_for_transaction_cancelation_requested.pyindex 720c1bc7e4..b75760de26 100644--- a/saleor/plugins/webhook/tests/subscription_webhooks/test_create_deliveries_for_transaction_cancelation_requested.py+++ b/saleor/plugins/webhook/tests/subscription_webhooks/test_create_deliveries_for_transaction_cancelation_requested.py@@ -34,15 +34,14 @@ subscription {@freeze_time("2020-03-18 12:00:00")-def test_transaction_void_request(order, webhook_app, permission_manage_payments):+def test_transaction_cancel_request(order, webhook_app, permission_manage_payments):# givenauthorized_value = Decimal("10")webhook_app.permissions.add(permission_manage_payments)transaction = TransactionItem.objects.create(- status="Captured",name="Credit card",psp_reference="PSP ref",- available_actions=["void"],+ available_actions=["cancel"],currency="USD",order_id=order.pk,authorized_value=authorized_value,@@ -66,7 +65,7 @@ def test_transaction_void_request(order, webhook_app, permission_manage_paymentstransaction_data = TransactionActionData(transaction=transaction,- action_type=TransactionAction.VOID,+ action_type=TransactionAction.CANCEL,event=request_event,transaction_app_owner=None,)@@ -80,22 +79,19 @@ def test_transaction_void_request(order, webhook_app, permission_manage_payments"transaction": {"id": transaction_id,"createdAt": "2020-03-18T12:00:00+00:00",- "actions": ["VOID"],+ "actions": ["CANCEL"],"authorizedAmount": {"currency": "USD","amount": quantize_price(authorized_value, "USD"),},"refundedAmount": {"currency": "USD", "amount": 0.0},- "voidedAmount": {"currency": "USD", "amount": 0.0},+ "canceledAmount": {"currency": "USD", "amount": 0.0},"chargedAmount": {"currency": "USD", "amount": 0.0},"events": [{"id": graphene.Node.to_global_id("TransactionEvent", request_event.id)}],- "status": "Captured",- "type": "Credit card",- "reference": "PSP ref","pspReference": "PSP ref","order": {"id": graphene.Node.to_global_id("Order", order.id)},},- "action": {"actionType": "VOID", "amount": None},+ "action": {"actionType": "CANCEL", "amount": None},}diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/test_create_deliveries_for_transaction_charge_requested.py b/saleor/plugins/webhook/tests/subscription_webhooks/test_create_deliveries_for_transaction_charge_requested.pyindex d54cb247c0..07ef57b81a 100644--- a/saleor/plugins/webhook/tests/subscription_webhooks/test_create_deliveries_for_transaction_charge_requested.py+++ b/saleor/plugins/webhook/tests/subscription_webhooks/test_create_deliveries_for_transaction_charge_requested.py@@ -39,7 +39,6 @@ def test_transaction_charge_request(order, webhook_app, permission_manage_paymenauthorized_value = Decimal("10")webhook_app.permissions.add(permission_manage_payments)transaction = TransactionItem.objects.create(- status="Authorized",name="Credit card",psp_reference="PSP ref",available_actions=["charge"],@@ -88,14 +87,11 @@ def test_transaction_charge_request(order, webhook_app, permission_manage_paymen"amount": quantize_price(authorized_value, "USD"),},"refundedAmount": {"currency": "USD", "amount": 0.0},- "voidedAmount": {"currency": "USD", "amount": 0.0},+ "canceledAmount": {"currency": "USD", "amount": 0.0},"chargedAmount": {"currency": "USD", "amount": 0.0},"events": [{"id": graphene.Node.to_global_id("TransactionEvent", request_event.id)}],- "status": "Authorized",- "type": "Credit card",- "reference": "PSP ref","pspReference": "PSP ref","order": {"id": graphene.Node.to_global_id("Order", order.id)},},diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/test_create_deliveries_for_transaction_refund_requested.py b/saleor/plugins/webhook/tests/subscription_webhooks/test_create_deliveries_for_transaction_refund_requested.pyindex a91ce91368..ff1e491cca 100644--- a/saleor/plugins/webhook/tests/subscription_webhooks/test_create_deliveries_for_transaction_refund_requested.py+++ b/saleor/plugins/webhook/tests/subscription_webhooks/test_create_deliveries_for_transaction_refund_requested.py@@ -74,7 +74,6 @@ def test_transaction_refund_request(order, webhook_app, permission_manage_paymencharged_value = Decimal("10")webhook_app.permissions.add(permission_manage_payments)transaction = TransactionItem.objects.create(- status="Captured",name="Credit card",psp_reference="PSP ref",available_actions=["refund"],@@ -120,7 +119,7 @@ def test_transaction_refund_request(order, webhook_app, permission_manage_paymen"actions": ["REFUND"],"authorizedAmount": {"currency": "USD", "amount": 0.0},"refundedAmount": {"currency": "USD", "amount": 0.0},- "voidedAmount": {"currency": "USD", "amount": 0.0},+ "canceledAmount": {"currency": "USD", "amount": 0.0},"chargedAmount": {"currency": "USD","amount": quantize_price(charged_value, "USD"),@@ -128,9 +127,6 @@ def test_transaction_refund_request(order, webhook_app, permission_manage_paymen"events": [{"id": graphene.Node.to_global_id("TransactionEvent", request_event.id)}],- "status": "Captured",- "type": "Credit card",- "reference": "PSP ref","pspReference": "PSP ref","order": {"id": graphene.Node.to_global_id("Order", order.id)},},@@ -149,7 +145,6 @@ def test_transaction_refund_request_with_granted_refund(charged_value = Decimal("10")webhook_app.permissions.add(permission_manage_payments)transaction = TransactionItem.objects.create(- status="Captured",name="Credit card",psp_reference="PSP ref",available_actions=["refund"],@@ -209,7 +204,7 @@ def test_transaction_refund_request_with_granted_refund("actions": ["REFUND"],"authorizedAmount": {"currency": "USD", "amount": 0.0},"refundedAmount": {"currency": "USD", "amount": 0.0},- "voidedAmount": {"currency": "USD", "amount": 0.0},+ "canceledAmount": {"amount": 0.0, "currency": "USD"},"chargedAmount": {"currency": "USD","amount": quantize_price(charged_value, "USD"),@@ -217,9 +212,6 @@ def test_transaction_refund_request_with_granted_refund("events": [{"id": graphene.Node.to_global_id("TransactionEvent", request_event.id)}],- "status": "Captured",- "type": "Credit card",- "reference": "PSP ref","pspReference": "PSP ref","order": {"id": graphene.Node.to_global_id("Order", order_with_lines.id)},},diff --git a/saleor/plugins/webhook/tests/test_tasks.py b/saleor/plugins/webhook/tests/test_tasks.pyindex e98127083f..675bf080e0 100644--- a/saleor/plugins/webhook/tests/test_tasks.py+++ b/saleor/plugins/webhook/tests/test_tasks.py@@ -791,7 +791,11 @@ def test_handle_transaction_request_task_with_available_actions(transaction.refresh_from_db()assert set(transaction.available_actions) == set(- ["charge", "refund", "cancel", "void"]+ [+ "charge",+ "refund",+ "cancel",+ ])mocked_post_request.assert_called_once_with(diff --git a/saleor/plugins/webhook/tests/test_webhook.py b/saleor/plugins/webhook/tests/test_webhook.pyindex 199c40a17a..d8f3aa2be1 100644--- a/saleor/plugins/webhook/tests/test_webhook.py+++ b/saleor/plugins/webhook/tests/test_webhook.py@@ -53,7 +53,6 @@ from ....webhook.payloads import (generate_product_variant_with_stock_payload,generate_sale_payload,generate_sale_toggle_payload,- generate_transaction_action_request_payload,)from ....webhook.utils import get_webhooks_for_eventfrom ...manager import get_plugins_manager@@ -1603,65 +1602,6 @@ def test_send_webhook_request_async_when_webhook_is_disabled(assert event_delivery.status == EventDeliveryStatus.FAILED-@freeze_time("1914-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_transaction_action_request(- mocked_webhook_trigger,- mocked_get_webhooks_for_event,- any_webhook,- settings,- order,- channel_USD,-):- # given- mocked_get_webhooks_for_event.return_value = [any_webhook]- settings.PLUGINS = ["saleor.plugins.webhook.plugin.WebhookPlugin"]- manager = get_plugins_manager()- transaction = TransactionItem.objects.create(- status="Authorized",- name="Credit card",- psp_reference="PSP ref",- available_actions=["capture", "void"],- currency="USD",- order_id=order.pk,- authorized_value=Decimal("10"),- )-- action_value = Decimal("5.00")-- request_event = transaction.events.create(- amount_value=action_value,- currency=transaction.currency,- type=TransactionEventType.CHARGE_REQUEST,- )-- transaction_action_data = TransactionActionData(- transaction=transaction,- action_type=TransactionAction.CHARGE,- action_value=action_value,- event=request_event,- transaction_app_owner=None,- )-- # when- manager.transaction_action_request(- transaction_action_data, channel_slug=channel_USD.slug- )-- # then- expected_data = generate_transaction_action_request_payload(- transaction_action_data,- )- mocked_webhook_trigger.assert_called_once_with(- expected_data,- WebhookEventAsyncType.TRANSACTION_ACTION_REQUEST,- [any_webhook],- subscribable_object=transaction_action_data,- requestor=ANY,- )--@freeze_time("1914-06-28 10:50")@mock.patch("saleor.plugins.webhook.plugin.get_webhooks_for_event")@mock.patch("saleor.plugins.webhook.plugin.trigger_transaction_request")@@ -1682,7 +1622,6 @@ def test_transaction_charge_requested(settings.PLUGINS = ["saleor.plugins.webhook.plugin.WebhookPlugin"]manager = get_plugins_manager()transaction = TransactionItem.objects.create(- status="Authorized",name="Credit card",psp_reference="PSP ref",available_actions=["capture", "void"],@@ -1735,7 +1674,6 @@ def test_transaction_refund_requested(settings.PLUGINS = ["saleor.plugins.webhook.plugin.WebhookPlugin"]manager = get_plugins_manager()transaction = TransactionItem.objects.create(- status="Authorized",name="Credit card",psp_reference="PSP ref",available_actions=[@@ -1790,7 +1728,6 @@ def test_transaction_cancelation_requested(settings.PLUGINS = ["saleor.plugins.webhook.plugin.WebhookPlugin"]manager = get_plugins_manager()transaction = TransactionItem.objects.create(- status="Authorized",name="Credit card",psp_reference="PSP ref",available_actions=[@@ -1897,17 +1834,13 @@ def test_send_webhook_request_async_when_max_retries_exceeded(mocked_observability.assert_called_once_with(attempt)- "event, expected_is_active",- (("invoice_request", False), ("transaction_action_request", True)),-)-def test_is_event_active(- event, expected_is_active, settings, webhook, permission_manage_payments-):+def test_is_event_active(settings, webhook, permission_manage_orders):# given+ event = "invoice_request"+ expected_is_active = Truesettings.PLUGINS = ["saleor.plugins.webhook.plugin.WebhookPlugin"]- webhook.app.permissions.add(permission_manage_payments)- webhook.events.create(event_type=WebhookEventAsyncType.TRANSACTION_ACTION_REQUEST)+ webhook.app.permissions.add(permission_manage_orders)+ webhook.events.create(event_type=WebhookEventAsyncType.INVOICE_REQUESTED)manager = get_plugins_manager()diff --git a/saleor/tests/fixtures.py b/saleor/tests/fixtures.pyindex d3800e07e3..9f55df8a51 100644--- a/saleor/tests/fixtures.py+++ b/saleor/tests/fixtures.py@@ -316,7 +316,6 @@ def checkout_with_item(checkout, product):@pytest.fixturedef checkout_with_item_and_transaction_item(checkout_with_item):TransactionItem.objects.create(- status="Captured",name="Credit card",psp_reference="PSP ref",available_actions=["refund"],diff --git a/saleor/webhook/event_types.py b/saleor/webhook/event_types.pyindex b959cb4ba0..9a087c786d 100644--- a/saleor/webhook/event_types.py+++ b/saleor/webhook/event_types.py@@ -154,7 +154,6 @@ class WebhookEventAsyncType:STAFF_UPDATED = "staff_updated"STAFF_DELETED = "staff_deleted"- TRANSACTION_ACTION_REQUEST = "transaction_action_request"TRANSACTION_ITEM_METADATA_UPDATED = "transaction_item_metadata_updated"TRANSLATION_CREATED = "translation_created"@@ -283,7 +282,6 @@ class WebhookEventAsyncType:STAFF_CREATED: "Staff created",STAFF_UPDATED: "Staff updated",STAFF_DELETED: "Staff deleted",- TRANSACTION_ACTION_REQUEST: "Payment action request",TRANSACTION_ITEM_METADATA_UPDATED: "Transaction item metadata updated",TRANSLATION_CREATED: "Create translation",TRANSLATION_UPDATED: "Update translation",@@ -420,7 +418,6 @@ class WebhookEventAsyncType:(STAFF_CREATED, DISPLAY_LABELS[STAFF_CREATED]),(STAFF_UPDATED, DISPLAY_LABELS[STAFF_UPDATED]),(STAFF_DELETED, DISPLAY_LABELS[STAFF_DELETED]),- (TRANSACTION_ACTION_REQUEST, DISPLAY_LABELS[TRANSACTION_ACTION_REQUEST]),(TRANSACTION_ITEM_METADATA_UPDATED,DISPLAY_LABELS[TRANSACTION_ITEM_METADATA_UPDATED],@@ -549,7 +546,6 @@ class WebhookEventAsyncType:STAFF_CREATED: AccountPermissions.MANAGE_STAFF,STAFF_UPDATED: AccountPermissions.MANAGE_STAFF,STAFF_DELETED: AccountPermissions.MANAGE_STAFF,- TRANSACTION_ACTION_REQUEST: PaymentPermissions.HANDLE_PAYMENTS,TRANSACTION_ITEM_METADATA_UPDATED: PaymentPermissions.HANDLE_PAYMENTS,TRANSLATION_CREATED: SitePermissions.MANAGE_TRANSLATIONS,TRANSLATION_UPDATED: SitePermissions.MANAGE_TRANSLATIONS,diff --git a/saleor/webhook/migrations/0010_drop_transaction_request_action_event.py b/saleor/webhook/migrations/0010_drop_transaction_request_action_event.pynew file mode 100644index 0000000000..7b30c0b69d--- /dev/null+++ b/saleor/webhook/migrations/0010_drop_transaction_request_action_event.py@@ -0,0 +1,21 @@+from django.db import migrations+++def drop_transaction_action_request(apps, _schema_editor):+ WebhookEvent = apps.get_model("webhook", "WebhookEvent")+ # transaction_action_request was the webhook for triggering the actions like a+ # refund, charge or cancel in asynchronous mode. The number of records here will+ # be from 0 to max +/- 10.+ WebhookEvent.objects.filter(event_type="transaction_action_request").delete()+++class Migration(migrations.Migration):+ dependencies = [+ ("webhook", "0009_webhook_custom_headers"),+ ]++ operations = [+ migrations.RunPython(+ drop_transaction_action_request, reverse_code=migrations.RunPython.noop+ )+ ]diff --git a/saleor/webhook/payloads.py b/saleor/webhook/payloads.pyindex 2c22e22d23..afb92652c9 100644--- a/saleor/webhook/payloads.py+++ b/saleor/webhook/payloads.py@@ -1469,7 +1469,6 @@ def generate_transaction_action_request_payload("currency": transaction.currency,},"transaction": {- "status": transaction.status,"type": transaction.name,"name": transaction.name,"message": transaction.message,@@ -1486,9 +1485,6 @@ def generate_transaction_action_request_payload("refunded_value": quantize_price(transaction.refunded_value, transaction.currency),- "voided_value": quantize_price(- transaction.canceled_value, transaction.currency- ),"canceled_value": quantize_price(transaction.canceled_value, transaction.currency),diff --git a/saleor/webhook/tests/test_webhook_payloads.py b/saleor/webhook/tests/test_webhook_payloads.pyindex 9d511853e6..19acb9f296 100644--- a/saleor/webhook/tests/test_webhook_payloads.py+++ b/saleor/webhook/tests/test_webhook_payloads.py@@ -2112,7 +2112,7 @@ GROSS_AMOUNT = sentinel.GROSS_AMOUNT[(TransactionAction.CHARGE, Decimal("5.000")),(TransactionAction.REFUND, Decimal("9.000")),- (TransactionAction.VOID, None),+ (TransactionAction.CANCEL, None),],)@freeze_time("1914-06-28 10:50")@@ -2126,10 +2126,9 @@ def test_generate_transaction_action_request_payload_for_order(requestor = get_user_or_app_from_context(request)transaction = TransactionItem.objects.create(- status="Authorized",name="Credit card",psp_reference="PSP ref",- available_actions=["capture", "void"],+ available_actions=["capture", "cancel"],currency="USD",order_id=order.pk,authorized_value=Decimal("10"),@@ -2163,7 +2162,6 @@ def test_generate_transaction_action_request_payload_for_order("currency": currency,},"transaction": {- "status": transaction.status,"type": transaction.name,"name": transaction.name,"message": transaction.message,@@ -2176,7 +2174,6 @@ def test_generate_transaction_action_request_payload_for_order(quantize_price(transaction.authorized_value, currency)),"refunded_value": str(quantize_price(transaction.refunded_value, currency)),- "voided_value": str(quantize_price(transaction.canceled_value, currency)),"canceled_value": str(quantize_price(transaction.canceled_value, currency)),"order_id": graphene.Node.to_global_id("Order", order.pk),"checkout_id": None,@@ -2206,7 +2203,7 @@ def test_generate_transaction_action_request_payload_for_order(TransactionEventType.REFUND_REQUEST,Decimal("9.000"),),- (TransactionAction.VOID, TransactionEventType.CANCEL_REQUEST, None),+ (TransactionAction.CANCEL, TransactionEventType.CANCEL_REQUEST, None),],)@freeze_time("1914-06-28 10:50")@@ -2220,10 +2217,9 @@ def test_generate_transaction_action_request_payload_for_checkout(requestor = get_user_or_app_from_context(request)transaction = TransactionItem.objects.create(- status="Authorized",name="Credit card",psp_reference="PSP ref",- available_actions=["capture", "void"],+ available_actions=["capture", "cancel"],currency="USD",checkout_id=checkout.pk,authorized_value=Decimal("10"),@@ -2257,7 +2253,6 @@ def test_generate_transaction_action_request_payload_for_checkout("currency": currency,},"transaction": {- "status": transaction.status,"type": transaction.name,"name": transaction.name,"message": transaction.message,@@ -2270,7 +2265,6 @@ def test_generate_transaction_action_request_payload_for_checkout(quantize_price(transaction.authorized_value, currency)),"refunded_value": str(quantize_price(transaction.refunded_value, currency)),- "voided_value": str(quantize_price(transaction.canceled_value, currency)),"canceled_value": str(quantize_price(transaction.canceled_value, currency)),"order_id": None,"checkout_id": graphene.Node.to_global_id("Checkout", checkout.pk),