Update guzzle
This commit is contained in:
parent
fcb9c7a317
commit
be4226250c
4 changed files with 144 additions and 5 deletions
|
@ -51,7 +51,7 @@ class AtolOnline
|
|||
DeserializationContext::create()->setGroups(['post'])
|
||||
);
|
||||
} catch (RuntimeException $exception) {
|
||||
throw new InvalidResponseException($exception->getMessage());
|
||||
throw $this->createInvalidResponseException($response, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ class AtolOnline
|
|||
DeserializationContext::create()->setGroups(['get'])
|
||||
);
|
||||
} catch (RuntimeException $exception) {
|
||||
throw new InvalidResponseException($exception->getMessage());
|
||||
throw $this->createInvalidResponseException($response, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,4 +107,26 @@ class AtolOnline
|
|||
{
|
||||
return $this->api;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $response
|
||||
* @param RuntimeException $previous
|
||||
* @return InvalidResponseException
|
||||
*/
|
||||
private function createInvalidResponseException(string $response, RuntimeException $previous): InvalidResponseException
|
||||
{
|
||||
$exception = new InvalidResponseException($previous->getMessage());
|
||||
|
||||
preg_match('/<head><title>(\d+) ([\w ]+)<\/title><\/head>/m', $response, $matches);
|
||||
|
||||
if (count($matches) === 3) {
|
||||
[, $code, $message] = $matches;
|
||||
|
||||
$exception
|
||||
->setCodeError($code)
|
||||
->setMessageError($message);
|
||||
}
|
||||
|
||||
return $exception;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ class AtolOnlineApi
|
|||
*/
|
||||
public function getVersion(): string
|
||||
{
|
||||
return $this->connection->version;
|
||||
return $this->connection->version ?: self::API_VERSION_V3;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,7 +103,7 @@ class AtolOnlineApi
|
|||
* @param $paymentReceiptRequest
|
||||
* @return string
|
||||
*/
|
||||
public function sell($paymentReceiptRequest): ?string
|
||||
public function sell($paymentReceiptRequest)
|
||||
{
|
||||
return $this->sendOperationRequest('sell', $paymentReceiptRequest);
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ class AtolOnlineApi
|
|||
* @param $paymentReceiptRequest
|
||||
* @return string
|
||||
*/
|
||||
public function sellRefund($paymentReceiptRequest): ?string
|
||||
public function sellRefund($paymentReceiptRequest)
|
||||
{
|
||||
return $this->sendOperationRequest('sell_refund', $paymentReceiptRequest);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,58 @@
|
|||
|
||||
namespace AtolOnlineClient\Exception;
|
||||
|
||||
/**
|
||||
* Class InvalidResponseException
|
||||
*
|
||||
* @package AtolOnlineClient\Exception
|
||||
*/
|
||||
class InvalidResponseException extends AtolException
|
||||
{
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
protected $codeError;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $messageError;
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getCodeError(): ?int
|
||||
{
|
||||
return $this->codeError;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $codeError
|
||||
* @return InvalidResponseException
|
||||
*/
|
||||
public function setCodeError(?int $codeError): InvalidResponseException
|
||||
{
|
||||
$this->codeError = $codeError;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getMessageError(): ?string
|
||||
{
|
||||
return $this->messageError;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $messageError
|
||||
* @return InvalidResponseException
|
||||
*/
|
||||
public function setMessageError(?string $messageError): InvalidResponseException
|
||||
{
|
||||
$this->messageError = $messageError;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ use AtolOnlineClient\Request\V4\PaymentReceiptRequest;
|
|||
use AtolOnlineClient\Request\V4\ReceiptRequest;
|
||||
use AtolOnlineClient\Request\V4\ServiceRequest;
|
||||
use GuzzleHttp\Client;
|
||||
use JMS\Serializer\Exception\RuntimeException;
|
||||
use JMS\Serializer\SerializerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
|
@ -121,6 +122,26 @@ class AtolOnlineTest extends TestCase
|
|||
$this->atol->deserializeCheckStatusResponse('<html></html>');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $code
|
||||
* @param string|null $message
|
||||
* @param string $html
|
||||
* @covers \AtolOnlineClient\AtolOnline::createInvalidResponseException
|
||||
* @dataProvider dataInvalidResponse
|
||||
*/
|
||||
public function testCreateInvalidResponseException(?int $code, ?string $message, string $html): void
|
||||
{
|
||||
/** @var InvalidResponseException $exception */
|
||||
$exception = $this->callMethod($this->atol, 'createInvalidResponseException', [
|
||||
'response' => $html,
|
||||
'previous' => new RuntimeException()
|
||||
]);
|
||||
|
||||
$this->assertInstanceOf(InvalidResponseException::class, $exception);
|
||||
$this->assertEquals($code, $exception->getCodeError());
|
||||
$this->assertEquals($message, $exception->getMessageError());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \AtolOnlineClient\AtolOnline::serializeOperationRequest
|
||||
*/
|
||||
|
@ -197,4 +218,48 @@ class AtolOnlineTest extends TestCase
|
|||
['error_response_v4.json']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function dataInvalidResponse(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'code' => 404,
|
||||
'message' => 'Not Found',
|
||||
'html' => '<html><head><title>404 Not Found</title></head><body><center><h1>404 Not Found</h1></center><hr><center>openresty/1.15.8.1rc1</center></body></html>',
|
||||
],
|
||||
[
|
||||
'code' => 502,
|
||||
'message' => 'Bad Gateway',
|
||||
'html' => '<html><head><title>502 Bad Gateway</title></head><body><center><h1>502 Bad Gateway</h1></center><hr><center>nginx/1.15.8</center></body></html>',
|
||||
],
|
||||
[
|
||||
'code' => null,
|
||||
'message' => null,
|
||||
'html' => '<html></html>',
|
||||
],
|
||||
[
|
||||
'code' => null,
|
||||
'message' => null,
|
||||
'html' => '',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $object
|
||||
* @param string $name
|
||||
* @param array $args
|
||||
* @return mixed
|
||||
*/
|
||||
private function callMethod($object, string $name, array $args = [])
|
||||
{
|
||||
$reflection = new \ReflectionClass($object);
|
||||
$method = $reflection->getMethod($name);
|
||||
$method->setAccessible(true);
|
||||
|
||||
return $method->invokeArgs($object, $args);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue