@@ -44,23 +44,31 @@ class RESTcli
4444 */
4545 protected string $ identity ;
4646
47+ /**
48+ * Value for the X-BitPay-Platform-Info header.
49+ * @var string
50+ */
51+ protected string $ platformInfo ;
52+
4753 /**
4854 * @var string
4955 */
5056 protected string $ proxy ;
5157
58+
5259 /**
5360 * RESTcli constructor.
5461 * @param string $environment
5562 * @param PrivateKey $ecKey
5663 * @param string|null $proxy
5764 * @throws BitPayApiException
5865 */
59- public function __construct (string $ environment , PrivateKey $ ecKey , ?string $ proxy = null )
66+ public function __construct (string $ environment , PrivateKey $ ecKey , ?string $ proxy = null , ? string $ platformInfo )
6067 {
6168 $ this ->ecKey = $ ecKey ;
6269 $ this ->baseUrl = $ environment == Env::TEST ? Env::TEST_URL : Env::PROD_URL ;
6370 $ this ->proxy = $ proxy !== null ? trim ($ proxy ) : '' ;
71+ $ this ->platformInfo = $ platformInfo !== null ? trim ($ platformInfo ) : '' ;
6472 $ this ->init ();
6573 }
6674
@@ -89,6 +97,10 @@ public function init(): void
8997 $ config ['proxy ' ] = $ this ->proxy ;
9098 }
9199
100+ if ($ this ->platformInfo !== '' ) {
101+ $ config ['defaults ' ]['headers ' ]['x-bitpay-platform-info ' ] = $ this ->platformInfo ;
102+ }
103+
92104 $ this ->client = new GuzzleHttpClient ($ config );
93105 } catch (Exception $ e ) {
94106 BitPayExceptionProvider::throwApiExceptionWithMessage ($ e ->getMessage ());
@@ -128,6 +140,10 @@ public function post($uri, array $formData = [], bool $signatureRequired = true)
128140 $ headers ['x-identity ' ] = $ this ->identity ;
129141 }
130142
143+ if ($ this ->platformInfo !== '' ) {
144+ $ headers ['x-bitpay-platform-info ' ] = $ this ->platformInfo ;
145+ }
146+
131147 $ method = "POST " ;
132148
133149 LoggerProvider::getLogger ()->logRequest ($ method , $ fullURL , $ jsonRequestData );
@@ -190,6 +206,10 @@ public function get($uri, array $parameters = null, bool $signatureRequired = tr
190206 $ headers ['x-identity ' ] = $ this ->identity ;
191207 }
192208
209+ if ($ this ->platformInfo !== '' ) {
210+ $ headers ['x-bitpay-platform-info ' ] = $ this ->platformInfo ;
211+ }
212+
193213 $ method = 'GET ' ;
194214
195215 LoggerProvider::getLogger ()->logRequest ($ method , $ fullURL , null );
@@ -247,6 +267,10 @@ public function delete($uri, array $parameters = null): string
247267 BitPayExceptionProvider::throwGenericExceptionWithMessage ('Wrong ecKey. ' . $ e ->getMessage ());
248268 }
249269
270+ if ($ this ->platformInfo !== '' ) {
271+ $ headers ['x-bitpay-platform-info ' ] = $ this ->platformInfo ;
272+ }
273+
250274 $ method = 'DELETE ' ;
251275
252276 $ jsonRequestData = json_encode ($ parameters , JSON_THROW_ON_ERROR );
@@ -305,6 +329,10 @@ public function update($uri, array $formData = []): string
305329 BitPayExceptionProvider::throwGenericExceptionWithMessage ('Wrong ecKey. ' . $ e ->getMessage ());
306330 }
307331
332+ if ($ this ->platformInfo !== '' ) {
333+ $ headers ['x-bitpay-platform-info ' ] = $ this ->platformInfo ;
334+ }
335+
308336 $ method = 'PUT ' ;
309337
310338 LoggerProvider::getLogger ()->logRequest ($ method , $ fullURL , $ jsonRequestData );
0 commit comments