Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add manager parameter to is_currency_supported method
IKarbowiak0811a11d00c3
diff --git a/saleor/graphql/payment/mutations.py b/saleor/graphql/payment/mutations.pyindex e49616c1b1..48ee01dfe8 100644--- a/saleor/graphql/payment/mutations.py+++ b/saleor/graphql/payment/mutations.py@@ -79,8 +79,8 @@ class CheckoutPaymentCreate(BaseMutation, I18nMixin):)@classmethod- def validate_gateway(cls, gateway_id, currency):- if not is_currency_supported(currency, gateway_id):+ def validate_gateway(cls, manager, gateway_id, currency):+ if not is_currency_supported(currency, gateway_id, manager):raise ValidationError({"gateway": ValidationError(@@ -124,11 +124,11 @@ class CheckoutPaymentCreate(BaseMutation, I18nMixin):data = data["input"]gateway = data["gateway"]- cls.validate_gateway(gateway, checkout.currency)- cls.validate_token(info.context.plugins, gateway, data)+ manager = info.context.plugins+ cls.validate_gateway(manager, gateway, checkout.currency)+ cls.validate_token(manager, gateway, data)cls.validate_return_url(data)- manager = info.context.pluginslines = fetch_checkout_lines(checkout)checkout_info = fetch_checkout_info(checkout, lines, info.context.discounts, managerdiff --git a/saleor/payment/tests/test_payment.py b/saleor/payment/tests/test_payment.pyindex 3333f2c8d5..fc0476ca3e 100644--- a/saleor/payment/tests/test_payment.py+++ b/saleor/payment/tests/test_payment.py@@ -482,6 +482,7 @@ def test_is_currency_supported(currency, exp_response, dummy_gateway_config, monkeypatch):# given+ manager = get_plugins_manager()dummy_gateway_config.supported_currencies = "USD, EUR"monkeypatch.setattr("saleor.payment.gateways.dummy.plugin.DummyGatewayPlugin._get_gateway_config",@@ -489,7 +490,7 @@ def test_is_currency_supported()# when- response = is_currency_supported(currency, "mirumee.payments.dummy")+ response = is_currency_supported(currency, "mirumee.payments.dummy", manager)# thenassert response == exp_responsediff --git a/saleor/payment/utils.py b/saleor/payment/utils.pyindex 9407774291..4fab2a88cc 100644--- a/saleor/payment/utils.py+++ b/saleor/payment/utils.py@@ -1,7 +1,7 @@import jsonimport loggingfrom decimal import Decimal-from typing import Dict, Optional+from typing import TYPE_CHECKING, Dict, Optionalimport graphenefrom django.core.serializers.json import DjangoJSONEncoder@@ -10,12 +10,14 @@ from django.db import transactionfrom ..account.models import Userfrom ..checkout.models import Checkoutfrom ..order.models import Order-from ..plugins.manager import get_plugins_managerfrom . import ChargeStatus, GatewayError, PaymentError, TransactionKindfrom .error_codes import PaymentErrorCodefrom .interface import AddressData, GatewayResponse, PaymentDatafrom .models import Payment, Transaction+if TYPE_CHECKING:+ from ..plugins.manager import PluginsManager+logger = logging.getLogger(__name__)GENERIC_TRANSACTION_ERROR = "Transaction was unsuccessful"@@ -359,7 +361,7 @@ def get_payment_token(payment: Payment):return auth_transaction.token-def is_currency_supported(currency: str, gateway_id: str):+def is_currency_supported(currency: str, gateway_id: str, manager: "PluginsManager"):"""Return true if the given gateway supports given currency."""- available_gateways = get_plugins_manager().list_payment_gateways(currency=currency)+ available_gateways = manager.list_payment_gateways(currency=currency)return any([gateway.id == gateway_id for gateway in available_gateways])