Skip to content

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

Display gateway configuration form

Mira Szewczykf03c4203c3c1
diff --git a/saleor/dashboard/payment/views.py b/saleor/dashboard/payment/views.py
new file mode 100644
index 0000000000..0cebd6436d
--- /dev/null
+++ b/saleor/dashboard/payment/views.py
@@ -0,0 +1,48 @@
+from django.contrib import messages
+from django.contrib.auth.decorators import permission_required
+from django.http import HttpRequest, HttpResponse
+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 ..views import staff_member_required
+from .forms import GatewayConfigurationForm
+
+GATEWAYS_PLUGINS = [
+ BraintreeGatewayPlugin,
+ DummyGatewayPlugin,
+ RazorpayGatewayPlugin,
+ StripeGatewayPlugin,
+]
+
+
+@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}
+ 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:
+ msg = pgettext_lazy("Dashboard message", "Selected plugin does not exists.")
+ messages.error(request, msg)
+ return redirect("dashboard:payments-index")
+
+ form = GatewayConfigurationForm(plugin)
+
+ ctx = {"plugin_name": plugin_name, "config_form": form}
+ return TemplateResponse(request, "dashboard/payments/configuration_form.html", ctx)
diff --git a/templates/dashboard/payments/configuration_form.html b/templates/dashboard/payments/configuration_form.html
new file mode 100644
index 0000000000..6010b899c9
--- /dev/null
+++ b/templates/dashboard/payments/configuration_form.html
@@ -0,0 +1,43 @@
+{% extends "dashboard/base.html" %}
+{% load i18n %}
+{% load materializecss %}
+{% load static %}
+
+{% block title %}
+ {% trans "Payment configuration" context "Dashboard payments form" %} - {{ block.super }}
+{% endblock %}
+
+{% block body_class %}body-customers{% endblock %}
+{% block menu_payments_class %}active{% endblock %}
+
+{% block breadcrumbs %}
+<ul class="breadcrumbs breadcrumbs--history">
+ <li>
+ {% trans "Payments configurations" context "Dashboard payment configuration page" %}
+ </li>
+ <li>{{ plugin_name }}</li>
+</ul>
+{% endblock %}
+
+{% block content %}
+ <div class="tab-content" id="details">
+ <div class="row">
+ <div class="col m12 l9">
+ <form method="post" class="card" id="form-config" novalidate>
+ {% csrf_token %}
+ <div class="card-content">
+ <div class="row">
+ <div class="col s12 l8">
+ {% for field in config_form %}
+ <div class="row">
+ {{ field|materializecss }}
+ </div>
+ {% endfor %}
+ </div>
+ </div>
+ </div>
+ </form>
+ </div>
+ </div>
+ </div>
+{% endblock %}
diff --git a/templates/dashboard/payments/index.html b/templates/dashboard/payments/index.html
index c6e45e3acf..10c1c01a1d 100644
--- a/templates/dashboard/payments/index.html
+++ b/templates/dashboard/payments/index.html
@@ -34,7 +34,7 @@
</thead>
<tbody>
{% for gateway in payment_gateways%}
- <tr data-action-go="">
+ <tr data-action-go="{% url "dashboard:configure-payment" gateway %}">
<td>
{{ gateway }}
</td>