Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
WebhookMessageReader.php
Go to the documentation of this file.
1 <?php
7 
9 
14 {
18  private $dataDecoder;
19 
23  private $webhookMessageFactory;
24 
29  public function __construct(
30  DecoderInterface $decoder,
31  WebhookMessageFactory $webhookMessageFactory
32  ) {
33  $this->dataDecoder = $decoder;
34  $this->webhookMessageFactory = $webhookMessageFactory;
35  }
36 
44  public function read(WebhookRequest $request)
45  {
46  try {
47  $decodedData = $this->dataDecoder->decode($request->getBody());
48  } catch (\Exception $e) {
49  throw new \InvalidArgumentException(
50  'Webhook request body is not valid JSON: ' . $e->getMessage(),
51  $e->getCode(),
52  $e
53  );
54  }
55 
56  $webhookMessage = $this->webhookMessageFactory->create(
57  [
58  'data' => $decodedData,
59  'eventTopic' => $request->getEventTopic()
60  ]
61  );
62 
63  return $webhookMessage;
64  }
65 }
__construct(DecoderInterface $decoder, WebhookMessageFactory $webhookMessageFactory)