@@ -51,6 +51,11 @@ abstract class AbstractMindboxClient
5151 */
5252 protected $ responseType ;
5353
54+ /**
55+ * @var array $headers Поля хедера для запроса.
56+ */
57+ protected $ headers ;
58+
5459 /**
5560 * Конструктор AbstractMindboxClient.
5661 *
@@ -64,6 +69,7 @@ public function __construct($secretKey, IHttpClient $httpClient, LoggerInterface
6469 $ this ->httpClient = $ httpClient ;
6570 $ this ->logger = $ logger ;
6671 $ this ->responseType = MindboxResponse::class;
72+ $ this ->headers = $ this ->getDefaultHeaders ();
6773 }
6874
6975 /**
@@ -184,17 +190,11 @@ abstract protected function prepareUrl($additionalUrl, array $queryParams, $isSy
184190 /**
185191 * Подготовка массива заголовков запроса.
186192 *
187- * @param bool $addDeviceUUID Флаг: добавлять ли в запрос DeviceUUID.
188- *
189193 * @return array
190194 */
191- protected function prepareHeaders ($ addDeviceUUID = true )
195+ protected function prepareHeaders ()
192196 {
193- return [
194- 'Accept ' => 'application/json ' ,
195- 'Content-Type ' => 'application/json ' ,
196- 'Authorization ' => $ this ->prepareAuthorizationHeader (),
197- ];
197+ return $ this ->headers ;
198198 }
199199
200200 /**
@@ -378,4 +378,37 @@ public function setResponseType($type)
378378 }
379379 $ this ->responseType = $ type ;
380380 }
381+
382+ /**
383+ * Возвращает стандартные заголовки запроса.
384+ *
385+ * @return array
386+ */
387+ protected function getDefaultHeaders ()
388+ {
389+ return [
390+ 'Accept ' => 'application/json ' ,
391+ 'Content-Type ' => 'application/json ' ,
392+ 'Authorization ' => $ this ->prepareAuthorizationHeader (),
393+ 'Mindbox-Integration ' => 'PhpSDK ' ,
394+ 'Mindbox-Integration-Version ' => '1.0 '
395+ ];
396+ }
397+
398+ /**
399+ * Добавляет заголовок запроса.
400+ *
401+ * @param array $headers Заголовок или массив заголовков.
402+ *
403+ * Пример:
404+ *
405+ * ['Mindbox-Integration' => 'PhpSDK']
406+ *
407+ */
408+ public function addHeaders (array $ headers )
409+ {
410+ if (is_array ($ headers )) {
411+ $ this ->headers = array_merge ($ this ->headers , $ headers );
412+ }
413+ }
381414}
0 commit comments