linkmobility-php-client/src/Response/Response.php

111 lines
2.4 KiB
PHP
Raw Normal View History

2022-07-13 10:41:23 +02:00
<?php
2022-07-13 10:50:45 +02:00
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link https://www.oxidmodule.com
*/
2022-06-20 14:47:33 +02:00
declare(strict_types=1);
namespace D3\LinkmobilityClient\Response;
abstract class Response implements ResponseInterface
{
2022-07-13 10:41:23 +02:00
public const STATUSCODE = 'statusCode';
public const STATUSMESSAGE = 'statusMessage';
public const CLIENTMESSAGEID = 'clientMessageId';
public const TRANSFERID = 'transferId';
public const SMSCOUNT = 'smsCount';
2022-06-20 14:47:33 +02:00
/**
* @var \Psr\Http\Message\ResponseInterface
2022-06-20 14:47:33 +02:00
*/
protected $rawResponse;
protected $content;
2022-06-20 14:47:33 +02:00
/**
* @var int
*/
protected $status;
public function __construct(\Psr\Http\Message\ResponseInterface $rawResponse)
{
$this->rawResponse = $rawResponse;
$this->rawResponse->getBody()->rewind();
$this->content = json_decode($this->rawResponse->getBody()->getContents(), true);
}
2022-07-13 10:41:23 +02:00
public function getRawResponse(): \Psr\Http\Message\ResponseInterface
{
return $this->rawResponse;
}
public function getContent()
2022-06-20 14:47:33 +02:00
{
return $this->content;
}
2022-06-20 14:47:33 +02:00
/**
* @return int
*/
2022-07-13 10:41:23 +02:00
public function getInternalStatus(): int
{
return $this->getContent()[self::STATUSCODE];
}
2022-06-20 14:47:33 +02:00
/**
* @return string
*/
2022-07-13 10:41:23 +02:00
public function getStatusMessage(): string
{
return $this->getContent()[self::STATUSMESSAGE];
}
/**
* @return string|null
*/
public function getClientMessageId(): ?string
{
return $this->getContent()[self::CLIENTMESSAGEID];
}
/**
* @return string|null
*/
public function getTransferId(): ?string
{
return $this->getContent()[self::TRANSFERID];
}
/**
* @return int
*/
2022-07-13 10:41:23 +02:00
public function getSmsCount(): int
{
return $this->getContent()[self::SMSCOUNT];
2022-06-20 14:47:33 +02:00
}
/**
* @return bool
*/
public function isSuccessful(): bool
{
$status = $this->getInternalStatus();
return $status >= 2000 && $status <= 2999;
2022-06-20 14:47:33 +02:00
}
public function getErrorMessage(): string
2022-06-20 14:47:33 +02:00
{
return $this->isSuccessful() ? '' : $this->getStatusMessage();
2022-06-20 14:47:33 +02:00
}
}