Files
shoppy/shop/views.py
T
2025-01-16 23:32:03 +01:00

23 lines
645 B
Python

from django.http.response import HttpResponse
from django.shortcuts import get_object_or_404
from django.views.decorators.csrf import csrf_exempt
from shop.models import Order
from shop.utils import add_payment_to_order, validate_payment_for_order
@csrf_exempt
def webhook(request, uuid):
order = get_object_or_404(Order, uuid=uuid)
try:
amount_paid = validate_payment_for_order(request, order)
add_payment_to_order(order, amount_paid)
return HttpResponse(status=200)
except Exception as e:
order.status = Order.Statuses.STATUS_ERROR
order.save()
return HttpResponse(status=409)