Skip to content

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

Select plugin using ExtensionManager

Mira Szewczyk24199eb21176
diff --git a/saleor/dashboard/payment/views.py b/saleor/dashboard/payment/views.py
index e6801049d0..08b668b560 100644
--- a/saleor/dashboard/payment/views.py
+++ b/saleor/dashboard/payment/views.py
@@ -5,34 +5,26 @@ from django.shortcuts import redirect
from django.template.response import TemplateResponse
from django.utils.translation import pgettext_lazy
-from ...payment.gateways.braintree.plugin import BraintreeGatewayPlugin
-from ...payment.gateways.dummy.plugin import DummyGatewayPlugin
-from ...payment.gateways.razorpay.plugin import RazorpayGatewayPlugin
-from ...payment.gateways.stripe.plugin import StripeGatewayPlugin
+from ...extensions.manager import get_extensions_manager
from ..views import staff_member_required
from .forms import GatewayConfigurationForm
-PAYMENT_PLUGINS = [
- BraintreeGatewayPlugin,
- DummyGatewayPlugin,
- RazorpayGatewayPlugin,
- StripeGatewayPlugin,
-]
-
-PAYMENT_GATEWAYS = {plugin.PLUGIN_NAME: plugin for plugin in PAYMENT_PLUGINS}
-
@staff_member_required
@permission_required("extensions.manage_plugins")
def index(request: "HttpRequest") -> TemplateResponse:
- ctx = {"payment_gateways": PAYMENT_GATEWAYS.keys()}
+ payment_gateways = [
+ gateway["name"]
+ for gateway in get_extensions_manager().list_payment_gateways(active_only=False)
+ ]
+ ctx = {"payment_gateways": payment_gateways}
return TemplateResponse(request, "dashboard/payments/index.html", ctx)
@staff_member_required
@permission_required("extension.manage_plugins")
def configure_payment_gateway(request: HttpRequest, plugin_name: str) -> HttpResponse:
- plugin = PAYMENT_GATEWAYS.get(plugin_name, None)
+ plugin = get_extensions_manager().get_plugin(plugin_name)
if plugin is None:
msg = pgettext_lazy("Dashboard message", "Selected plugin does not exist.")
messages.error(request, msg)
diff --git a/saleor/extensions/manager.py b/saleor/extensions/manager.py
index 0fbd438736..48a4566a31 100644
--- a/saleor/extensions/manager.py
+++ b/saleor/extensions/manager.py
@@ -263,7 +263,7 @@ class ExtensionsManager(PaymentInterface):
)
raise Exception(f"Payment plugin {gateway} is inaccessible!")
- def list_payment_gateways(self) -> List[dict]:
+ def list_payment_gateways(self, active_only: bool = True) -> List[dict]:
payment_method = "process_payment"
return [
{
@@ -272,7 +272,11 @@ class ExtensionsManager(PaymentInterface):
}
for plugin in self.plugins
if payment_method in type(plugin).__dict__
- and self.get_plugin_configuration(plugin.PLUGIN_NAME).active
+ and (
+ self.get_plugin_configuration(plugin.PLUGIN_NAME).active
+ if active_only
+ else True
+ )
]
def get_payment_template(self, gateway: str) -> str: