diff --git a/src/Config.php b/src/Config.php index 46dfb88..51b0e0e 100644 --- a/src/Config.php +++ b/src/Config.php @@ -18,6 +18,7 @@ public function __construct( public ?string $clientSecret = null, public ?string $goid = null, public ?string $gatewayUrl = null, + public ?string $customUserAgent = null, ) { } diff --git a/src/GoPay.php b/src/GoPay.php index e2ed829..4a7671a 100644 --- a/src/GoPay.php +++ b/src/GoPay.php @@ -14,6 +14,9 @@ class GoPay const LOCALE_CZECH = 'cs-CZ'; const LOCALE_ENGLISH = 'en-US'; + const VERSION = '1.10.1'; + const DEFAULT_USER_AGENT = 'GoPay PHP ' . self::VERSION; + private $config; private $browser; @@ -71,18 +74,21 @@ private function encodeData($contentType, $data) private function buildHeaders($contentType, $authorization) { + $customUserAgent = array_key_exists('customUserAgent', $this->config) ? $this->config['customUserAgent'] : null; if (is_null($contentType)) { return [ 'Accept' => 'application/json', 'Accept-Language' => $this->getAcceptedLanguage(), - 'Authorization' => $authorization + 'Authorization' => $authorization, + 'User-Agent' => is_null($customUserAgent) ? self::DEFAULT_USER_AGENT : $customUserAgent ]; } else { - return [ + return [ 'Accept' => 'application/json', 'Accept-Language' => $this->getAcceptedLanguage(), 'Content-Type' => $contentType, - 'Authorization' => $authorization + 'Authorization' => $authorization, + 'User-Agent' => is_null($customUserAgent) ? self::DEFAULT_USER_AGENT : $customUserAgent ]; } }