cancel
Showing results for 
Search instead for 
Did you mean: 

Configure module to receive webhooks from external service

Configure module to receive webhooks from external service

I need to set up the module I'm building to listen for webhooks from an external service.  What is the right approach for this?  I've been trying to set up etc/frontend/routes.xml like so:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route id="paystandmagento" frontName="paystandmagento">
            <module name="PayStand_PayStandMagento" />
        </route>
    </router>
</config>

I have a controller at Controller/Webhook/PayStand.php like this:

<?php

namespace PayStand\PayStandMagento\Controller;

/**
 * Webhook Receiver Controller
 */
class WebhookReceiver extends \Magento\Framework\App\Action\Action
{
  /** @var \Psr\Log\LoggerInterface  */
  protected $_logger;

  /**
   * @param \Magento\Framework\App\Action\Context $context
   * @param \Psr\Log\LoggerInterface $logger
   */
  public function __construct(
    \Magento\Framework\App\Action\Context $context,
    \Psr\Log\LoggerInterface $logger
  ) {
    $this->_logger = $logger;
    parent::__construct($context);
  }

  /**
   * Receives webhook events from Roadrunner
   */
  public function execute()
  {
    $this->_logger->addDebug('paystandmagento/webhook/paystand endpoint was hit');
  }
}

However, when I try to send a post request to http://<<magento base url>>/paystandmagento/webhook/paystand/ I get a 404 error page in response.  What I want is for the endpoint to not return anything but a http 200 code, but for my controller to have access to the data payload to act upon.

 

Can this be done with routes, or do I need to configure a web api?  I don't have control of the service that will be sending me webhooks except to set to url, so I can't use authentication.

 

Googling for answers here is difficult because searching for "Magento webhook" keeps returning results about the magento system sending out webhooks for it's own events - nothing about how to receive a webhook from outside.

1 REPLY 1

Re: Configure module to receive webhooks from external service

I want the same thing but unable to get any thing