blob: de6695f93dc8cf94cfcca16883c90892385ef22a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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')
|