Skip to content

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

Move gateway meta utils to payment module

Jakub Draganek50abb271fed4
diff --git a/saleor/graphql/payment/resolvers.py b/saleor/graphql/payment/resolvers.py
index 295b34f72a..7cb2cbf140 100644
--- a/saleor/graphql/payment/resolvers.py
+++ b/saleor/graphql/payment/resolvers.py
@@ -2,8 +2,8 @@ import graphene_django_optimizer as gql_optimizer
from ...payment import models
from ...payment.interface import TokenConfig
-from ...payment.utils import gateway_get_client_token
-from ..utils import extract_id_for_payment_gateway, filter_by_query_param
+from ...payment.utils import gateway_get_client_token, extract_id_for_payment_gateway
+from ..utils import filter_by_query_param
PAYMENT_SEARCH_FIELDS = ["id"]
diff --git a/saleor/graphql/utils.py b/saleor/graphql/utils.py
index 2de06cbd70..b9d78d9dfb 100644
--- a/saleor/graphql/utils.py
+++ b/saleor/graphql/utils.py
@@ -148,25 +148,3 @@ def format_permissions_for_display(permissions):
PermissionDisplay(code=PermissionEnum.get(codename), name=permission.name)
)
return formatted_permissions
-
-
-GATEWAYS_LABEL = "gateways"
-
-
-def extract_id_for_payment_gateway(user, gateway):
- gateway_meta = user.get_private_meta(label=GATEWAYS_LABEL)
- if not gateway_meta:
- return None
- if gateway not in gateway_meta:
- return None
- gateway_config = gateway_meta[gateway]
- if "customer_id" not in gateway_config:
- return None
- return gateway_config["customer_id"]
-
-
-def store_id_for_payment_gateway(user, gateway, customer_id):
- user.store_private_meta(
- label=GATEWAYS_LABEL, key=gateway, value={"customer_id": customer_id}
- )
- user.save()
diff --git a/saleor/payment/utils.py b/saleor/payment/utils.py
index 2a94ee5904..6fe1db6ee2 100644
--- a/saleor/payment/utils.py
+++ b/saleor/payment/utils.py
@@ -500,3 +500,25 @@ def gateway_refund(payment, amount: Decimal = None) -> Transaction:
_gateway_postprocess(transaction, payment)
return transaction
+
+
+GATEWAYS_LABEL = "gateways"
+
+
+def extract_id_for_payment_gateway(user, gateway):
+ gateway_meta = user.get_private_meta(label=GATEWAYS_LABEL)
+ if not gateway_meta:
+ return None
+ if gateway not in gateway_meta:
+ return None
+ gateway_config = gateway_meta[gateway]
+ if "customer_id" not in gateway_config:
+ return None
+ return gateway_config["customer_id"]
+
+
+def store_id_for_payment_gateway(user, gateway, customer_id):
+ user.store_private_meta(
+ label=GATEWAYS_LABEL, key=gateway, value={"customer_id": customer_id}
+ )
+ user.save()
diff --git a/tests/api/test_payment.py b/tests/api/test_payment.py
index 131bb423ab..4a0aa46e61 100644
--- a/tests/api/test_payment.py
+++ b/tests/api/test_payment.py
@@ -12,7 +12,7 @@ from saleor.graphql.payment.enums import (
PaymentChargeStatusEnum,
PaymentGatewayEnum,
)
-from saleor.graphql.utils import (
+from saleor.payment.utils import (
extract_id_for_payment_gateway,
store_id_for_payment_gateway,
)