Skip to content

Commit

Permalink
Merge pull request #103 from xsolla/PAYMENTS-17730_fix_bugs_sdk
Browse files Browse the repository at this point in the history
PAYMENTS-17730 update SDK backward compability
  • Loading branch information
AKlimenkoXsolla authored Jan 30, 2024
2 parents 33db9a2 + 6a93fcc commit e68a83e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
29 changes: 26 additions & 3 deletions src/Exception/API/XsollaAPIException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -35,17 +37,38 @@ 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);
}

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);
}
}
2 changes: 1 addition & 1 deletion src/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Version
{
const VERSION = 'v4.2.1';
const VERSION = 'v4.3.1';

/**
* @throws XsollaException
Expand Down

0 comments on commit e68a83e

Please sign in to comment.