Skip to content

Commit

Permalink
Merge pull request #67 from gopaycommunity/feature/user-agent-with-sd…
Browse files Browse the repository at this point in the history
…k-version

Added User-agent with version
  • Loading branch information
pmaryska authored Sep 24, 2024
2 parents 51b882f + 8b15789 commit c9382b0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function __construct(
public ?string $clientSecret = null,
public ?string $goid = null,
public ?string $gatewayUrl = null,
public ?string $customUserAgent = null,
) {
}

Expand Down
12 changes: 9 additions & 3 deletions src/GoPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
];
}
}
Expand Down

0 comments on commit c9382b0

Please sign in to comment.