diff options
Diffstat (limited to 'restaurant_orders/wordpress_integration/views.py')
| -rw-r--r-- | restaurant_orders/wordpress_integration/views.py | 22 | 
1 files changed, 22 insertions, 0 deletions
diff --git a/restaurant_orders/wordpress_integration/views.py b/restaurant_orders/wordpress_integration/views.py new file mode 100644 index 0000000..de6695f --- /dev/null +++ b/restaurant_orders/wordpress_integration/views.py  | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | from core.models import Restaurant, Order | ||
| 2 | from core.decorators import woocommerce_authentication_required | ||
| 3 | |||
| 4 | from django.shortcuts import HttpResponse, get_object_or_404 | ||
| 5 | from django.views.decorators.csrf import csrf_exempt | ||
| 6 | from django.views.decorators.http import require_POST | ||
| 7 | import json | ||
| 8 | |||
| 9 | @csrf_exempt | ||
| 10 | @require_POST | ||
| 11 | @woocommerce_authentication_required | ||
| 12 | def webhook(request, restaurant_pk): | ||
| 13 | payload = request.body.decode('utf-8') | ||
| 14 | restaurant = get_object_or_404(Restaurant, pk=restaurant_pk) | ||
| 15 | |||
| 16 | order = Order.update_or_create_from_response(json.loads(payload), restaurant) | ||
| 17 | if order is None: | ||
| 18 | response = HttpResponse('Error, cannot read order properties!') | ||
| 19 | response.status_code = 400 | ||
| 20 | return response | ||
| 21 | |||
| 22 | return HttpResponse('success') | ||
