Jump to content
Zeka

How to debug real request from remote server.

Recommended Posts

I have a module that listening for webhook notification on specific URL:

<?php namespace ProcessWire;

class ProcessPayments extends WireData implements Module, ConfigurableModule
{
	public function init()
	{
		$this->addHookBefore('ProcessPageView::execute', $this, 'runPayments');
	}

	public function ready() {

	}

	public function runPayments($event)
	{
		$it = isset($_GET['it']) ? $_GET['it'] : "";
		if (substr($it, 0, 1) === '/') $it = ltrim($it, "/");
		if (strpos($it, "webhooks/") !== false) {
          $this->checkRequest();
		} else {
			return;
		}

		switch ($it) {
			case 'webhooks/pay':
				$this->handlePayRequest();
				exit();
				break;
		}
	}

	private function checkRequest()
	{
		$this->checkRequestHMAC();
		return true;
	}

	...
}

Currently, for debugging real request from a remote server I use logs, but this is so inconvenient and slow after using dumps from TracyDebugger ( @adrian  is there something in TracyDebugger that can help? ). 

So looking for advice about how to debug such request, are there some tools for it? 

Share this post


Link to post
Share on other sites

@bernhard @adrian Wow, tracy's Request Logger Panel is what I was looking for and it works great with standard pages. 

But I have difficulties in getting it to work in my case.

As you could see I hooking into 'before' ProcessPageView::execute in 'init' stage and I don't have any page or template for this URL, so there is no page object available and I can't use  $this->wire('page')->logRequests();

1130597126_FireShotCapture013--https___brandhuman.ru_webhooks_pay.png.24d28dad6f035a931c08201be117d840.png

That's all that I have from Tracy.

Am I missing something? 

 

Share this post


Link to post
Share on other sites

Is there a reason you can't move the hook to ready where you will have the page object?

  • Like 1

Share this post


Link to post
Share on other sites

Yes, I can't move it to ready as I need to change the output depending on an incoming request.

Basically, I have to return {'code': 0} if I have a valid incoming request and on ready stage, I already have rendered 404 page.

Maybe there is a better place for a hook? 

I have changed ProcessPageView::execute to ProcessPageView::ready and now everything works. Thank for the help, TracyDebugger and Logger panel! 

  • Like 4

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...