From 3990276041e1d369e1622be78b5831ae4587beb5 Mon Sep 17 00:00:00 2001 From: Saulius Usonis Date: Tue, 23 Aug 2022 14:16:05 +0300 Subject: [PATCH] Release 3.1.2 --- composer.json | 2 +- lib/ApiClient.php | 22 +++++++++++++++++++--- lib/Configuration.php | 6 +++--- test/ApiClientTest.php | 18 ++++++++++++++++++ 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index aec3f8b..067d171 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "postfinancecheckout/sdk", - "version": "3.1.1", + "version": "3.1.2", "description": "PostFinance Checkout SDK for PHP", "keywords": [ "postfinancecheckout", diff --git a/lib/ApiClient.php b/lib/ApiClient.php index 792bd4d..1e5b926 100644 --- a/lib/ApiClient.php +++ b/lib/ApiClient.php @@ -47,14 +47,18 @@ final class ApiClient { * * @var array */ - private $defaultHeaders = []; + private $defaultHeaders = [ + 'x-meta-sdk-version' => "3.1.2", + 'x-meta-sdk-language' => 'php', + 'x-meta-sdk-provider' => "PostFinance Checkout", + ]; /** * The user agent that is sent with any request. * * @var string */ - private $userAgent = 'PHP-Client/3.1.1/php'; + private $userAgent = 'PHP-Client/3.1.2/php'; /** * The path to the certificate authority file. @@ -138,6 +142,8 @@ public function __construct($userId, $applicationKey) { $this->serializer = new ObjectSerializer(); $this->isDebuggingEnabled() ? $this->serializer->enableDebugging() : $this->serializer->disableDebugging(); $this->serializer->setDebugFile($this->getDebugFile()); + $this->addDefaultHeader('x-meta-sdk-language-version', phpversion()); + } /** @@ -311,10 +317,20 @@ public function addDefaultHeader($key, $value) { throw new \InvalidArgumentException('The header key must be a string.'); } - $defaultHeaders[$key] = $value; + $this->defaultHeaders[$key] = $value; return $this; } + /** + * Gets the default headers that will be sent in the request. + * + * @since 3.1.2 + * @return string[] + */ + function getDefaultHeaders() { + return $this->defaultHeaders; + } + /** * Returns true, when debugging is enabled. * diff --git a/lib/Configuration.php b/lib/Configuration.php index 20e2bd6..7f34196 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -80,7 +80,7 @@ class Configuration * * @var string */ - protected $userAgent = 'PostFinanceCheckout\Sdk/3.1.1/php'; + protected $userAgent = 'PostFinanceCheckout\Sdk/3.1.2/php'; /** * Debug switch (default set to false) @@ -388,8 +388,8 @@ public static function toDebugReport() $report = 'PHP SDK (PostFinanceCheckout\Sdk) Debug Report:' . PHP_EOL; $report .= ' OS: ' . php_uname() . PHP_EOL; $report .= ' PHP Version: ' . PHP_VERSION . PHP_EOL; - $report .= ' OpenAPI Spec Version: 3.1.1' . PHP_EOL; - $report .= ' SDK Package Version: 3.1.1' . PHP_EOL; + $report .= ' OpenAPI Spec Version: 3.1.2' . PHP_EOL; + $report .= ' SDK Package Version: 3.1.2' . PHP_EOL; $report .= ' Temp Folder Path: ' . self::getDefaultConfiguration()->getTempFolderPath() . PHP_EOL; return $report; diff --git a/test/ApiClientTest.php b/test/ApiClientTest.php index 39fa69c..cba61cf 100644 --- a/test/ApiClientTest.php +++ b/test/ApiClientTest.php @@ -132,5 +132,23 @@ public function testEmptyResponseWithCurlClient() $this->apiClient->getTransactionService()->read($this->spaceId, 1); } + /** + * Tests that the headers in the response contain headers with SDK information by default. + * + * @since 3.1.2 + * @return void + */ + public function testSdkHeaders() + { + $headers = $this->apiClient->getDefaultHeaders(); + $this->assertGreaterThanOrEqual(4, count($headers)); + + // Check SDK default header values. + $this->assertEquals($headers['x-meta-sdk-version'], "3.1.2"); + $this->assertEquals($headers['x-meta-sdk-language'], 'php'); + $this->assertEquals($headers['x-meta-sdk-provider'], "PostFinance Checkout"); + $this->assertEquals($headers['x-meta-sdk-language-version'], phpversion()); + } + }