Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Use dynamic config to check if payment plugin is active

Jakub Draganekf80e67a8764f
diff --git a/saleor/extensions/manager.py b/saleor/extensions/manager.py
index f4b6682192..528a76ce8b 100644
--- a/saleor/extensions/manager.py
+++ b/saleor/extensions/manager.py
@@ -243,7 +243,8 @@ class ExtensionsManager(PaymentInterface):
return [
Gateway(plugin.PLUGIN_NAME)
for plugin in self.plugins
- if plugin.active and PAYMENT_METHOD in type(plugin).__dict__
+ if PAYMENT_METHOD in type(plugin).__dict__
+ and self.get_plugin_configuration(plugin.PLUGIN_NAME).active
]
def __run_payment_method(
diff --git a/saleor/payment/gateways/braintree/plugin.py b/saleor/payment/gateways/braintree/plugin.py
index 1d1d6fb4e8..b299fc4362 100644
--- a/saleor/payment/gateways/braintree/plugin.py
+++ b/saleor/payment/gateways/braintree/plugin.py
@@ -1,6 +1,5 @@
from typing import TYPE_CHECKING, List
-from django.conf import settings
from django.utils.translation import pgettext_lazy
from saleor.extensions import ConfigurationTypeField
@@ -26,6 +25,7 @@ if TYPE_CHECKING:
def require_active_plugin(fn):
def wrapped(self, *args, **kwargs):
previous = kwargs.get("previous_value", None)
+ self._initialize_plugin_configuration()
if not self.active:
return previous
return fn(self, *args, **kwargs)
@@ -34,7 +34,7 @@ def require_active_plugin(fn):
class BraintreeGatewayPlugin(BasePlugin):
- PLUGIN_NAME = "Braintree Gateway"
+ PLUGIN_NAME = "braintree"
CONFIG_STRUCTURE = {
"Public API key": {
"type": ConfigurationTypeField.STRING,
@@ -99,6 +99,7 @@ class BraintreeGatewayPlugin(BasePlugin):
if self._cached_config and self._cached_config.configuration:
configuration = self._cached_config.configuration
+ configuration = {item["name"]: item["value"] for item in configuration}
self.config = GatewayConfig(
gateway_name=GATEWAY_NAME,
auto_capture=configuration["Automatic payment capture"],
@@ -111,17 +112,6 @@ class BraintreeGatewayPlugin(BasePlugin):
template_path="",
store_customer=configuration["Store customers card"],
)
- else:
- # This should be removed after we drop payment configs in settings
- gateway_config = settings.PAYMENT_GATEWAYS[GATEWAY_NAME]["config"]
- self.config = GatewayConfig(
- gateway_name=GATEWAY_NAME,
- auto_capture=gateway_config["auto_capture"],
- template_path=gateway_config["template_path"],
- connection_params=gateway_config["connection_params"],
- store_customer=gateway_config["store_card"],
- )
- self.active = False
@classmethod
def _get_default_configuration(cls):
diff --git a/saleor/payment/gateways/dummy/plugin.py b/saleor/payment/gateways/dummy/plugin.py
index c81e1b4c7d..2c14f1bd0f 100644
--- a/saleor/payment/gateways/dummy/plugin.py
+++ b/saleor/payment/gateways/dummy/plugin.py
@@ -1,6 +1,5 @@
from typing import TYPE_CHECKING
-from django.conf import settings
from django.utils.translation import pgettext_lazy
from saleor.extensions import ConfigurationTypeField
@@ -27,6 +26,7 @@ if TYPE_CHECKING:
def require_active_plugin(fn):
def wrapped(self, *args, **kwargs):
previous = kwargs.get("previous_value", None)
+ self._initialize_plugin_configuration()
if not self.active:
return previous
return fn(self, *args, **kwargs)
@@ -71,6 +71,7 @@ class DummyGatewayPlugin(BasePlugin):
if self._cached_config and self._cached_config.configuration:
configuration = self._cached_config.configuration
+ configuration = {item["name"]: item["value"] for item in configuration}
self.config = GatewayConfig(
gateway_name=GATEWAY_NAME,
auto_capture=configuration["Automatic payment capture"],
@@ -78,17 +79,6 @@ class DummyGatewayPlugin(BasePlugin):
template_path="",
store_customer=configuration["Store customers card"],
)
- else:
- # This should be removed after we drop payment configs in settings
- gateway_config = settings.PAYMENT_GATEWAYS[GATEWAY_NAME]["config"]
- self.config = GatewayConfig(
- gateway_name=GATEWAY_NAME,
- auto_capture=gateway_config["auto_capture"],
- template_path=gateway_config["template_path"],
- connection_params=gateway_config["connection_params"],
- store_customer=gateway_config["store_card"],
- )
- self.active = GATEWAY_NAME in settings.CHECKOUT_PAYMENT_GATEWAYS
@classmethod
def _get_default_configuration(cls):
diff --git a/saleor/payment/gateways/razorpay/plugin.py b/saleor/payment/gateways/razorpay/plugin.py
index 5e607cd302..4ba6f50992 100644
--- a/saleor/payment/gateways/razorpay/plugin.py
+++ b/saleor/payment/gateways/razorpay/plugin.py
@@ -17,6 +17,7 @@ if TYPE_CHECKING:
def require_active_plugin(fn):
def wrapped(self, *args, **kwargs):
previous = kwargs.get("previous_value", None)
+ self._initialize_plugin_configuration()
if not self.active:
return previous
return fn(self, *args, **kwargs)
@@ -68,6 +69,7 @@ class RazorpayGatewayPlugin(BasePlugin):
if self._cached_config and self._cached_config.configuration:
configuration = self._cached_config.configuration
+ configuration = {item["name"]: item["value"] for item in configuration}
self.config = GatewayConfig(
gateway_name=GATEWAY_NAME,
auto_capture=configuration["Automatic payment capture"],
@@ -78,17 +80,6 @@ class RazorpayGatewayPlugin(BasePlugin):
template_path="",
store_customer=configuration["Store customers card"],
)
- else:
- # This should be removed after we drop payment configs in settings
- gateway_config = settings.PAYMENT_GATEWAYS[GATEWAY_NAME]["config"]
- self.config = GatewayConfig(
- gateway_name=GATEWAY_NAME,
- auto_capture=gateway_config["auto_capture"],
- template_path=gateway_config["template_path"],
- connection_params=gateway_config["connection_params"],
- store_customer=gateway_config["store_card"],
- )
- self.active = GATEWAY_NAME in settings.CHECKOUT_PAYMENT_GATEWAYS
@classmethod
def _get_default_configuration(cls):
diff --git a/saleor/payment/gateways/stripe/plugin.py b/saleor/payment/gateways/stripe/plugin.py
index 71c3dd2c19..af57e839e9 100644
--- a/saleor/payment/gateways/stripe/plugin.py
+++ b/saleor/payment/gateways/stripe/plugin.py
@@ -1,6 +1,5 @@
from typing import TYPE_CHECKING, List
-from django.conf import settings
from django.utils.translation import pgettext_lazy
from saleor.extensions import ConfigurationTypeField
@@ -25,6 +24,7 @@ if TYPE_CHECKING:
def require_active_plugin(fn):
def wrapped(self, *args, **kwargs):
previous = kwargs.get("previous_value", None)
+ self._initialize_plugin_configuration()
if not self.active:
return previous
return fn(self, *args, **kwargs)
@@ -33,7 +33,7 @@ def require_active_plugin(fn):
class StripeGatewayPlugin(BasePlugin):
- PLUGIN_NAME = "Stripe Gateway"
+ PLUGIN_NAME = GATEWAY_NAME
CONFIG_STRUCTURE = {
"Public API key": {
"type": ConfigurationTypeField.STRING,
@@ -78,6 +78,7 @@ class StripeGatewayPlugin(BasePlugin):
if self._cached_config and self._cached_config.configuration:
configuration = self._cached_config.configuration
+ configuration = {item["name"]: item["value"] for item in configuration}
self.config = GatewayConfig(
gateway_name=GATEWAY_NAME,
auto_capture=configuration["Automatic payment capture"],
@@ -88,17 +89,6 @@ class StripeGatewayPlugin(BasePlugin):
template_path="",
store_customer=configuration["Store customers card"],
)
- else:
- # This should be removed after we drop payment configs in settings
- gateway_config = settings.PAYMENT_GATEWAYS[GATEWAY_NAME]["config"]
- self.config = GatewayConfig(
- gateway_name=GATEWAY_NAME,
- auto_capture=gateway_config["auto_capture"],
- template_path=gateway_config["template_path"],
- connection_params=gateway_config["connection_params"],
- store_customer=gateway_config["store_card"],
- )
- self.active = False
@classmethod
def _get_default_configuration(cls):