@@ -24,6 +24,10 @@ class ApiRequest implements ApiRequestInterface
2424 const REPORT_ORDERS_API_V4 = '/api/v4/reports/orders ' ;
2525 const REPORT_ORDER_DETAILS_API = '/api/v4/reports/order-details ' ;
2626 const PODELI_MERCHANT_REGISTRATION_API = '/api/v4/registration/merchant/podeli ' ;
27+ const QST_CREATE_API = '/api/v4/qst/create ' ;
28+ const QST_STATUS_API = '/api/v4/qst/status ' ;
29+ const QST_PRINT_API = '/api/v4/qst/print ' ;
30+ const QST_LIST_API = '/api/v4/qst/list ' ;
2731 const HOST = 'https://secure.ypmn.ru ' ;
2832 const SANDBOX_HOST = 'https://sandbox.ypmn.ru ' ;
2933 const LOCAL_HOST = 'http://127.0.0.1 ' ;
@@ -40,6 +44,9 @@ class ApiRequest implements ApiRequestInterface
4044 /** @var bool Режим Отладки (вывод системных сообщений) */
4145 private bool $ debugModeIsOn = false ;
4246
47+ /** @var bool Отображать заголовки ответа в режим отладки */
48+ private bool $ debugShowResponseHeaders = true ;
49+
4350 /** @var bool Формат результата в режиме отладки */
4451 private bool $ jsonDebugResponse = true ;
4552
@@ -220,6 +227,12 @@ private function sendGetRequest(string $api): array
220227 ]
221228 ];
222229
230+ $ headers = [];
231+
232+ if ($ this ->getDebugShowResponseHeaders ()) {
233+ $ this ->addCurlOptHeaderFunction ($ setopt_array , $ headers );
234+ }
235+
223236 curl_setopt_array ($ curl , $ setopt_array );
224237
225238 $ response = curl_exec ($ curl );
@@ -231,11 +244,16 @@ private function sendGetRequest(string $api): array
231244 $ this ->echoDebugMessage ($ this ->getHost () . $ api );
232245 $ this ->echoDebugMessage ('Ответ от сервера Ypmn: ' );
233246 if ($ this ->getJsonDebugResponse ()) {
234- $ this ->echoDebugMessage (json_encode (json_decode ($ response ), JSON_PRETTY_PRINT ));
247+ $ this ->echoDebugMessage (json_encode (json_decode ($ response ), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE ));
235248 } else {
236249 $ this ->echoDebugMessage ($ response );
237250 }
238251
252+ if ($ this ->getDebugShowResponseHeaders ()) {
253+ $ this ->echoDebugMessage ('Заголовки ответа от сервера Ypmn: ' );
254+ $ this ->echoDebugMessage (implode ("\n" , $ headers ));
255+ }
256+
239257 if (mb_strlen ($ err ) > 0 ) {
240258 $ this ->echoDebugMessage ('Ошибка ' );
241259 echo '<br>Вы можете отправить запрос на поддержку на <a href="mailto:[email protected] ?subject=YPMN_Integration">[email protected] </a> ' ;
@@ -296,7 +314,7 @@ public function sendPostRequest($data, string $api): array
296314 $ date = (new DateTime ())->format (DateTimeInterface::ATOM );
297315 $ requestHttpVerb = 'POST ' ;
298316
299- curl_setopt_array ( $ curl , [
317+ $ setOptArray = [
300318 CURLOPT_URL => $ this ->getHost () . $ api ,
301319 CURLOPT_RETURNTRANSFER => true ,
302320 CURLOPT_ENCODING => '' ,
@@ -318,7 +336,15 @@ public function sendPostRequest($data, string $api): array
318336 $ encodedJsonDataHash
319337 )
320338 ]
321- ]);
339+ ];
340+
341+ $ headers = [];
342+
343+ if ($ this ->getDebugShowResponseHeaders ()) {
344+ $ this ->addCurlOptHeaderFunction ($ setOptArray , $ headers );
345+ }
346+
347+ curl_setopt_array ($ curl , $ setOptArray );
322348
323349 $ response = curl_exec ($ curl );
324350 $ err = curl_error ($ curl );
@@ -328,7 +354,12 @@ public function sendPostRequest($data, string $api): array
328354 $ this ->echoDebugMessage ('POST-Запрос к серверу Ypmn: ' );
329355 $ this ->echoDebugMessage ($ encodedJsonData );
330356 $ this ->echoDebugMessage ('Ответ от сервера Ypmn: ' );
331- $ this ->echoDebugMessage (json_encode (json_decode ($ response ), JSON_PRETTY_PRINT ));
357+ $ this ->echoDebugMessage (json_encode (json_decode ($ response ), JSON_PRETTY_PRINT |JSON_UNESCAPED_UNICODE ));
358+
359+ if ($ this ->getDebugShowResponseHeaders ()) {
360+ $ this ->echoDebugMessage ('Заголовки ответа от сервера Ypmn: ' );
361+ $ this ->echoDebugMessage (implode ("\n" , $ headers ));
362+ }
332363
333364 if (mb_strlen ($ err ) > 0 ) {
334365 $ this ->echoDebugMessage ('Ошибка ' );
@@ -594,4 +625,60 @@ public function sendPodeliRegistrationMerchantRequest(PodeliMerchant $merchant):
594625 {
595626 return $ this ->sendPostRequest ($ merchant , self ::PODELI_MERCHANT_REGISTRATION_API );
596627 }
628+
629+ /** @inheritdoc */
630+ public function sendQstCreateRequest (QstInterface $ qst ): array
631+ {
632+ return $ this ->sendPostRequest ($ qst , self ::QST_CREATE_API );
633+ }
634+
635+ /** @inheritdoc */
636+ public function sendQstStatusRequest (int $ qstId ): array
637+ {
638+ return $ this ->sendGetRequest (self ::QST_STATUS_API . '/ ' . $ qstId );
639+ }
640+
641+ /** @inheritdoc */
642+ public function sendQstPrintRequest (int $ qstId ): array
643+ {
644+ return $ this ->sendGetRequest (self ::QST_PRINT_API . '/ ' . $ qstId );
645+ }
646+
647+ /** @inheritdoc */
648+ public function sendQstListRequest (): array
649+ {
650+ return $ this ->sendGetRequest (self ::QST_LIST_API );
651+ }
652+
653+ /** @inheritdoc */
654+ public function getDebugShowResponseHeaders (): bool
655+ {
656+ return $ this ->debugShowResponseHeaders ;
657+ }
658+
659+ /** @inheritdoc */
660+ public function setDebugShowResponseHeaders (bool $ debugShowResponseHeaders = true ): self
661+ {
662+ $ this ->debugShowResponseHeaders = $ debugShowResponseHeaders ;
663+ return $ this ;
664+ }
665+
666+ /**
667+ * @param array $curlOptArr
668+ * @param array $headers
669+ * @return void
670+ */
671+ private function addCurlOptHeaderFunction (array &$ curlOptArr , array &$ headers ): void
672+ {
673+ $ curlOptArr += [
674+ CURLOPT_HEADERFUNCTION => static function ($ curl , $ header ) use (&$ headers )
675+ {
676+ if (strlen (trim ($ header )) > 0 ) {
677+ $ headers [] = trim ($ header );
678+ }
679+
680+ return strlen ($ header );
681+ }
682+ ];
683+ }
597684}
0 commit comments