Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Make payment action name part of the URL
Marcin Gębala0e9ca119edc0
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.pyindex 11de3205d1..03f3da3a94 100644--- a/saleor/dashboard/order/forms.py+++ b/saleor/dashboard/order/forms.py@@ -27,7 +27,6 @@ class OrderNoteForm(forms.ModelForm):class ManagePaymentForm(forms.Form):- action = forms.CharField(widget=forms.HiddenInput())amount = forms.DecimalField(min_value=0, decimal_places=2, required=False)def __init__(self, *args, **kwargs):diff --git a/saleor/dashboard/order/urls.py b/saleor/dashboard/order/urls.pyindex d83522a654..b07afd7af4 100644--- a/saleor/dashboard/order/urls.py+++ b/saleor/dashboard/order/urls.py@@ -12,7 +12,7 @@ urlpatterns = patterns(views.address_view, name='address-billing-edit'),url(r'^(?P<order_pk>[0-9]+)/address-shipping/(?P<group_pk>[0-9]+)/$',views.address_view, name='address-shipping-edit'),- url(r'^(?P<pk>[0-9]+)/payment$',+ url(r'^payment/(?P<pk>[0-9]+)/(?P<action>capture|refund|release)$',views.manage_payment, name='manage-payment'),url(r'^line/(?P<pk>[0-9]+)/$', views.edit_order_line,name='order-line-edit'),diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.pyindex e5ce622c1c..a438edfa07 100644--- a/saleor/dashboard/order/views.py+++ b/saleor/dashboard/order/views.py@@ -68,11 +68,10 @@ def order_details(request, pk):@staff_member_required-def manage_payment(request, pk):+def manage_payment(request, pk, action):payment = get_object_or_404(Payment, pk=pk)form = ManagePaymentForm(request.POST or None, payment=payment)if form.is_valid():- action = form.cleaned_data['action']try:form.handle_action(action, request.user)except PaymentError as e:@@ -83,7 +82,6 @@ def manage_payment(request, pk):messages.success(request, _('Success'))return redirect('dashboard:order-details', pk=payment.order.pk)if request.is_ajax():- action = request.GET['action']amount = 0if action == 'release':template = 'dashboard/includes/modal_release.html'diff --git a/saleor/dashboard/templates/dashboard/includes/modal_capture_refund.html b/saleor/dashboard/templates/dashboard/includes/modal_capture_refund.htmlindex 7a9913d630..3f8ec398ac 100644--- a/saleor/dashboard/templates/dashboard/includes/modal_capture_refund.html+++ b/saleor/dashboard/templates/dashboard/includes/modal_capture_refund.html@@ -7,12 +7,11 @@<h3>{{ action|capfirst }} {% trans "payment" %}</h3></div><div class="modal-body">- <form id="modal-form" class="form-inline" role="form" method="post" action={% url 'dashboard:manage-payment' pk=payment.pk %}>+ <form id="modal-form" class="form-inline" role="form" method="post" action={% url 'dashboard:manage-payment' pk=payment.pk action=action %}>{% csrf_token %}<div class="form-group"><label class="control-label" for="amount">{% blocktrans %}Amount to {{ action }}:{% endblocktrans %}</label>{% render_widget form.amount class="form-control" %} {{ currency }}- {{ form.action }}</div></form><p>{% trans "Before this action" %}</p>diff --git a/saleor/dashboard/templates/dashboard/includes/modal_release.html b/saleor/dashboard/templates/dashboard/includes/modal_release.htmlindex 696896fb4a..c67921580f 100644--- a/saleor/dashboard/templates/dashboard/includes/modal_release.html+++ b/saleor/dashboard/templates/dashboard/includes/modal_release.html@@ -9,9 +9,8 @@<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" action={% url 'dashboard:manage-payment' pk=payment.pk %}>+ <form id="release-form" class="form-inline" method="post" role="form" action={% url 'dashboard:manage-payment' pk=payment.pk action=action %}>{% csrf_token %}- {{ form.action }}<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>diff --git a/saleor/dashboard/templates/dashboard/order/detail.html b/saleor/dashboard/templates/dashboard/order/detail.htmlindex eb79fc385f..bf68268474 100644--- a/saleor/dashboard/templates/dashboard/order/detail.html+++ b/saleor/dashboard/templates/dashboard/order/detail.html@@ -76,12 +76,12 @@<p>Refunded amount: {% gross refunded %}</p>{% endif %}{% if can_capture %}- <a class="btn btn-success" data-target="#base-modal" href="{% url 'dashboard:manage-payment' pk=payment.pk %}?action=capture" data-toggle="modal">{% trans "Capture" %}</a>+ <a class="btn btn-success" data-target="#base-modal" href="{% url 'dashboard:manage-payment' pk=payment.pk action='capture' %}" data-toggle="modal">{% trans "Capture" %}</a>{% elif can_refund %}- <a class="btn btn-danger" data-target="#base-modal" href="{% url 'dashboard:manage-payment' pk=payment.pk %}?action=refund" data-toggle="modal">{% trans "Refund" %}</a>+ <a class="btn btn-danger" data-target="#base-modal" href="{% url 'dashboard:manage-payment' pk=payment.pk action='refund' %}" data-toggle="modal">{% trans "Refund" %}</a>{% endif %}{% if can_release %}- <a class="btn btn-danger" data-target="#base-modal" href="{% url 'dashboard:manage-payment' pk=payment.pk %}?action=release" data-toggle="modal">{% trans "Release" %}</a>+ <a class="btn btn-danger" data-target="#base-modal" href="{% url 'dashboard:manage-payment' pk=payment.pk action='release' %}" data-toggle="modal">{% trans "Release" %}</a>{% endif %}{% else %}<span>{% trans "No payment for this order" %}</span>