diff --git a/Dockerfile b/Dockerfile index 9a2ecfe..72463e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM php:7.2-cli +FROM php:8.2-cli LABEL maintainer="neto.joaobatista@gmail.com" RUN apt -y update && apt -y install zlib1g-dev zip diff --git a/composer.json b/composer.json index 863cc46..b671b88 100644 --- a/composer.json +++ b/composer.json @@ -6,10 +6,10 @@ "license": "MIT", "type": "library", "require": { - "php": ">=7.2", + "php": ">=8.2", "ext-curl": "*", "ext-json": "*", - "psr/log": "^1.1", + "psr/log": "^1.1 ||^2.0 || ^3.0", "monolog/monolog": "*" }, "require-dev": { diff --git a/src/Rede/Authorization.php b/src/Rede/Authorization.php index b254d9c..389732b 100644 --- a/src/Rede/Authorization.php +++ b/src/Rede/Authorization.php @@ -94,6 +94,11 @@ class Authorization */ private $tid; + /** + * @var object + */ + private $brand; + /** * @return string */ @@ -417,4 +422,20 @@ public function setTid($tid) $this->tid = $tid; return $this; } + + /** + * @return object + */ + public function getBrand() + { + return $this->brand; + } + + /** + * @param object $brand + */ + public function setBrand($brand): void + { + $this->brand = $brand; + } } \ No newline at end of file diff --git a/src/Rede/Brand.php b/src/Rede/Brand.php index 97caeb5..f2cbaf4 100644 --- a/src/Rede/Brand.php +++ b/src/Rede/Brand.php @@ -21,6 +21,11 @@ class Brand */ private $returnMessage; + /** + * @var string + */ + private $authorizationCode; + /** * @return string */ @@ -78,5 +83,23 @@ public function setReturnMessage(string $returnMessage): Brand return $this; } + /** + * @param string $authorizationCode + * + * @return Brand + */ + public function setAuthorizationCode(string $authorizationCode): Brand + { + $this->authorizationCode = $authorizationCode; + return $this; + } + + /** + * @return string + */ + public function getAuthorizationCode(): string + { + return $this->authorizationCode; + } } \ No newline at end of file diff --git a/src/Rede/Environment.php b/src/Rede/Environment.php index 2daf62d..5dfccde 100644 --- a/src/Rede/Environment.php +++ b/src/Rede/Environment.php @@ -104,7 +104,7 @@ public function setSessionId($sessionId) /** * @return array */ - public function jsonSerialize() + public function jsonSerialize(): array { $consumer = new stdClass(); $consumer->ip = $this->ip; diff --git a/src/Rede/Exception/RedeException.php b/src/Rede/Exception/RedeException.php index 41d6f3e..c687b5a 100644 --- a/src/Rede/Exception/RedeException.php +++ b/src/Rede/Exception/RedeException.php @@ -2,8 +2,37 @@ namespace Rede\Exception; +use Rede\Transaction; use RuntimeException; +use Throwable; class RedeException extends RuntimeException { + private ?string $response = null; + + private ?Transaction $transaction = null; + + public function __construct($message = "", $code = 0, ?Throwable $previous = null, ?string $response = null, ?Transaction $transaction = null) + { + parent::__construct($message, $code, $previous); + + $this->response = $response; + $this->transaction = $transaction; + } + + /** + * @return string|null + */ + public function getResponse(): ?string + { + return $this->response; + } + + /** + * @return Transaction|null + */ + public function getTransaction(): ?Transaction + { + return $this->transaction; + } } diff --git a/src/Rede/SerializeTrait.php b/src/Rede/SerializeTrait.php index 6ec13af..b7ffafb 100644 --- a/src/Rede/SerializeTrait.php +++ b/src/Rede/SerializeTrait.php @@ -7,7 +7,7 @@ trait SerializeTrait /** * @return array */ - public function jsonSerialize() + public function jsonSerialize(): array { return array_filter(get_object_vars($this), function ($v) { return $v !== null; diff --git a/src/Rede/Service/AbstractService.php b/src/Rede/Service/AbstractService.php index 1d48e14..5f40c5b 100644 --- a/src/Rede/Service/AbstractService.php +++ b/src/Rede/Service/AbstractService.php @@ -47,7 +47,7 @@ abstract class AbstractService * @param Store $store * @param LoggerInterface|null $logger */ - public function __construct(Store $store, LoggerInterface $logger = null) + public function __construct(Store $store, ?LoggerInterface $logger = null) { $this->store = $store; $this->logger = $logger; @@ -93,10 +93,6 @@ protected function sendRequest($body = '', $method = 'GET') $userAgent .= sprintf(' %s/%s', $this->platform, $this->platformVersion); } - if (is_resource($this->curl)) { - curl_close($this->curl); - } - $curlVersion = curl_version(); if (is_array($curlVersion)) { @@ -194,8 +190,6 @@ protected function sendRequest($body = '', $method = 'GET') throw new RuntimeException(sprintf('Curl error[%s]: %s', curl_errno($this->curl), curl_error($this->curl))); } - curl_close($this->curl); - $this->curl = null; return $this->parseResponse($response, $httpInfo['http_code']); diff --git a/src/Rede/Service/AbstractTransactionsService.php b/src/Rede/Service/AbstractTransactionsService.php index 24297a3..b9f8d20 100644 --- a/src/Rede/Service/AbstractTransactionsService.php +++ b/src/Rede/Service/AbstractTransactionsService.php @@ -29,7 +29,7 @@ abstract class AbstractTransactionsService extends AbstractService * @param Transaction|null $transaction * @param LoggerInterface|null $logger */ - public function __construct(Store $store, Transaction $transaction = null, LoggerInterface $logger = null) + public function __construct(Store $store, ?Transaction $transaction = null, ?LoggerInterface $logger = null) { parent::__construct($store, $logger); @@ -100,7 +100,9 @@ protected function parseResponse($response, $statusCode) throw new RedeException( $this->transaction->getReturnMessage(), $this->transaction->getReturnCode(), - $previous + $previous, + $response, + $this->transaction ); } diff --git a/src/Rede/Store.php b/src/Rede/Store.php index b0bbbaf..9dd9d70 100644 --- a/src/Rede/Store.php +++ b/src/Rede/Store.php @@ -29,7 +29,7 @@ class Store * @param string $token * @param Environment|null $environment if none provided, production will be used. */ - public function __construct($filiation, $token, Environment $environment = null) + public function __construct($filiation, $token, ?Environment $environment = null) { $environment = $environment != null ? $environment : Environment::production(); diff --git a/src/Rede/Transaction.php b/src/Rede/Transaction.php index 55e24e3..f77ae56 100644 --- a/src/Rede/Transaction.php +++ b/src/Rede/Transaction.php @@ -337,7 +337,7 @@ public function capture($capture = true) * @return array * @see \JsonSerializable::jsonSerialize() */ - public function jsonSerialize() + public function jsonSerialize(): array { $capture = null; @@ -446,7 +446,9 @@ public function jsonUnserialize($serialized) continue; } - $this->$property = $value; + if (property_exists($this, $property)) { + $this->$property = $value; + } } return $this; diff --git a/src/Rede/eRede.php b/src/Rede/eRede.php index 7790c11..899fe67 100644 --- a/src/Rede/eRede.php +++ b/src/Rede/eRede.php @@ -39,7 +39,7 @@ class eRede * @param Store $store * @param LoggerInterface|null $logger */ - public function __construct(Store $store, LoggerInterface $logger = null) + public function __construct(Store $store, ?LoggerInterface $logger = null) { $this->store = $store; $this->logger = $logger;