Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Update supported currencies in gateways, set default currency for dummy gateway
IKarbowiak601cc389f511
diff --git a/saleor/graphql/checkout/tests/test_checkout.py b/saleor/graphql/checkout/tests/test_checkout.pyindex 2d6c9875bc..001d076060 100644--- a/saleor/graphql/checkout/tests/test_checkout.py+++ b/saleor/graphql/checkout/tests/test_checkout.py@@ -1,5 +1,4 @@import uuid-import warningsfrom decimal import Decimalfrom unittest import mockfrom unittest.mock import ANY, patch@@ -579,16 +578,8 @@ def test_checkout_available_payment_gateways(api_client, checkout_with_item, expected_dummy_gateway):query = GET_CHECKOUT_PAYMENTS_QUERY- expected_warning = (- "Default currency used for Dummy. "- "DEFAULT_CURRENCY setting is deprecated, "- "please configure supported currencies for this gateway."- )variables = {"token": str(checkout_with_item.token)}- with warnings.catch_warnings(record=True) as warns:- response = api_client.post_graphql(query, variables)-- assert any([str(warning.message) == expected_warning for warning in warns])+ response = api_client.post_graphql(query, variables)content = get_graphql_content(response)data = content["data"]["checkout"]diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex a442f6f575..29d7c56c70 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -1167,7 +1167,6 @@ input ConfigurationItemInput {enum ConfigurationTypeFieldEnum {STRINGBOOLEAN- LISTSECRETPASSWORD}diff --git a/saleor/payment/gateways/braintree/plugin.py b/saleor/payment/gateways/braintree/plugin.pyindex 7dcd529800..1dd43b12c9 100644--- a/saleor/payment/gateways/braintree/plugin.py+++ b/saleor/payment/gateways/braintree/plugin.py@@ -43,7 +43,7 @@ class BraintreeGatewayPlugin(BasePlugin):{"name": "Store customers card", "value": False},{"name": "Automatic payment capture", "value": True},{"name": "Require 3D secure", "value": False},- {"name": "Supported currencies", "value": []},+ {"name": "Supported currencies", "value": ""},]CONFIG_STRUCTURE = {@@ -84,8 +84,9 @@ class BraintreeGatewayPlugin(BasePlugin):"label": "Require 3D secure",},"Supported currencies": {- "type": ConfigurationTypeField.LIST,- "help_text": "Determines currencies supported by gateway.",+ "type": ConfigurationTypeField.STRING,+ "help_text": "Determines currencies supported by gateway."+ " Please enter currencies separated by a comma.","label": "Supported currencies",},}diff --git a/saleor/payment/gateways/braintree/tests/test_braintree.py b/saleor/payment/gateways/braintree/tests/test_braintree.pyindex 95e789b3ba..8f5b67d45b 100644--- a/saleor/payment/gateways/braintree/tests/test_braintree.py+++ b/saleor/payment/gateways/braintree/tests/test_braintree.py@@ -84,7 +84,7 @@ def gateway_config():"public_key": "456","private_key": "789",},- supported_currencies=["USD"],+ supported_currencies="USD",)diff --git a/saleor/payment/gateways/dummy/plugin.py b/saleor/payment/gateways/dummy/plugin.pyindex 92dd4dc6bc..b66285dbe0 100644--- a/saleor/payment/gateways/dummy/plugin.py+++ b/saleor/payment/gateways/dummy/plugin.py@@ -1,5 +1,7 @@from typing import TYPE_CHECKING+from django.conf import settings+from saleor.plugins.base_plugin import BasePlugin, ConfigurationTypeFieldfrom ..utils import get_supported_currencies@@ -37,7 +39,7 @@ class DummyGatewayPlugin(BasePlugin):DEFAULT_CONFIGURATION = [{"name": "Store customers card", "value": False},{"name": "Automatic payment capture", "value": True},- {"name": "Supported currencies", "value": []},+ {"name": "Supported currencies", "value": settings.DEFAULT_CURRENCY},]CONFIG_STRUCTURE = {"Store customers card": {@@ -51,8 +53,9 @@ class DummyGatewayPlugin(BasePlugin):"label": "Automatic payment capture",},"Supported currencies": {- "type": ConfigurationTypeField.LIST,- "help_text": "Determines currencies supported by gateway.",+ "type": ConfigurationTypeField.STRING,+ "help_text": "Determines currencies supported by gateway."+ " Please enter currencies separated by a comma.","label": "Supported currencies",},}diff --git a/saleor/payment/gateways/razorpay/plugin.py b/saleor/payment/gateways/razorpay/plugin.pyindex a24d73dffa..6f2a3a1b9b 100644--- a/saleor/payment/gateways/razorpay/plugin.py+++ b/saleor/payment/gateways/razorpay/plugin.py@@ -29,7 +29,7 @@ class RazorpayGatewayPlugin(BasePlugin):{"name": "Secret API key", "value": None},{"name": "Store customers card", "value": False},{"name": "Automatic payment capture", "value": True},- {"name": "Supported currencies", "value": []},+ {"name": "Supported currencies", "value": ""},]CONFIG_STRUCTURE = {@@ -55,8 +55,9 @@ class RazorpayGatewayPlugin(BasePlugin):"label": "Automatic payment capture",},"Supported currencies": {- "type": ConfigurationTypeField.LIST,- "help_text": "Determines currencies supported by gateway.",+ "type": ConfigurationTypeField.STRING,+ "help_text": "Determines currencies supported by gateway."+ " Please enter currencies separated by a comma.","label": "Supported currencies",},}diff --git a/saleor/payment/gateways/razorpay/tests/test_razorpay.py b/saleor/payment/gateways/razorpay/tests/test_razorpay.pyindex 4ad625378d..277625eb86 100644--- a/saleor/payment/gateways/razorpay/tests/test_razorpay.py+++ b/saleor/payment/gateways/razorpay/tests/test_razorpay.py@@ -27,7 +27,7 @@ def gateway_config():return GatewayConfig(gateway_name="razorpay",auto_capture=False,- supported_currencies=["USD"],+ supported_currencies="USD",connection_params={"public_key": "public","private_key": "secret",diff --git a/saleor/payment/gateways/stripe/plugin.py b/saleor/payment/gateways/stripe/plugin.pyindex baca3ee948..d085c543a9 100644--- a/saleor/payment/gateways/stripe/plugin.py+++ b/saleor/payment/gateways/stripe/plugin.py@@ -39,7 +39,7 @@ class StripeGatewayPlugin(BasePlugin):{"name": "Secret API key", "value": None},{"name": "Store customers card", "value": False},{"name": "Automatic payment capture", "value": True},- {"name": "Supported currencies", "value": []},+ {"name": "Supported currencies", "value": ""},]CONFIG_STRUCTURE = {@@ -65,8 +65,9 @@ class StripeGatewayPlugin(BasePlugin):"label": "Automatic payment capture",},"Supported currencies": {- "type": ConfigurationTypeField.LIST,- "help_text": "Determines currencies supported by gateway.",+ "type": ConfigurationTypeField.STRING,+ "help_text": "Determines currencies supported by gateway."+ " Please enter currencies separated by a comma.","label": "Supported currencies",},}diff --git a/saleor/payment/gateways/stripe/tests/test_stripe.py b/saleor/payment/gateways/stripe/tests/test_stripe.pyindex af854f15aa..38c37b487d 100644--- a/saleor/payment/gateways/stripe/tests/test_stripe.py+++ b/saleor/payment/gateways/stripe/tests/test_stripe.py@@ -37,7 +37,7 @@ def gateway_config():return GatewayConfig(gateway_name="stripe",auto_capture=True,- supported_currencies=["USD"],+ supported_currencies="USD",connection_params={"public_key": "public","private_key": "secret",diff --git a/saleor/payment/gateways/utils.py b/saleor/payment/gateways/utils.pyindex 098cee018f..3dbfcd1f51 100644--- a/saleor/payment/gateways/utils.py+++ b/saleor/payment/gateways/utils.py@@ -1,3 +1,4 @@+import reimport warningsfrom typing import TYPE_CHECKING, List@@ -8,12 +9,15 @@ if TYPE_CHECKING:def get_supported_currencies(config: "GatewayConfig", gateway_name: str) -> List[str]:- currencies = config.supported_currencies- if not currencies:+ supp_currencies = config.supported_currencies+ if not supp_currencies:currencies = [settings.DEFAULT_CURRENCY]warnings.warn(f"Default currency used for {gateway_name}. ""DEFAULT_CURRENCY setting is deprecated, ""please configure supported currencies for this gateway.")+ else:+ currencies = re.split(r",\s*", supp_currencies)+return currenciesdiff --git a/saleor/payment/interface.py b/saleor/payment/interface.pyindex 6ef7296f76..7830f3428b 100644--- a/saleor/payment/interface.py+++ b/saleor/payment/interface.py@@ -1,6 +1,6 @@from dataclasses import dataclassfrom decimal import Decimal-from typing import Any, Dict, List, Optional+from typing import Any, Dict, Optional@dataclass@@ -86,7 +86,7 @@ class GatewayConfig:gateway_name: strauto_capture: bool- supported_currencies: List[str]+ supported_currencies: str# Each gateway has different connection data so we are not able to create# a unified structureconnection_params: Dict[str, Any]diff --git a/saleor/payment/tests/test_gateways_utils.py b/saleor/payment/tests/test_gateways_utils.pyindex 764a0a6f92..3c2f3c5ffd 100644--- a/saleor/payment/tests/test_gateways_utils.py+++ b/saleor/payment/tests/test_gateways_utils.py@@ -11,20 +11,30 @@ def gateway_config():return GatewayConfig(gateway_name="Dummy",auto_capture=True,- supported_currencies=[],+ supported_currencies="",connection_params={"secret-key": "dummy"},)-def test_get_supported_currencies(gateway_config):+ "supported_currencies, expected_currencies",+ [+ ("PLN, USD, EUR", ["PLN", "USD", "EUR"]),+ ("PLN,EUR", ["PLN", "EUR"]),+ ("USD", ["USD"]),+ ],+)+def test_get_supported_currencies(+ supported_currencies, expected_currencies, gateway_config+):# given- gateway_config.supported_currencies = ["PLN", "USD"]+ gateway_config.supported_currencies = supported_currencies# whencurrencies = get_supported_currencies(gateway_config, "Test")# then- assert currencies == ["PLN", "USD"]+ assert currencies == expected_currenciesdef test_get_supported_currencies_default_currency(gateway_config):diff --git a/saleor/payment/tests/test_payment.py b/saleor/payment/tests/test_payment.pyindex 7f443f141b..6a2be762f4 100644--- a/saleor/payment/tests/test_payment.py+++ b/saleor/payment/tests/test_payment.py@@ -64,7 +64,7 @@ def gateway_config():return GatewayConfig(gateway_name="Dummy",auto_capture=True,- supported_currencies=["USD"],+ supported_currencies="USD",connection_params={"secret-key": "nobodylikesspanishinqusition"},)diff --git a/saleor/plugins/base_plugin.py b/saleor/plugins/base_plugin.pyindex 23937c2d52..845f871436 100644--- a/saleor/plugins/base_plugin.py+++ b/saleor/plugins/base_plugin.py@@ -24,13 +24,11 @@ PluginConfigurationType = List[dict]class ConfigurationTypeField:STRING = "String"BOOLEAN = "Boolean"- LIST = "List"SECRET = "Secret"PASSWORD = "Password"CHOICES = [(STRING, "Field is a String"),(BOOLEAN, "Field is a Boolean"),- (LIST, "Field is a List"),(SECRET, "Field is a Secret"),(PASSWORD, "Field is a Password"),]