Django receive POST from webhook
Our App is receiving webhooks via POST from our payment processor. When I was building this function I originally had it to GET for testing purposes so I could use the URL to test paramaters. Everything worked fine but now I need to test with fake purchases which sends POST request to our URL. So I updated the code but no new webhooks are being saved in our database now.
@require_POST def webhook(request): template_name = 'payment/index.html' hook = Webhook() user = User.objects.get(id=request.POST.get('clientAccnum', '')) hook.user = user hook.clientSubacc = request.POST.get('clientSubacc', '') hook.eventType = request.POST.get('eventType') hook.eventGroupType = request.POST.get('eventGroupType', '') hook.subscriptionId = request.POST.get('subscriptionId', '') hook.timestamp = request.POST.get('timestamp', '') hook.timestamplocal = timezone.now() hook.save() hook.user.profile.account_paid = hook.eventType == 'RenewalSuccess' hook.user.profile.save() return render(request, template_name)
class Webhook(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE, null=False) clientSubacc = models.CharField(max_length=120, blank=True, null=True) eventType = models.CharField(max_length=120, blank=True, null=True) eventGroupType = models.CharField(max_length=120, blank=True, null=True) subscriptionId = models.CharField(max_length=120, blank=True, null=True) timestamp = models.DateTimeField(blank=True, null=True) timestamplocal = models.DateTimeField(blank=True, null=True)
I'm firing POST requests now from our payment processor and their support is telling me webhooks are being fired but nothing new is saving in the db. This leads me to believe the views.py code is wrong.
Anyway I can test this?