summaryrefslogtreecommitdiffstats
path: root/restaurant_orders/wordpress_integration
diff options
context:
space:
mode:
authorjdlugosz963 <jdlugosz963@gmail.com>2023-07-17 01:47:57 +0200
committerjdlugosz963 <jdlugosz963@gmail.com>2023-07-17 01:52:26 +0200
commitc21f4b3dacd597a15a5ec39d525df1dfe1b70376 (patch)
tree0dfc51d2ffeb7b5022d9ad852f2fd3620c72196a /restaurant_orders/wordpress_integration
parent2c6f98aeef4fa1aba5678fe17c8e762a11db7b40 (diff)
downloadrestaurant-orders-c21f4b3dacd597a15a5ec39d525df1dfe1b70376.tar.gz
restaurant-orders-c21f4b3dacd597a15a5ec39d525df1dfe1b70376.zip
Add project.main
Diffstat (limited to 'restaurant_orders/wordpress_integration')
-rw-r--r--restaurant_orders/wordpress_integration/__init__.py0
-rw-r--r--restaurant_orders/wordpress_integration/admin.py1
-rw-r--r--restaurant_orders/wordpress_integration/apps.py6
-rw-r--r--restaurant_orders/wordpress_integration/urls.py8
-rw-r--r--restaurant_orders/wordpress_integration/views.py22
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 @@
1from django.apps import AppConfig
2
3
4class 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 @@
1from wordpress_integration.views import webhook
2from django.urls import path
3
4app_name = 'wordpress_integration'
5
6urlpatterns = [
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 @@
1from core.models import Restaurant, Order
2from core.decorators import woocommerce_authentication_required
3
4from django.shortcuts import HttpResponse, get_object_or_404
5from django.views.decorators.csrf import csrf_exempt
6from django.views.decorators.http import require_POST
7import json
8
9@csrf_exempt
10@require_POST
11@woocommerce_authentication_required
12def 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')