Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fetch payment gateway config from payment plugin
Jakub Draganek72c14c57ab69
diff --git a/saleor/extensions/base_plugin.py b/saleor/extensions/base_plugin.pyindex 152b418051..5f0a47960f 100644--- a/saleor/extensions/base_plugin.py+++ b/saleor/extensions/base_plugin.py@@ -195,6 +195,9 @@ class BasePlugin:def get_payment_template(self, previous_value):return NotImplemented+ def get_payment_config(self, previous_value):+ return NotImplemented+@classmethoddef _update_config_items(cls, configuration_to_update: List[dict], current_config: List[dict]diff --git a/saleor/extensions/manager.py b/saleor/extensions/manager.pyindex 05cc6327d4..0fbd438736 100644--- a/saleor/extensions/manager.py+++ b/saleor/extensions/manager.py@@ -263,10 +263,13 @@ class ExtensionsManager(PaymentInterface):)raise Exception(f"Payment plugin {gateway} is inaccessible!")- def list_payment_gateways(self) -> List[str]:+ def list_payment_gateways(self) -> List[dict]:payment_method = "process_payment"return [- plugin.PLUGIN_NAME+ {+ "name": plugin.PLUGIN_NAME,+ "config": self.__get_payment_config(plugin.PLUGIN_NAME),+ }for plugin in self.pluginsif payment_method in type(plugin).__dict__and self.get_plugin_configuration(plugin.PLUGIN_NAME).active@@ -278,6 +281,12 @@ class ExtensionsManager(PaymentInterface):gtw = self.get_plugin(gateway)return self.__run_method_on_single_plugin(gtw, method_name, default_value)+ def __get_payment_config(self, gateway: str) -> List[dict]:+ method_name = "get_payment_config"+ default_value = []+ gtw = self.get_plugin(gateway)+ return self.__run_method_on_single_plugin(gtw, method_name, default_value)+def __run_payment_method(self,gateway: str,diff --git a/saleor/graphql/checkout/types.py b/saleor/graphql/checkout/types.pyindex 6a76ea2b43..4f009d1353 100644--- a/saleor/graphql/checkout/types.py+++ b/saleor/graphql/checkout/types.py@@ -167,10 +167,7 @@ class Checkout(MetadataObjectType, CountableDjangoObjectType):@staticmethoddef resolve_available_payment_gateways(_: models.Checkout, _info):- return [- {"name": gtw, "config": []}- for gtw in get_extensions_manager().list_payment_gateways()- ]+ return [gtw for gtw in get_extensions_manager().list_payment_gateways()]@staticmethoddef resolve_gift_cards(root: models.Checkout, _info):diff --git a/saleor/payment/gateway.py b/saleor/payment/gateway.pyindex ecddd128eb..1f19b0f6cb 100644--- a/saleor/payment/gateway.py+++ b/saleor/payment/gateway.py@@ -204,7 +204,7 @@ def get_client_token(gateway: str, customer_id: str = None) -> str:return plugin_manager.get_client_token(gateway, token_config)-def list_gateways() -> List[str]:+def list_gateways() -> List[dict]:return get_extensions_manager().list_payment_gateways()diff --git a/saleor/payment/gateways/dummy/plugin.py b/saleor/payment/gateways/dummy/plugin.pyindex 8c65e9f75b..47836672bc 100644--- a/saleor/payment/gateways/dummy/plugin.py+++ b/saleor/payment/gateways/dummy/plugin.py@@ -154,3 +154,8 @@ class DummyGatewayPlugin(BasePlugin):@require_active_plugindef get_payment_template(self, previous_value) -> str:return self._get_gateway_config().template_path++ @require_active_plugin+ def get_payment_config(self, previous_value):+ config = self._get_gateway_config()+ return [{"field": "store_customer_card", "value": config.store_customer}]diff --git a/tests/api/test_checkout.py b/tests/api/test_checkout.pyindex 724ba69aa1..e747f1ff4c 100644--- a/tests/api/test_checkout.py+++ b/tests/api/test_checkout.py@@ -383,7 +383,7 @@ def test_checkout_create_check_lines_quantity(def expected_dummy_gateway():return {"name": "Dummy",- "config": [{"field": "store_customer_card", "value": False}],+ "config": [{"field": "store_customer_card", "value": "false"}],}