Initial Commit
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2020 "YooMoney", NBСO LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace YooKassa\Common\Exceptions;
|
||||
|
||||
class ApiConnectionException extends ApiException
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2020 "YooMoney", NBСO LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace YooKassa\Common\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class ApiException extends Exception
|
||||
{
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $responseBody;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $responseHeaders;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $message Error message
|
||||
* @param int $code HTTP status code
|
||||
* @param string[] $responseHeaders HTTP header
|
||||
* @param mixed $responseBody HTTP body
|
||||
*/
|
||||
public function __construct($message = "", $code = 0, $responseHeaders = array(), $responseBody = null)
|
||||
{
|
||||
parent::__construct($message, $code);
|
||||
$this->responseHeaders = $responseHeaders;
|
||||
$this->responseBody = $responseBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getResponseHeaders()
|
||||
{
|
||||
return $this->responseHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getResponseBody()
|
||||
{
|
||||
return $this->responseBody;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2020 "YooMoney", NBСO LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace YooKassa\Common\Exceptions;
|
||||
|
||||
class AuthorizeException extends ApiException
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2020 "YooMoney", NBСO LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace YooKassa\Common\Exceptions;
|
||||
|
||||
class BadApiRequestException extends ApiException
|
||||
{
|
||||
const HTTP_CODE = 400;
|
||||
|
||||
public $type;
|
||||
|
||||
public $retryAfter;
|
||||
|
||||
public function __construct($responseHeaders = array(), $responseBody = null)
|
||||
{
|
||||
$errorData = json_decode($responseBody, true);
|
||||
$message = '';
|
||||
|
||||
if (isset($errorData['description'])) {
|
||||
$message .= $errorData['description'] . '. ';
|
||||
}
|
||||
|
||||
if (isset($errorData['code'])) {
|
||||
$message .= sprintf('Error code: %s. ', $errorData['code']);
|
||||
}
|
||||
|
||||
if (isset($errorData['parameter'])) {
|
||||
$message .= sprintf('Parameter name: %s. ', $errorData['parameter']);
|
||||
}
|
||||
|
||||
if (isset($errorData['retry_after'])) {
|
||||
$this->retryAfter = $errorData['retry_after'];
|
||||
}
|
||||
|
||||
if (isset($errorData['type'])) {
|
||||
$this->type = $errorData['type'];
|
||||
}
|
||||
|
||||
parent::__construct(trim($message), self::HTTP_CODE, $responseHeaders, $responseBody);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2020 "YooMoney", NBСO LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace YooKassa\Common\Exceptions;
|
||||
|
||||
class EmptyPropertyValueException extends InvalidPropertyException
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2020 "YooMoney", NBСO LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace YooKassa\Common\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class ExtensionNotFoundException extends Exception
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $name extension name
|
||||
* @param int $code error code
|
||||
*/
|
||||
|
||||
public function __construct($name, $code = 0)
|
||||
{
|
||||
$message = sprintf('%s extension is not loaded!', $name);
|
||||
|
||||
parent::__construct($message, $code);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2020 "YooMoney", NBСO LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace YooKassa\Common\Exceptions;
|
||||
|
||||
class ForbiddenException extends ApiException
|
||||
{
|
||||
const HTTP_CODE = 403;
|
||||
|
||||
public $type;
|
||||
|
||||
public $retryAfter;
|
||||
|
||||
public function __construct($responseHeaders = array(), $responseBody = null)
|
||||
{
|
||||
$errorData = json_decode($responseBody, true);
|
||||
$message = '';
|
||||
|
||||
if (isset($errorData['description'])) {
|
||||
$message .= $errorData['description'] . '. ';
|
||||
}
|
||||
|
||||
if (isset($errorData['code'])) {
|
||||
$message .= sprintf('Error code: %s. ', $errorData['code']);
|
||||
}
|
||||
|
||||
if (isset($errorData['parameter'])) {
|
||||
$message .= sprintf('Parameter name: %s. ', $errorData['parameter']);
|
||||
}
|
||||
|
||||
if (isset($errorData['retry_after'])) {
|
||||
$this->retryAfter = $errorData['retry_after'];
|
||||
}
|
||||
|
||||
if (isset($errorData['type'])) {
|
||||
$this->type = $errorData['type'];
|
||||
}
|
||||
|
||||
parent::__construct(trim($message), self::HTTP_CODE, $responseHeaders, $responseBody);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2020 "YooMoney", NBСO LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace YooKassa\Common\Exceptions;
|
||||
|
||||
class InternalServerError extends ApiException
|
||||
{
|
||||
const HTTP_CODE = 500;
|
||||
|
||||
public $retryAfter;
|
||||
|
||||
public $type;
|
||||
|
||||
public function __construct($responseHeaders = array(), $responseBody = null)
|
||||
{
|
||||
$errorData = json_decode($responseBody, true);
|
||||
$message = '';
|
||||
|
||||
if (isset($errorData['description'])) {
|
||||
$message .= $errorData['description'] . '. ';
|
||||
}
|
||||
|
||||
if (isset($errorData['code'])) {
|
||||
$message .= sprintf('Error code: %s. ', $errorData['code']);
|
||||
}
|
||||
|
||||
if (isset($errorData['parameter'])) {
|
||||
$message .= sprintf('Parameter name: %s. ', $errorData['parameter']);
|
||||
}
|
||||
|
||||
if (isset($errorData['retry_after'])) {
|
||||
$this->retryAfter = $errorData['retry_after'];
|
||||
}
|
||||
|
||||
if (isset($errorData['type'])) {
|
||||
$this->type = $errorData['type'];
|
||||
}
|
||||
|
||||
parent::__construct(trim($message), self::HTTP_CODE, $responseHeaders, $responseBody);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2020 "YooMoney", NBСO LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace YooKassa\Common\Exceptions;
|
||||
|
||||
class InvalidPropertyException extends \InvalidArgumentException
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $propertyName;
|
||||
|
||||
/**
|
||||
* InvalidValueException constructor.
|
||||
* @param string $message
|
||||
* @param int $code
|
||||
* @param string $property
|
||||
*/
|
||||
public function __construct($message = "", $code = 0, $property = "")
|
||||
{
|
||||
parent::__construct($message, $code);
|
||||
$this->propertyName = (string)$property;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getProperty()
|
||||
{
|
||||
return $this->propertyName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2020 "YooMoney", NBСO LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace YooKassa\Common\Exceptions;
|
||||
|
||||
class InvalidPropertyValueException extends InvalidPropertyException
|
||||
{
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
private $invalidValue;
|
||||
|
||||
/**
|
||||
* InvalidPropertyValueTypeException constructor.
|
||||
* @param string $message
|
||||
* @param int $code
|
||||
* @param string $property
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function __construct($message = '', $code = 0, $property = '', $value = null)
|
||||
{
|
||||
parent::__construct($message, $code, $property);
|
||||
if ($value !== null) {
|
||||
$this->invalidValue = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->invalidValue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2020 "YooMoney", NBСO LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace YooKassa\Common\Exceptions;
|
||||
|
||||
class InvalidPropertyValueTypeException extends InvalidPropertyException
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $type;
|
||||
|
||||
/**
|
||||
* InvalidPropertyValueTypeException constructor.
|
||||
* @param string $message
|
||||
* @param int $code
|
||||
* @param string $property
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function __construct($message = "", $code = 0, $property = "", $value = null)
|
||||
{
|
||||
parent::__construct($message, $code, $property);
|
||||
if ($value === null) {
|
||||
$this->type = 'null';
|
||||
} elseif (is_object($value)) {
|
||||
$this->type = get_class($value);
|
||||
} else {
|
||||
$this->type = gettype($value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2020 "YooMoney", NBСO LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace YooKassa\Common\Exceptions;
|
||||
|
||||
use YooKassa\Common\AbstractRequest;
|
||||
|
||||
class InvalidRequestException extends \RuntimeException
|
||||
{
|
||||
/**
|
||||
* @var AbstractRequest|null
|
||||
*/
|
||||
private $errorRequest;
|
||||
|
||||
/**
|
||||
* InvalidRequestException constructor.
|
||||
* @param AbstractRequest|string $error
|
||||
* @param int $code
|
||||
* @param null $previous
|
||||
*/
|
||||
public function __construct($error, $code = 0, $previous = null)
|
||||
{
|
||||
if ($error instanceof AbstractRequest) {
|
||||
$message = 'Failed to build request "'.get_class($error).'": "'.$error->getLastValidationError().'"';
|
||||
$this->errorRequest = $error;
|
||||
} else {
|
||||
$message = $error;
|
||||
}
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AbstractRequest|null
|
||||
*/
|
||||
public function getRequestObject()
|
||||
{
|
||||
return $this->errorRequest;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2020 "YooMoney", NBСO LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace YooKassa\Common\Exceptions;
|
||||
|
||||
class JsonException extends \UnexpectedValueException
|
||||
{
|
||||
public static $errorLabels = array(
|
||||
JSON_ERROR_NONE => 'No error',
|
||||
JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
|
||||
JSON_ERROR_STATE_MISMATCH => 'State mismatch (invalid or malformed JSON)',
|
||||
JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded',
|
||||
JSON_ERROR_SYNTAX => 'Syntax error',
|
||||
JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded'
|
||||
);
|
||||
|
||||
public function __construct($message = "", $code = 0, $previous = null)
|
||||
{
|
||||
$errorMsg = isset(self::$errorLabels[$code]) ? self::$errorLabels[$code] : 'Unknown error';
|
||||
$message = sprintf('%s %s', $message, $errorMsg);
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2020 "YooMoney", NBСO LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace YooKassa\Common\Exceptions;
|
||||
|
||||
class NotFoundException extends ApiException
|
||||
{
|
||||
const HTTP_CODE = 404;
|
||||
|
||||
public $type;
|
||||
|
||||
public $retryAfter;
|
||||
|
||||
public function __construct($responseHeaders = array(), $responseBody = null)
|
||||
{
|
||||
$errorData = json_decode($responseBody, true);
|
||||
$message = '';
|
||||
|
||||
if (isset($errorData['description'])) {
|
||||
$message .= $errorData['description'].'. ';
|
||||
}
|
||||
|
||||
if (isset($errorData['code'])) {
|
||||
$message .= sprintf('Error code: %s. ', $errorData['code']);
|
||||
}
|
||||
|
||||
if (isset($errorData['parameter'])) {
|
||||
$message .= sprintf('Parameter name: %s. ', $errorData['parameter']);
|
||||
}
|
||||
|
||||
if (isset($errorData['retry_after'])) {
|
||||
$this->retryAfter = $errorData['retry_after'];
|
||||
}
|
||||
|
||||
if (isset($errorData['type'])) {
|
||||
$this->type = $errorData['type'];
|
||||
}
|
||||
|
||||
parent::__construct(trim($message), self::HTTP_CODE, $responseHeaders, $responseBody);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2020 "YooMoney", NBСO LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace YooKassa\Common\Exceptions;
|
||||
|
||||
class ResponseProcessingException extends ApiException
|
||||
{
|
||||
const HTTP_CODE = 202;
|
||||
|
||||
public $type;
|
||||
|
||||
public $retryAfter;
|
||||
|
||||
public function __construct($responseHeaders = array(), $responseBody = null)
|
||||
{
|
||||
$errorData = json_decode($responseBody, true);
|
||||
$message = '';
|
||||
|
||||
if (isset($errorData['description'])) {
|
||||
$message .= $errorData['description'] . '. ';
|
||||
}
|
||||
|
||||
if (isset($errorData['retry_after'])) {
|
||||
$this->retryAfter = $errorData['retry_after'];
|
||||
}
|
||||
|
||||
if (isset($errorData['type'])) {
|
||||
$this->type = $errorData['type'];
|
||||
}
|
||||
|
||||
parent::__construct(trim($message), self::HTTP_CODE, $responseHeaders, $responseBody);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2020 "YooMoney", NBСO LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace YooKassa\Common\Exceptions;
|
||||
|
||||
class TooManyRequestsException extends ApiException
|
||||
{
|
||||
const HTTP_CODE = 429;
|
||||
|
||||
public $type;
|
||||
|
||||
public $retryAfter;
|
||||
|
||||
public function __construct($responseHeaders = array(), $responseBody = null)
|
||||
{
|
||||
$errorData = json_decode($responseBody, true);
|
||||
$message = '';
|
||||
|
||||
if (isset($errorData['description'])) {
|
||||
$message .= $errorData['description'] . '. ';
|
||||
}
|
||||
|
||||
if (isset($errorData['code'])) {
|
||||
$message .= sprintf('Error code: %s. ', $errorData['code']);
|
||||
}
|
||||
|
||||
if (isset($errorData['parameter'])) {
|
||||
$message .= sprintf('Parameter name: %s. ', $errorData['parameter']);
|
||||
}
|
||||
|
||||
if (isset($errorData['retry_after'])) {
|
||||
$this->retryAfter = $errorData['retry_after'];
|
||||
}
|
||||
|
||||
if (isset($errorData['type'])) {
|
||||
$this->type = $errorData['type'];
|
||||
}
|
||||
|
||||
parent::__construct(trim($message), self::HTTP_CODE, $responseHeaders, $responseBody);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2020 "YooMoney", NBСO LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace YooKassa\Common\Exceptions;
|
||||
|
||||
class UnauthorizedException extends ApiException
|
||||
{
|
||||
const HTTP_CODE = 401;
|
||||
|
||||
public $type;
|
||||
|
||||
public $retryAfter;
|
||||
|
||||
public function __construct($responseHeaders = array(), $responseBody = null)
|
||||
{
|
||||
$errorData = json_decode($responseBody, true);
|
||||
$message = '';
|
||||
|
||||
if (isset($errorData['description'])) {
|
||||
$message .= $errorData['description'] . '. ';
|
||||
}
|
||||
|
||||
if (isset($errorData['code'])) {
|
||||
$message .= sprintf('Error code: %s. ', $errorData['code']);
|
||||
}
|
||||
|
||||
if (isset($errorData['parameter'])) {
|
||||
$message .= sprintf('Parameter name: %s. ', $errorData['parameter']);
|
||||
}
|
||||
|
||||
if (isset($errorData['retry_after'])) {
|
||||
$this->retryAfter = $errorData['retry_after'];
|
||||
}
|
||||
|
||||
if (isset($errorData['type'])) {
|
||||
$this->type = $errorData['type'];
|
||||
}
|
||||
|
||||
parent::__construct(trim($message), self::HTTP_CODE, $responseHeaders, $responseBody);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user