Skip to content

Commit

Permalink
🪙 Execute product callback hooks on payment
Browse files Browse the repository at this point in the history
In the payment API, when a payment is initiated, call the preparation
hooks of a payment hook class. In the return view, call the accept
hooks.
  • Loading branch information
Lymkwi committed Oct 15, 2023
1 parent ab74dc3 commit ef1cd45
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
24 changes: 23 additions & 1 deletion insalan/payment/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"})
1 change: 1 addition & 0 deletions insalan/tournament/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
)
from django.utils.translation import gettext_lazy as _

from insalan.tickets.models import Ticket
from insalan.user.models import User


Expand Down

0 comments on commit ef1cd45

Please sign in to comment.