diff --git a/app/api/orders.py b/app/api/orders.py index 9b2dabfa5c..c68af53905 100644 --- a/app/api/orders.py +++ b/app/api/orders.py @@ -63,6 +63,16 @@ def is_payment_valid(order, mode): return (order.paid_via == 'paypal') and order.transaction_id +def check_billing_info(data): + if data.get('amount') > 0 and not data.get('is_billing_enabled'): + raise UnprocessableEntity({'pointer': '/data/attributes/is_billing_enabled'}, + "Billing information is mandatory for paid orders") + if data.get('is_billing_enabled') and not (data.get('company') and data.get('address') and data.get('city') and + data.get('zip') and data.get('country')): + raise UnprocessableEntity({'pointer': '/data/attributes/is_billing_enabled'}, + "Billing information incomplete") + + class OrdersListPost(ResourceList): """ OrderListPost class for OrderSchema @@ -96,6 +106,7 @@ def before_create_object(self, data, view_kwargs): :param view_kwargs: :return: """ + check_billing_info(data) free_ticket_quantity = 0 @@ -299,6 +310,7 @@ def before_update_object(self, order, data, view_kwargs): :param view_kwargs: :return: """ + check_billing_info(data) if (not has_access('is_coorganizer', event_id=order.event_id)) and (not current_user.id == order.user_id): raise ForbiddenException({'pointer': ''}, "Access Forbidden")