Skip to content

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

Block payments if not enough data

Anna Siwik94017d86d807
diff --git a/saleor/dashboard/order/urls.py b/saleor/dashboard/order/urls.py
index 1f6b34d60d..2c3d362355 100644
--- a/saleor/dashboard/order/urls.py
+++ b/saleor/dashboard/order/urls.py
@@ -57,4 +57,5 @@ urlpatterns = [
views.order_invoice, name='order-invoice'),
url('^(?P<order_pk>\d+)/ajax/shipping-methods/$',
- views.ajax_order_shipping_methods_list, name='ajax-order-shipping-methods')]
+ views.ajax_order_shipping_methods_list,
+ name='ajax-order-shipping-methods')]
diff --git a/saleor/dashboard/order/utils.py b/saleor/dashboard/order/utils.py
index f50f652d51..521d0c50fa 100644
--- a/saleor/dashboard/order/utils.py
+++ b/saleor/dashboard/order/utils.py
@@ -3,7 +3,6 @@ from django.contrib.sites.shortcuts import get_current_site
from django.template.loader import get_template
from prices import Money
-from saleor.product.models import ProductVariant
from ...discount import VoucherType
from ...discount.models import NotApplicable
from ...discount.utils import (
diff --git a/saleor/order/utils.py b/saleor/order/utils.py
index d5b172c96e..dc6673573e 100644
--- a/saleor/order/utils.py
+++ b/saleor/order/utils.py
@@ -12,9 +12,11 @@ from ..product.utils import allocate_stock, deallocate_stock, increase_stock
def check_order_status(func):
- """Prevent execution of decorated function if order is fully paid.
+ """Check if order meets preconditions of payment process.
- Instead redirects to order details page.
+ Order can not have draft status or be fully paid. Billing address
+ must be provided.
+ If not, redirect to order details page.
"""
# pylint: disable=cyclic-import
from .models import Order
@@ -23,7 +25,10 @@ def check_order_status(func):
def decorator(*args, **kwargs):
token = kwargs.pop('token')
order = get_object_or_404(Order, token=token)
- if order.is_fully_paid():
+ can_be_paid = (
+ order.status != OrderStatus.DRAFT and order.billing_address and
+ not order.is_fully_paid())
+ if not can_be_paid:
return redirect('order:details', token=order.token)
kwargs['order'] = order
return func(*args, **kwargs)
@@ -52,7 +57,8 @@ def recalculate_order(order, discount_amount=None):
def cancel_order(order, restock):
"""Cancel order and associated fulfillments.
- Return products to corresponding stocks if restock is set to True."""
+ Return products to corresponding stocks if restock is set to True.
+ """
if restock:
restock_order_lines(order)
for fulfillment in order.fulfillments.all():
@@ -82,7 +88,8 @@ def update_order_status(order):
def cancel_fulfillment(fulfillment, restock):
"""Cancel fulfillment.
- Return products to corresponding stocks if restock is set to True."""
+ Return products to corresponding stocks if restock is set to True.
+ """
if restock:
restock_fulfillment_lines(fulfillment)
for line in fulfillment:
diff --git a/saleor/order/views.py b/saleor/order/views.py
index 0168a018b3..be542b3eea 100644
--- a/saleor/order/views.py
+++ b/saleor/order/views.py
@@ -49,8 +49,9 @@ def details(request, token):
def payment(request, token):
- orders = Order.objects.prefetch_related('lines__product')
- orders = orders.select_related(
+ orders = Order.objects.exclude(
+ status=OrderStatus.DRAFT).filter(billing_address__isnull=False)
+ orders = orders.prefetch_related('lines__product').select_related(
'billing_address', 'shipping_address', 'user')
order = get_object_or_404(orders, token=token)
payments = order.payments.all()