Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Show payment actions in modal
Marcin Gębalaca8f445adf53
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.pyindex e0de62f631..73d96e9608 100644--- a/saleor/dashboard/order/views.py+++ b/saleor/dashboard/order/views.py@@ -3,6 +3,9 @@ from django.utils.translation import ugettext_lazy as _from django.views.generic import ListView, DetailView, UpdateViewfrom django.core.urlresolvers import reversefrom django.shortcuts import get_object_or_404+from django.template.loader import render_to_string+from django.http import HttpResponse+from django.core.context_processors import csrffrom payments import PaymentErrorfrom ...order.models import Order, Address@@ -55,6 +58,7 @@ class OrderDetails(StaffMemberOnlyMixin, DetailView):amount = Nonectx['payment_form'] = self.payment_form_class(initial={'amount': amount})+ ctx['amount'] = amountif payment.status == 'refunded':ctx['refunded_amount'] = payment.total - payment.captured_amountelse:@@ -72,6 +76,25 @@ class OrderDetails(StaffMemberOnlyMixin, DetailView):except self.model.DoesNotExist:return None+ def get(self, request, *args, **kwargs):+ self.object = self.get_object()+ ctx = self.get_context_data()+ payment = ctx['payment']+ if request.is_ajax() and 'action' in request.GET:+ action = request.GET['action']+ ctx.update({'action': action, 'currency': payment.currency,+ 'captured': payment.captured_amount})+ if action == 'release':+ template = 'dashboard/includes/modal_release.html'+ else:+ template = 'dashboard/includes/modal_capture_refund.html'+ ctx.update(csrf(request))+ rendered = render_to_string(template, ctx)+ return HttpResponse(rendered)+ else:+ context = self.get_context_data(object=self.object)+ return self.render_to_response(context)+def post(self, request, *args, **kwargs):if 'release_action' in request.POST:self.handle_release_action()diff --git a/saleor/dashboard/templates/dashboard/includes/modal_capture_refund.html b/saleor/dashboard/templates/dashboard/includes/modal_capture_refund.htmlnew file mode 100644index 0000000000..0ebc1b511d--- /dev/null+++ b/saleor/dashboard/templates/dashboard/includes/modal_capture_refund.html@@ -0,0 +1,54 @@+{% load i18n %}+{% load bootstrap %}++<div class="modal-header">+ <a href="#" data-dismiss="modal" aria-hidden="true" class="close">×</a>+ <h3>{{ action|capfirst }} {% trans "payment" %}</h3>+</div>+<div class="modal-body">+ <form id="modal-form" class="form-inline" role="form" method="post">+ {% csrf_token %}+ <div class="form-group">+ <label class="control-label"for="amount">{% blocktrans %}Amount to {{ action }}:{% endblocktrans %}</label>+ {% render_widget payment_form.amount class="form-control" %} {{ currency }}+ <input id='id_action' type="hidden" name='payment_form' value={{ action }} />+ <input id='id_captured' type="hidden" value={{ captured }} />+ </div>+ </form>+ <p>{% trans "Before this action" %}</p>+ <ul>+ <li>{% trans "Captured amount: " %}{{ captured }} {{ currency }}</li>+ </ul>+ <p>{% trans "After this action" %}</p>+ <ul>+ <li>{% trans "Captured amount: " %}<span id="id_new_captured">{{ amount }}</span> {{ currency }}</li>+ </ul>+</div>+<div class="modal-footer">+ <button id="id_btn_yes" type="submit" class="btn btn-{% if action == 'capture' %}success{% else%}danger{% endif %}">{{ action|capfirst }}</button>+ <button data-dismiss="modal" aria-hidden="true" class="btn btn-default">{% trans "Cancel" %}</button>+</div>+++<script>+$('#id_btn_yes').click(function() {+ $('#modal-form').submit();+});+$('#id_amount').change(function() {+ var action = $('#id_action').val();+ var amount = $('#id_amount').val();+ var captured = parseFloat(($('#id_captured').val()).replace(',', '.'));++ var new_captured = 0;+ if (action == 'capture') {+ new_captured = amount - captured;+ } else {+ new_captured = captured - amount;+ if (new_captured < 0) {+ new_captured = 0;+ }+ }++ $('#id_new_captured').text(new_captured.toFixed(2));+});+</script>\ No newline at end of filediff --git a/saleor/dashboard/templates/dashboard/includes/modal_release.html b/saleor/dashboard/templates/dashboard/includes/modal_release.htmlnew file mode 100644index 0000000000..3e9f87d73b--- /dev/null+++ b/saleor/dashboard/templates/dashboard/includes/modal_release.html@@ -0,0 +1,18 @@+{% load i18n %}+{% load bootstrap %}++<div class="modal-header">+ <a href="#" data-dismiss="modal" aria-hidden="true" class="close">×</a>+ <h3>{% trans "Release payment" %}</h3>+</div>+<div class="modal-body">+ <p>{% trans "Do you want to release the payment?" %}</p>+</div>+<div class="modal-footer">+ <form id="release-form" class="form-inline" method="post" role="form">+ {% csrf_token %}+ <input type="hidden" name='release_action' value="release"/>+ <button type="submit" class="btn btn-danger">{% trans "Release" %}</button>+ <button data-dismiss="modal" aria-hidden="true" class="btn btn-default">{% trans "Cancel" %}</button>+ </form>+</div>\ No newline at end of filediff --git a/saleor/dashboard/templates/dashboard/order/detail.html b/saleor/dashboard/templates/dashboard/order/detail.htmlindex 556e19b315..7886f9a1ad 100644--- a/saleor/dashboard/templates/dashboard/order/detail.html+++ b/saleor/dashboard/templates/dashboard/order/detail.html@@ -67,31 +67,14 @@{% if payment %}<p>{% trans "Total amount:" %} {{ payment.total }} {{ payment.currency }}</p><p>{% trans "Captured amount:" %} {{ payment.captured_amount }} {{ payment.currency }}</p>- {% if refunded_amount %}- <p>{% trans "Refunded amount:" %} {{ refunded_amount }} {{ payment.currency }}</p>+ {% if can_capture %}+ <a class="btn btn-success" data-target="#payment-action-modal" href="{% url 'dashboard:order-details' pk=order.pk %}?action=capture" data-toggle="modal">{% trans "Capture" %}</a>+ {% elif can_refund %}+ <a class="btn btn-danger" data-target="#payment-action-modal" href="{% url 'dashboard:order-details' pk=order.pk %}?action=refund" data-toggle="modal">{% trans "Refund" %}</a>+ {% endif %}+ {% if can_release %}+ <a class="btn btn-danger" data-target="#payment-action-modal" href="{% url 'dashboard:order-details' pk=order.pk %}?action=release" data-toggle="modal">{% trans "Release" %}</a>{% endif %}- {% if can_capture or can_refund %}- <form class="form-inline" role="form" method="post">- {% csrf_token %}- <div class="form-group">- <label class="control-label"for="amount">{% trans "Amount" %}</label>- {% render_widget payment_form.amount class="form-control" %}- {% if can_capture %}- <button class="btn btn-success" type="submit" name='payment_form' value='capture'>{% trans "Capture" %}</button>- {% elif can_refund %}- <button class="btn btn-danger" type="submit" name='payment_form' value='refund'>{% trans "Refund" %}</button>- {% endif %}- </div>- </form>- {% endif %}-- {% if can_release %}- <form class="form-inline" method="post" role="form">- {% csrf_token %}- <label class="control-label">{% trans "Release payment" %}</label>- <input type="submit" class="btn btn-danger" name='release_action' value="Release"/>- </form>- {% endif %}{% else %}<span>{% trans "No payment for this order" %}</span>{% endif %}@@ -244,4 +227,20 @@</div></div></div>++<div id="payment-action-modal" class="modal">+ <div class="modal-dialog">+ <div class="modal-content"></div>+ </div>+</div>++{% endblock %}++{% block custom_js %}+{{ block.super }}+<script>+ $('#payment-action-modal').on('hide.bs.modal', function(e) {+ $(this).removeData();+ });+</script>{% endblock %}