Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Allow to specified currency in availablePaymentGateways for shop
IKarbowiaka25eeab5c5c3
diff --git a/saleor/graphql/checkout/tests/test_checkout.py b/saleor/graphql/checkout/tests/test_checkout.pyindex 22a97f4bbc..fb1a92f45d 100644--- a/saleor/graphql/checkout/tests/test_checkout.py+++ b/saleor/graphql/checkout/tests/test_checkout.py@@ -31,19 +31,6 @@ from ..mutations import (from ..utils import clean_checkout_payment, clean_checkout_shipping[email protected](autouse=True)-def setup_dummy_gateway(settings):- settings.PLUGINS = ["saleor.payment.gateways.dummy.plugin.DummyGatewayPlugin"]- return settings---def add_sample_gateway(settings):- settings.PLUGINS += [- "saleor.plugins.tests.sample_plugins.ActiveDummyPaymentGateway"- ]--def test_clean_shipping_method_after_shipping_address_changes_stay_the_same(checkout_with_single_item, address, shipping_method, other_shipping_method):diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 47d6c8f8ce..a442f6f575 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -4370,7 +4370,7 @@ input ShippingZoneUpdateInput {}type Shop {- availablePaymentGateways: [PaymentGateway!]!+ availablePaymentGateways(currency: String): [PaymentGateway!]!geolocalization: GeolocalizationauthorizationKeys: [AuthorizationKey]!countries(languageCode: LanguageCodeEnum): [CountryDisplay!]!diff --git a/saleor/graphql/shop/tests/test_shop.py b/saleor/graphql/shop/tests/test_shop.pyindex 3e0b319699..abdcad3a61 100644--- a/saleor/graphql/shop/tests/test_shop.py+++ b/saleor/graphql/shop/tests/test_shop.py@@ -682,23 +682,56 @@ def test_query_geolocalization(user_api_client):assert data["country"] is None[email protected]("ignore::UserWarning")-def test_query_available_payment_gateways(user_api_client):- query = """- query {- shop {- availablePaymentGateways {- id- name- }+AVAILABLE_PAYMENT_GATEWAYS_QUERY = """+ query Shop($currency: String){+ shop {+ availablePaymentGateways(currency: $currency) {+ id+ name}}- """+ }+"""++[email protected]("ignore::UserWarning")+def test_query_available_payment_gateways(user_api_client, add_sample_gateway):+ query = AVAILABLE_PAYMENT_GATEWAYS_QUERYresponse = user_api_client.post_graphql(query)content = get_graphql_content(response)data = content["data"]["shop"]["availablePaymentGateways"]- assert data[0]["id"] == "mirumee.payments.dummy"- assert data[0]["name"] == "Dummy"+ assert {gateway["id"] for gateway in data} == {+ "mirumee.payments.dummy",+ "sampleDummy.active",+ }+ assert {gateway["name"] for gateway in data} == {"Dummy", "SampleDummy"}++[email protected]("ignore::UserWarning")+def test_query_available_payment_gateways_specified_currency_USD(+ user_api_client, add_sample_gateway+):+ query = AVAILABLE_PAYMENT_GATEWAYS_QUERY+ response = user_api_client.post_graphql(query, {"currency": "USD"})+ content = get_graphql_content(response)+ data = content["data"]["shop"]["availablePaymentGateways"]+ assert {gateway["id"] for gateway in data} == {+ "mirumee.payments.dummy",+ "sampleDummy.active",+ }+ assert {gateway["name"] for gateway in data} == {"Dummy", "SampleDummy"}++[email protected]("ignore::UserWarning")+def test_query_available_payment_gateways_specified_currency_PLN(+ user_api_client, add_sample_gateway+):+ query = AVAILABLE_PAYMENT_GATEWAYS_QUERY+ response = user_api_client.post_graphql(query, {"currency": "PLN"})+ content = get_graphql_content(response)+ data = content["data"]["shop"]["availablePaymentGateways"]+ assert data[0]["id"] == "sampleDummy.active"+ assert data[0]["name"] == "SampleDummy"AUTHORIZATION_KEY_ADD = """diff --git a/saleor/graphql/shop/types.py b/saleor/graphql/shop/types.pyindex 51022c981c..e8c6ddf199 100644--- a/saleor/graphql/shop/types.py+++ b/saleor/graphql/shop/types.py@@ -1,3 +1,5 @@+from typing import Optional+import graphenefrom django.conf import settingsfrom django.utils import translation@@ -66,6 +68,11 @@ class Geolocalization(graphene.ObjectType):class Shop(graphene.ObjectType):available_payment_gateways = graphene.List(graphene.NonNull(PaymentGateway),+ currency=graphene.Argument(+ graphene.String,+ description="A currency for which gateways will be returned.",+ required=False,+ ),description="List of available payment gateways.",required=True,)@@ -166,8 +173,8 @@ class Shop(graphene.ObjectType):)@staticmethod- def resolve_available_payment_gateways(_, _info):- return [gtw for gtw in get_plugins_manager().list_payment_gateways()]+ def resolve_available_payment_gateways(_, _info, currency: Optional[str] = None):+ return get_plugins_manager().list_payment_gateways(currency=currency)@staticmethod@permission_required(SitePermissions.MANAGE_SETTINGS)diff --git a/saleor/plugins/tests/sample_plugins.py b/saleor/plugins/tests/sample_plugins.pyindex 561d42406b..c4cbeba904 100644--- a/saleor/plugins/tests/sample_plugins.py+++ b/saleor/plugins/tests/sample_plugins.py@@ -124,12 +124,12 @@ class ActivePaymentGateway(BasePlugin):class ActiveDummyPaymentGateway(BasePlugin):- PLUGIN_ID = "dummy.active"+ PLUGIN_ID = "sampleDummy.active"CLIENT_CONFIG = [{"field": "foo", "value": "bar"},{"field": "supported_currencies", "value": ["PLN", "USD"]},]- PLUGIN_NAME = "dummy"+ PLUGIN_NAME = "SampleDummy"DEFAULT_ACTIVE = Truedef process_payment(self, payment_information, previous_value):diff --git a/saleor/tests/fixtures.py b/saleor/tests/fixtures.pyindex bd5ee75a81..48a4af7db7 100644--- a/saleor/tests/fixtures.py+++ b/saleor/tests/fixtures.py@@ -183,6 +183,13 @@ def setup_dummy_gateway(settings):return settings+def add_sample_gateway(settings):+ settings.PLUGINS += [+ "saleor.plugins.tests.sample_plugins.ActiveDummyPaymentGateway"+ ]++@pytest.fixture(autouse=True)def site_settings(db, settings) -> SiteSettings:"""Create a site and matching site settings.