I have some code which checks for data coming from Stripe's Webhook. Now I got some code that queries my database to check if the payment has been confirmed. I am trying to write a function that checks my database to see if the payment has been confirmed, if the payment has not yet been confirmed, the program should wait 5 seconds and then check again, checking a maximum of 5 times. If after the fifth try the payment still does not show as confirmed, then I need to redirect the user.
This is because my code might execute faster than Stripe returns their webhook response to my server.
Current code below. How do I create the 'loop' on the if statement?
def accepted(request, payment_id):
r = Usertasks.objects.all().filter(user=request.user).filter(randomURL=payment_id).values("TaskPostedToNetwork")
e = Usertasks.objects.all().filter(user=request.user).filter(randomURL=payment_id).values("PaymentConfirmed")
if r == "False" and e == "yes":
print("true")
else:
return redirect('dashboard:index')
return render(request, 'request.html',)