You are here

public function ZoomApiWebhooksController::capture in Zoom API 2.0.x

Same name and namespace in other branches
  1. 8 src/Controller/ZoomApiWebhooksController.php \Drupal\zoomapi\Controller\ZoomApiWebhooksController::capture()

Capture the incoming payload.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request object.

Return value

\Symfony\Component\HttpFoundation\JsonResponse A simple JSON response.

1 string reference to 'ZoomApiWebhooksController::capture'
zoomapi.routing.yml in ./zoomapi.routing.yml
zoomapi.routing.yml

File

src/Controller/ZoomApiWebhooksController.php, line 124

Class

ZoomApiWebhooksController
Class ZoomApiWebhooksController.

Namespace

Drupal\zoomapi\Controller

Code

public function capture(Request $request) {

  // Capture the payload.
  $payload = $request
    ->getContent();

  // Check if the payload is empty.
  if (empty($payload)) {
    $message = 'The Zoom webhook payload was missing.';
    $this->logger
      ->notice($message);
    $response = [
      'success' => FALSE,
      'message' => $message,
      'data' => [],
    ];
    return new JsonResponse($response, 400);
  }

  // JSON decode the payload.
  // TODO: We could do additional error checking of the payload.
  $data = Json::decode($payload);

  // Ability to debug the incoming payload.
  if ($this->debug) {
    $this->logger
      ->debug('<pre><code>' . print_r($data, TRUE) . '</code></pre>');
  }

  // Dispatch Event.
  // Allows other modules to respond.
  // Var $data['event'] = Name of webhook event from Zoom.
  // Var $data['payload'] = Payload data from Zoom.
  // Var $request = The complete request from Zoom.
  $dispatch = new ZoomApiWebhookEvent($data['event'], $data['payload'], $request);
  $this->eventDispatcher
    ->dispatch(ZoomApiEvents::WEBHOOK_POST, $dispatch);
  $response = [
    'success' => TRUE,
    'message' => 'Webhook payload captured!',
    'data' => [],
  ];
  return new JsonResponse($response);
}