From c21f4b3dacd597a15a5ec39d525df1dfe1b70376 Mon Sep 17 00:00:00 2001 From: jdlugosz963 Date: Mon, 17 Jul 2023 01:47:57 +0200 Subject: Add project. --- restaurant_orders/wordpress_integration/views.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 restaurant_orders/wordpress_integration/views.py (limited to 'restaurant_orders/wordpress_integration/views.py') 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