Skip to content

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

Simplify configure_payment_gateway view

Mira Szewczykf4a06510fc6c
diff --git a/saleor/dashboard/payment/views.py b/saleor/dashboard/payment/views.py
index db60a59889..2de56dfae4 100644
--- a/saleor/dashboard/payment/views.py
+++ b/saleor/dashboard/payment/views.py
@@ -12,32 +12,28 @@ from ...payment.gateways.stripe.plugin import StripeGatewayPlugin
from ..views import staff_member_required
from .forms import GatewayConfigurationForm
-GATEWAYS_PLUGINS = [
+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:
- payment_gateways = [gateway.PLUGIN_NAME for gateway in GATEWAYS_PLUGINS]
-
- ctx = {"payment_gateways": payment_gateways}
+ ctx = {"payment_gateways": PAYMENT_GATEWAYS.keys()}
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 = None
- for gateway in GATEWAYS_PLUGINS:
- if gateway.PLUGIN_NAME == plugin_name:
- plugin = gateway
- break
- else:
+ plugin = PAYMENT_GATEWAYS.get(plugin_name, None)
+ if plugin is None:
msg = pgettext_lazy("Dashboard message", "Selected plugin does not exists.")
messages.error(request, msg)
return redirect("dashboard:payments-index")