1 | <?php |
||
10 | class WebhookRequestHandler |
||
11 | { |
||
12 | /** |
||
13 | * @var ServerRequestInterface |
||
14 | */ |
||
15 | private $request; |
||
16 | |||
17 | /** |
||
18 | * App secret used to verify the request sha1 |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | private $secret; |
||
23 | |||
24 | /** |
||
25 | * @var array |
||
26 | */ |
||
27 | private $decodedBody; |
||
28 | |||
29 | /** |
||
30 | * @var Entry[] |
||
31 | */ |
||
32 | private $hydratedEntries; |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | private $body; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | */ |
||
42 | private $verifyToken; |
||
43 | |||
44 | /** |
||
45 | * @param string $secret |
||
46 | * @param string $verifyToken |
||
47 | * @param ServerRequestInterface|null $request |
||
48 | */ |
||
49 | 10 | public function __construct($secret, $verifyToken, ServerRequestInterface $request = null) |
|
55 | |||
56 | /** |
||
57 | * Check if the token match with the given verify token. |
||
58 | * This is useful in the webhook setup process. |
||
59 | * |
||
60 | * @return bool |
||
61 | */ |
||
62 | 1 | public function isValidVerifyTokenRequest() |
|
76 | |||
77 | /** |
||
78 | * @return null|string |
||
79 | */ |
||
80 | 1 | public function getChallenge() |
|
86 | |||
87 | /** |
||
88 | * Check if the request is a valid webhook request |
||
89 | * |
||
90 | * @return bool |
||
91 | */ |
||
92 | 3 | public function isValidCallbackRequest() |
|
105 | |||
106 | /** |
||
107 | * Check if the request is a valid webhook request |
||
108 | * |
||
109 | * @deprecated use WebhookRequestHandler::isValidCallbackRequest() instead |
||
110 | * |
||
111 | * @return bool |
||
112 | */ |
||
113 | public function isValid() |
||
117 | |||
118 | /** |
||
119 | * @return CallbackEvent[] |
||
120 | */ |
||
121 | 1 | public function getAllCallbackEvents() |
|
131 | |||
132 | /** |
||
133 | * @return Entry[] |
||
134 | */ |
||
135 | 1 | public function getEntries() |
|
139 | |||
140 | /** |
||
141 | * @return ServerRequestInterface |
||
142 | */ |
||
143 | 1 | public function getRequest() |
|
147 | |||
148 | /** |
||
149 | * @return array |
||
150 | */ |
||
151 | 4 | public function getDecodedBody() |
|
161 | |||
162 | /** |
||
163 | * @return Entry[] |
||
164 | */ |
||
165 | 2 | private function getHydratedEntries() |
|
182 | |||
183 | /** |
||
184 | * @return string |
||
185 | */ |
||
186 | 6 | private function getBody() |
|
196 | |||
197 | /** |
||
198 | * @return bool |
||
199 | */ |
||
200 | 3 | private function isValidHeader() |
|
212 | } |
||
213 |