Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/api/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -96,6 +106,7 @@ def before_create_object(self, data, view_kwargs):
:param view_kwargs:
:return:
"""
check_billing_info(data)

free_ticket_quantity = 0

Expand Down Expand Up @@ -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")

Expand Down