Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Use payment status_change signal
Michal Ociepkab1d06d2c4ecf
diff --git a/order/views.py b/order/views.pyindex cc8be4cc46..820b4e14f6 100644--- a/order/views.py+++ b/order/views.py@@ -1,8 +1,11 @@-from django.shortcuts import get_object_or_404+from django.shortcuts import get_object_or_404, redirectfrom django.template.response import TemplateResponsefrom order.models import Orderdef success(request, token):order = get_object_or_404(Order, token=token)- return TemplateResponse(request, 'order/success.html', {'order': order})+ if order.status == 'complete':+ return TemplateResponse(request, 'order/success.html',+ {'order': order})+ return redirect('order:payment:index', token=order.token)diff --git a/payment/__init__.py b/payment/__init__.pyindex 20a0a1414e..d98f2c02eb 100644--- a/payment/__init__.py+++ b/payment/__init__.py@@ -1,6 +1,8 @@from authorizenet.utils import process_paymentfrom django.utils.translation import ugettextimport urllib2+from payments.signals import status_changed+from django.dispatch import receiverclass PaymentFailure(Exception):@@ -39,3 +41,11 @@ def authorizenet(order, cleaned_data, capture=True):raise PaymentFailure(ugettext('Could not connect to the gateway.'))if not response.is_approved:raise PaymentFailure(response.response_reason_text)+++@receiver(status_changed)+def order_status_change(sender, instance, **kwargs):+ order = instance.order+ if order.is_full_paid():+ order.status = 'complete'+ order.save()