Repository: saleor/saleor

Issue:
Missing `currency` in action for transaction requests
## Problem

I want to easily fetch the currency when processing the webhooks like `TransactionChargeRequested`. Currently `action` doesn't have a ` currency` field. It means that I need to additionally fetch `transactions` to get a correct `currency`.

<!-- Describe what you are trying to achive. You can include proposed solution.  -->

---

## 1. General Assumptions
We will extend the `action` type to contain `currency` field. The same as we have for webhooks like  `TransactionInitializeSession` or `TransactionProcessSession`
<!--   -->

### Acceptance Criteria

<!-- Conditions that a feature must satisfy to be approved by QA
- Functional use case:
  - Permissions: As USER/APP with permision `XYZ' I should be able to 'action"
  - Webhooks: Webhook `name` event should be sent for every updated `instance name`
  - Support for old versions: After updating, it is possible to retrieve data created in older (3.1, 3.5, 3.7) Saleor versions.
  - Error handling: Should be handled according to 'policy_name'
  - Other use-cases: ID or externalReference can be used to identify object
- Non-functional use case
  - X objects can be updated in one mutation
-->

- [ ] `TransactionChargeRequested` has `action.currency` field 
- [ ] `TransactionRefundRequested` has `action.currency` field
- [ ] `TransactionCancelationRequested` has `action.currency` field

## 2. API changes

### Subscriptions
 `TransactionChargeRequested`, `TransactionRefundRequested`, `TransactionCancelationRequested` should receive a new field `currency` in `action` structure. 

```graphql
subscription {
  event{
    ... on TransactionChargeRequested{
      action{
        actionType
        amount
        # currency <-- missing
      }
    }
  }
}
```




Discussion:

Resolving patch:
diff --git a/saleor/graphql/webhook/subscription_types.py b/saleor/graphql/webhook/subscription_types.py
--- a/saleor/graphql/webhook/subscription_types.py
+++ b/saleor/graphql/webhook/subscription_types.py
@@ -1650,6 +1650,10 @@ class TransactionAction(SubscriptionObjectType, AbstractType):
     amount = PositiveDecimal(
         description="Transaction request amount. Null when action type is VOID.",
     )
+    currency = graphene.String(
+        description="Currency code." + ADDED_IN_316,
+        required=True,
+    )
 
     class Meta:
         doc_category = DOC_CATEGORY_PAYMENTS
@@ -1660,6 +1664,10 @@ def resolve_amount(root: TransactionActionData, _info: ResolveInfo):
             return quantize_price(root.action_value, root.transaction.currency)
         return None
 
+    @staticmethod
+    def resolve_currency(root: TransactionActionData, _info: ResolveInfo):
+        return root.transaction.currency
+
 
 class TransactionActionBase(AbstractType):
     transaction = graphene.Field(


Test patch:
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.py
--- 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
@@ -25,6 +25,7 @@
       action {
         actionType
         amount
+        currency
       }
     }
   }
@@ -93,5 +94,5 @@ def test_transaction_cancel_request(order, webhook_app, permission_manage_paymen
             "pspReference": "PSP ref",
             "order": {"id": graphene.Node.to_global_id("Order", order.id)},
         },
-        "action": {"actionType": "CANCEL", "amount": None},
+        "action": {"actionType": "CANCEL", "amount": None, "currency": "USD"},
     }
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.py
--- 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
@@ -25,6 +25,7 @@
       action {
         actionType
         amount
+        currency
       }
     }
   }
@@ -98,5 +99,6 @@ def test_transaction_charge_request(order, webhook_app, permission_manage_paymen
         "action": {
             "actionType": "CHARGE",
             "amount": quantize_price(action_value, "USD"),
+            "currency": "USD",
         },
     }
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.py
--- 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
@@ -25,6 +25,7 @@
       action {
         actionType
         amount
+        currency
       }
     }
   }
@@ -60,6 +61,7 @@
       action {
         actionType
         amount
+        currency
       }
     }
   }
@@ -133,6 +135,7 @@ def test_transaction_refund_request(order, webhook_app, permission_manage_paymen
         "action": {
             "actionType": "REFUND",
             "amount": quantize_price(action_value, "USD"),
+            "currency": "USD",
         },
     }
 
@@ -231,5 +234,6 @@ def test_transaction_refund_request_with_granted_refund(
         "action": {
             "actionType": "REFUND",
             "amount": 12.3,
+            "currency": "USD",
         },
     }