diff options
author | jdlugosz963 <jdlugosz963@gmail.com> | 2023-07-17 01:47:57 +0200 |
---|---|---|
committer | jdlugosz963 <jdlugosz963@gmail.com> | 2023-07-17 01:52:26 +0200 |
commit | c21f4b3dacd597a15a5ec39d525df1dfe1b70376 (patch) | |
tree | 0dfc51d2ffeb7b5022d9ad852f2fd3620c72196a /restaurant_orders/wordpress_integration/views.py | |
parent | 2c6f98aeef4fa1aba5678fe17c8e762a11db7b40 (diff) | |
download | restaurant-orders-main.tar.gz restaurant-orders-main.zip |
Add project.main
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') | ||