Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Match supported gateways based on checkout currency
IKarbowiakb3bbe8341b1c
diff --git a/saleor/graphql/checkout/tests/test_checkout.py b/saleor/graphql/checkout/tests/test_checkout.pyindex b050f0ea79..22a97f4bbc 100644--- a/saleor/graphql/checkout/tests/test_checkout.py+++ b/saleor/graphql/checkout/tests/test_checkout.py@@ -20,6 +20,7 @@ from ....order.models import Orderfrom ....payment import TransactionKindfrom ....payment.interface import GatewayResponsefrom ....plugins.manager import PluginsManager+from ....plugins.tests.sample_plugins import ActiveDummyPaymentGatewayfrom ....warehouse.models import Stockfrom ....warehouse.tests.utils import get_available_quantity_for_stockfrom ...tests.utils import assert_no_permission, get_graphql_content@@ -36,6 +37,13 @@ def setup_dummy_gateway(settings):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):@@ -564,23 +572,26 @@ def expected_dummy_gateway():}+GET_CHECKOUT_QUERY = """+query getCheckout($token: UUID!) {+ checkout(token: $token) {+ availablePaymentGateways {+ id+ name+ config {+ field+ value+ }+ }+ }+}+"""++def test_checkout_available_payment_gateways(api_client, checkout_with_item, expected_dummy_gateway):- query = """- query getCheckout($token: UUID!) {- checkout(token: $token) {- availablePaymentGateways {- id- name- config {- field- value- }- }- }- }- """+ query = GET_CHECKOUT_QUERYexpected_warning = ("Default currency used for Dummy. ""DEFAULT_CURRENCY setting is deprecated, "@@ -597,6 +608,45 @@ def test_checkout_available_payment_gateways(assert data["availablePaymentGateways"] == [expected_dummy_gateway][email protected]("ignore::UserWarning")+def test_checkout_available_payment_gateways_currency_specified_USD(+ api_client, checkout_with_item, expected_dummy_gateway, add_sample_gateway+):+ checkout_with_item.currency = "USD"+ checkout_with_item.save(update_fields=["currency"])++ query = GET_CHECKOUT_QUERY++ variables = {"token": str(checkout_with_item.token)}+ response = api_client.post_graphql(query, variables)++ content = get_graphql_content(response)+ data = content["data"]["checkout"]+ assert {gateway["id"] for gateway in data["availablePaymentGateways"]} == {+ expected_dummy_gateway["id"],+ ActiveDummyPaymentGateway.PLUGIN_ID,+ }++[email protected]("ignore::UserWarning")+def test_checkout_available_payment_gateways_currency_specified_PLN(+ api_client, checkout_with_item, expected_dummy_gateway, add_sample_gateway+):+ checkout_with_item.currency = "PLN"+ checkout_with_item.save(update_fields=["currency"])++ query = GET_CHECKOUT_QUERY++ variables = {"token": str(checkout_with_item.token)}+ response = api_client.post_graphql(query, variables)++ content = get_graphql_content(response)+ data = content["data"]["checkout"]+ assert (+ data["availablePaymentGateways"][0]["id"] == ActiveDummyPaymentGateway.PLUGIN_ID+ )++def test_checkout_available_shipping_methods(api_client, checkout_with_item, address, shipping_zone):diff --git a/saleor/graphql/checkout/types.py b/saleor/graphql/checkout/types.pyindex a0a224250d..27086575eb 100644--- a/saleor/graphql/checkout/types.py+++ b/saleor/graphql/checkout/types.py@@ -237,8 +237,8 @@ class Checkout(CountableDjangoObjectType):)@staticmethod- def resolve_available_payment_gateways(_: models.Checkout, _info):- return [gtw for gtw in get_plugins_manager().list_payment_gateways()]+ def resolve_available_payment_gateways(root: models.Checkout, _info):+ return get_plugins_manager().list_payment_gateways(currency=root.currency)@staticmethoddef resolve_gift_cards(root: models.Checkout, _info):