Skip to content

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

Fix TypeError when availableActions null is provided to transactionCreate (#15999)

Tomasz Szymański46d26a91a68b
diff --git a/saleor/graphql/payment/mutations/transaction/transaction_create.py b/saleor/graphql/payment/mutations/transaction/transaction_create.py
index 2a10318b19..45cb453ba4 100644
--- a/saleor/graphql/payment/mutations/transaction/transaction_create.py
+++ b/saleor/graphql/payment/mutations/transaction/transaction_create.py
@@ -239,6 +239,8 @@ class TransactionCreate(BaseMutation):
transaction.get("external_url"),
error_code=TransactionCreateErrorCode.INVALID.value,
)
+ if "available_actions" in transaction and not transaction["available_actions"]:
+ transaction.pop("available_actions")
return instance
@classmethod
diff --git a/saleor/graphql/payment/tests/mutations/test_transaction_create.py b/saleor/graphql/payment/tests/mutations/test_transaction_create.py
index 186f34daa4..4b4f7fe758 100644
--- a/saleor/graphql/payment/tests/mutations/test_transaction_create.py
+++ b/saleor/graphql/payment/tests/mutations/test_transaction_create.py
@@ -2016,3 +2016,29 @@ def test_transaction_create_for_checkout_updates_last_transaction_modified_at(
transaction = checkout_with_items.payment_transactions.first()
assert checkout_with_items.last_transaction_modified_at == transaction.modified_at
+
+
+def test_transaction_create_null_available_actions(
+ checkout_with_items, permission_manage_payments, app_api_client
+):
+ # given
+ authorized_value = Decimal("10")
+ variables = {
+ "id": graphene.Node.to_global_id("Checkout", checkout_with_items.pk),
+ "transaction": {
+ "pspReference": "PSP reference - 123",
+ "availableActions": None,
+ "amountAuthorized": {
+ "amount": authorized_value,
+ "currency": "USD",
+ },
+ },
+ }
+
+ # when
+ app_api_client.post_graphql(
+ MUTATION_TRANSACTION_CREATE, variables, permissions=[permission_manage_payments]
+ )
+
+ # then
+ assert checkout_with_items.payment_transactions.first().available_actions == []