diff --git a/insalan/payment/views.py b/insalan/payment/views.py index d4fd5670..f4bf965f 100644 --- a/insalan/payment/views.py +++ b/insalan/payment/views.py @@ -83,13 +83,24 @@ def get(self, request, **kwargs): transaction_obj.payment_status = TransactionStatus.FAILED transaction_obj.touch() transaction_obj.save() + return Response(status=status.HTTP_403_FORBIDDEN) transaction_obj.payment_status = TransactionStatus.SUCCEEDED transaction_obj.touch() transaction_obj.save() - return Response(transaction_obj) + # Execute hooks + for proccount in ProductCount.objects.filter(transaction=transaction_obj): + # Get callback class + cls = PaymentCallbackSystem.retrieve_handler(proccount.product.category) + if cls is None: + logger.warning("No handler found for payment of %s", proccount.product) + return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR) + # Call callback class + cls.payment_success(transaction_obj, proccount.product, proccount.count) + + return Response(status=status.HTTP_200_OK) class ErrorView(generics.ListAPIView): pass @@ -148,5 +159,16 @@ def create(self, request): transaction_obj.intent_id = intent_id transaction_obj.save() logger.debug(intent_body) + + # Execute hooks + for proccount in ProductCount.objects.filter(transaction=transaction_obj): + # Get callback class + cls = PaymentCallbackSystem.retrieve_handler(proccount.product.category) + if cls is None: + logger.warning("No handler found for payment of %s", proccount.product) + return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR) + # Call callback class + cls.prepare_transaction(transaction_obj, proccount.product, proccount.count) + return HttpResponseRedirect(redirect_to=redirect_url) return JsonResponse({"problem": "oui"}) diff --git a/insalan/tournament/models.py b/insalan/tournament/models.py index 6f9ca49e..a1c2bc47 100644 --- a/insalan/tournament/models.py +++ b/insalan/tournament/models.py @@ -19,6 +19,7 @@ ) from django.utils.translation import gettext_lazy as _ +from insalan.tickets.models import Ticket from insalan.user.models import User