From c21f4b3dacd597a15a5ec39d525df1dfe1b70376 Mon Sep 17 00:00:00 2001 From: jdlugosz963 Date: Mon, 17 Jul 2023 01:47:57 +0200 Subject: Add project. --- .../wordpress_integration/__init__.py | 0 restaurant_orders/wordpress_integration/admin.py | 1 + restaurant_orders/wordpress_integration/apps.py | 6 ++++++ restaurant_orders/wordpress_integration/urls.py | 8 ++++++++ restaurant_orders/wordpress_integration/views.py | 22 ++++++++++++++++++++++ 5 files changed, 37 insertions(+) create mode 100644 restaurant_orders/wordpress_integration/__init__.py create mode 100644 restaurant_orders/wordpress_integration/admin.py create mode 100644 restaurant_orders/wordpress_integration/apps.py create mode 100644 restaurant_orders/wordpress_integration/urls.py create mode 100644 restaurant_orders/wordpress_integration/views.py (limited to 'restaurant_orders/wordpress_integration') diff --git a/restaurant_orders/wordpress_integration/__init__.py b/restaurant_orders/wordpress_integration/__init__.py new file mode 100644 index 0000000..e69de29 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 @@ +from django.apps import AppConfig + + +class WordpressIntegrationConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + 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 @@ +from wordpress_integration.views import webhook +from django.urls import path + +app_name = 'wordpress_integration' + +urlpatterns = [ + path('/', webhook, name='webhook'), +] 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 @@ +from core.models import Restaurant, Order +from core.decorators import woocommerce_authentication_required + +from django.shortcuts import HttpResponse, get_object_or_404 +from django.views.decorators.csrf import csrf_exempt +from django.views.decorators.http import require_POST +import json + +@csrf_exempt +@require_POST +@woocommerce_authentication_required +def webhook(request, restaurant_pk): + payload = request.body.decode('utf-8') + restaurant = get_object_or_404(Restaurant, pk=restaurant_pk) + + order = Order.update_or_create_from_response(json.loads(payload), restaurant) + if order is None: + response = HttpResponse('Error, cannot read order properties!') + response.status_code = 400 + return response + + return HttpResponse('success') -- cgit v1.2.3