diff options
Diffstat (limited to 'restaurant_orders/wordpress_integration')
5 files changed, 37 insertions, 0 deletions
diff --git a/restaurant_orders/wordpress_integration/__init__.py b/restaurant_orders/wordpress_integration/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/restaurant_orders/wordpress_integration/__init__.py | |||
diff --git a/restaurant_orders/wordpress_integration/admin.py b/restaurant_orders/wordpress_integration/admin.py new file mode 100644 index 0000000..694323f --- /dev/null +++ b/restaurant_orders/wordpress_integration/admin.py | |||
@@ -0,0 +1 @@ | |||
from django.contrib import admin | |||
diff --git a/restaurant_orders/wordpress_integration/apps.py b/restaurant_orders/wordpress_integration/apps.py new file mode 100644 index 0000000..f2fd48f --- /dev/null +++ b/restaurant_orders/wordpress_integration/apps.py | |||
@@ -0,0 +1,6 @@ | |||
1 | from django.apps import AppConfig | ||
2 | |||
3 | |||
4 | class WordpressIntegrationConfig(AppConfig): | ||
5 | default_auto_field = 'django.db.models.BigAutoField' | ||
6 | name = 'wordpress_integration' | ||
diff --git a/restaurant_orders/wordpress_integration/urls.py b/restaurant_orders/wordpress_integration/urls.py new file mode 100644 index 0000000..2489b9a --- /dev/null +++ b/restaurant_orders/wordpress_integration/urls.py | |||
@@ -0,0 +1,8 @@ | |||
1 | from wordpress_integration.views import webhook | ||
2 | from django.urls import path | ||
3 | |||
4 | app_name = 'wordpress_integration' | ||
5 | |||
6 | urlpatterns = [ | ||
7 | path('<int:restaurant_pk>/', webhook, name='webhook'), | ||
8 | ] | ||
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') | ||