Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Disable payment plugins when not active
Jakub Draganek5b2852181b06
diff --git a/saleor/payment/gateways/braintree/plugin.py b/saleor/payment/gateways/braintree/plugin.pyindex cc7860446b..a436d80219 100644--- a/saleor/payment/gateways/braintree/plugin.py+++ b/saleor/payment/gateways/braintree/plugin.py@@ -23,6 +23,16 @@ if TYPE_CHECKING:from . import GatewayResponse, PaymentData, CustomerSource+def require_active_plugin(fn):+ def wrapped(self, *args, **kwargs):+ previous = kwargs.get("previous_value", None)+ if not self.active:+ return previous+ return fn(self, *args, **kwargs)++ return wrapped++class BraintreeGatewayPlugin(BasePlugin):PLUGIN_NAME = "Braintree Gateway"CONFIG_STRUCTURE = {@@ -133,31 +143,37 @@ class BraintreeGatewayPlugin(BasePlugin):def _get_gateway_config(self):return self.config+ @require_active_plugindef authorize_payment(self, payment_information: "PaymentData", previous_value) -> "GatewayResponse":return authorize(payment_information, self._get_gateway_config())+ @require_active_plugindef capture_payment(self, payment_information: "PaymentData", previous_value) -> "GatewayResponse":return capture(payment_information, self._get_gateway_config())+ @require_active_plugindef refund_payment(self, payment_information: "PaymentData", previous_value) -> "GatewayResponse":return refund(payment_information, self._get_gateway_config())+ @require_active_plugindef void_payment(self, payment_information: "PaymentData", previous_value) -> "GatewayResponse":return void(payment_information, self._get_gateway_config())+ @require_active_plugindef process_payment(self, payment_information: "PaymentData", previous_value) -> "GatewayResponse":return process_payment(payment_information, self._get_gateway_config())+ @require_active_plugindef list_payment_sources(self, customer_id: str, previous_value) -> List["CustomerSource"]:@@ -165,5 +181,6 @@ class BraintreeGatewayPlugin(BasePlugin):previous_value.extend(sources)return previous_value+ @require_active_plugindef create_form(self, data, payment_information, previous_value) -> "forms.Form":return create_form(data, payment_information)diff --git a/saleor/payment/gateways/stripe/plugin.py b/saleor/payment/gateways/stripe/plugin.pyindex 661b980ba3..317d49012a 100644--- a/saleor/payment/gateways/stripe/plugin.py+++ b/saleor/payment/gateways/stripe/plugin.py@@ -22,6 +22,16 @@ if TYPE_CHECKING:from . import GatewayResponse, PaymentData, CustomerSource+def require_active_plugin(fn):+ def wrapped(self, *args, **kwargs):+ previous = kwargs.get("previous_value", None)+ if not self.active:+ return previous+ return fn(self, *args, **kwargs)++ return wrapped++class StripeGatewayPlugin(BasePlugin):PLUGIN_NAME = "Stripe Gateway"CONFIG_STRUCTURE = {@@ -108,26 +118,31 @@ class StripeGatewayPlugin(BasePlugin):def _get_gateway_config(self):return self.config+ @require_active_plugindef authorize_payment(self, payment_information: "PaymentData", previous_value) -> "GatewayResponse":return authorize(payment_information, self._get_gateway_config())+ @require_active_plugindef capture_payment(self, payment_information: "PaymentData", previous_value) -> "GatewayResponse":return capture(payment_information, self._get_gateway_config())+ @require_active_plugindef refund_payment(self, payment_information: "PaymentData", previous_value) -> "GatewayResponse":return refund(payment_information, self._get_gateway_config())+ @require_active_plugindef void_payment(self, payment_information: "PaymentData", previous_value) -> "GatewayResponse":return void(payment_information, self._get_gateway_config())+ @require_active_plugindef process_payment(self, payment_information: "PaymentData", previous_value) -> "GatewayResponse":