From 6a93fcc76ca8413cc64c44f52781aafa0af2ddb8 Mon Sep 17 00:00:00 2001 From: Andrey Klimenko Date: Mon, 22 Jan 2024 21:56:34 +0500 Subject: [PATCH] PAYMENTS-17730 update SDK backward compability and check composer ver --- CHANGELOG.md | 14 ++++++++++++ composer.json | 5 ++-- src/Exception/API/XsollaAPIException.php | 29 +++++++++++++++++++++--- src/Version.php | 2 +- 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc16b89..0dbc78a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,20 @@ All notable changes to this project will be documented in this file. ## [Unreleased](https://github.com/xsolla/xsolla-sdk-php/compare/v4.2.0...master) +## [v4.3.1](https://github.com/xsolla/xsolla-sdk-php/compare/v4.3.0...v4.3.1) - 2024-30-01 +### Fixed +* Add support version of PHP to ~8.0 (8.0 and higher) +* Add support for http-foundation ~6.0.0 (6.0 to 6.1) + +## [v4.3.0](https://github.com/xsolla/xsolla-sdk-php/compare/v4.2.0...v4.3.0) - 2023-18-09 +### Added +* New webhooks to handle by web-server + +### Fixed +* Tests refactoring +* Move all webhooks types into new class NotificationTypeDictionary +* Remove "abandoned" status + ## [v4.2.0](https://github.com/xsolla/xsolla-sdk-php/compare/v4.1.2...v4.2.0) - 2021-05-12 ### Added * Changed support version of PHP to ^7.3|^8.0 diff --git a/composer.json b/composer.json index 792c7bc..0baff9f 100644 --- a/composer.json +++ b/composer.json @@ -12,13 +12,14 @@ "source": "https://github.com/xsolla/xsolla-sdk-php/releases" }, "require": { - "php": "^7.3|~8.0.0", + "php": "^7.3|~8.0", "ext-curl": "*", "ext-json": "*", "guzzlehttp/guzzle": "~6.0", - "symfony/http-foundation": "~2.3 || ~3.0 || ~4.0 || ~5.0" + "symfony/http-foundation": "~2.3 || ~3.0 || ~4.0 || ~5.0 || ~6.0.0" }, "require-dev": { + "php": "^7.3|~8.0", "phpunit/phpunit": "^9.0", "symfony/process": "~4.1", "friendsofphp/php-cs-fixer": "~2.13", diff --git a/src/Exception/API/XsollaAPIException.php b/src/Exception/API/XsollaAPIException.php index 8d41c82..6b3674d 100644 --- a/src/Exception/API/XsollaAPIException.php +++ b/src/Exception/API/XsollaAPIException.php @@ -3,6 +3,8 @@ namespace Xsolla\SDK\Exception\API; use GuzzleHttp\Exception\BadResponseException; +use GuzzleHttp\Psr7\Message; +use Psr\Http\Message\MessageInterface; use Xsolla\SDK\Exception\XsollaException; use function GuzzleHttp\Psr7\str; @@ -35,12 +37,19 @@ class XsollaAPIException extends XsollaException */ public static function fromBadResponse(BadResponseException $previous) { - $statusCode = $previous->getResponse()->getStatusCode(); + $message = '$previous getResponse() return null'; + + $response = $previous->getResponse(); + if ($response === null) { + return new self ($message, 0, $previous); + } + + $statusCode = $response->getStatusCode(); $message = sprintf( static::$messageTemplate, $previous->getMessage(), - str($previous->getRequest()), - str($previous->getResponse()) + self::str($previous->getRequest()), + self::str($previous->getResponse()) ); if (array_key_exists($statusCode, static::$exceptions)) { return new static::$exceptions[$statusCode]($message, 0, $previous); @@ -48,4 +57,18 @@ public static function fromBadResponse(BadResponseException $previous) return new self($message, 0, $previous); } + + /** + * Alternative function for str() cuz it's deleted in guzzlehttp/psr7:2.0. Now Message::toString() instead of it. + * + * @return string + */ + protected static function str(MessageInterface $message) + { + if (method_exists(Message::class, 'toString')) { + return Message::toString($message); + } + + return str($message); + } } diff --git a/src/Version.php b/src/Version.php index 758e910..2ff4030 100644 --- a/src/Version.php +++ b/src/Version.php @@ -6,7 +6,7 @@ class Version { - const VERSION = 'v4.2.1'; + const VERSION = 'v4.3.1'; /** * @throws XsollaException