From cf443a08508f7b52fd1ddf20106336fa0f37848b Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 19 Jun 2024 10:49:47 -0400 Subject: [PATCH 01/51] chore: drop support for php under 8.2 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bf4ebcdd..4868bdea 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Transbank SDK", "keywords": ["payments", "transbank", "api", "sdk"], "require": { - "php": ">=7.0", + "php": ">=8.2", "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", From e691190657fda6a749b1441d55a6cd9105cb47bc Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 19 Jun 2024 10:50:03 -0400 Subject: [PATCH 02/51] docs: update readme with new version of php --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e7772cda..ffe5e286 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ ## Requisitos: -- PHP 7.0+ +- PHP 8.2+ ## Dependencias Para utilizar este SDK, debes tener las siguientes extensiones de PHP instaladas: From 8e922bd96763aa08e1e830735182a467a68dad29 Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 19 Jun 2024 11:32:23 -0400 Subject: [PATCH 03/51] feat: variables are typed --- .../Exceptions/WebpayRequestException.php | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/Webpay/Exceptions/WebpayRequestException.php b/src/Webpay/Exceptions/WebpayRequestException.php index 71bfe2d2..7f09fcdf 100644 --- a/src/Webpay/Exceptions/WebpayRequestException.php +++ b/src/Webpay/Exceptions/WebpayRequestException.php @@ -10,7 +10,7 @@ class WebpayRequestException extends WebpayException /** * @var string */ - protected static $defaultMessage = 'An error has happened on the request'; + protected static string $defaultMessage = 'An error has happened on the request'; /** * @var mixed @@ -35,16 +35,17 @@ class WebpayRequestException extends WebpayException * WebpayRequestException constructor. * * @param string $message - * @param mixed|string $tbkErrorMessage - * @param int $httpCode + * @param string|null $tbkErrorMessage + * @param int|null $httpCode * @param TransbankApiRequest|null $failedRequest + * @param \Exception|null $previous */ public function __construct( - $message, - $tbkErrorMessage = null, - $httpCode = null, - TransbankApiRequest $failedRequest = null, - \Exception $previous = null + string $message, + ?string $tbkErrorMessage = null, + ?int $httpCode = null, + ?TransbankApiRequest $failedRequest = null, + ?\Exception $previous = null ) { $theMessage = isset($tbkErrorMessage) ? $tbkErrorMessage : $message; if ($failedRequest !== null) { @@ -56,13 +57,13 @@ public function __construct( $this->httpCode = $httpCode; $this->failedRequest = $failedRequest; - parent::__construct($theMessage, $httpCode, $previous); + parent::__construct($theMessage, $httpCode ?? 0, $previous); } /** - * @return mixed + * @return string|null */ - public function getTransbankErrorMessage() + public function getTransbankErrorMessage(): ?string { return $this->transbankErrorMessage; } @@ -72,7 +73,7 @@ public function getTransbankErrorMessage() * * @return static */ - public static function raise(WebpayRequestException $exception) + public static function raise(WebpayRequestException $exception): self { return new static($exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), $exception); @@ -81,31 +82,32 @@ public static function raise(WebpayRequestException $exception) /** * @return int */ - public function getHttpCode() + public function getHttpCode(): int { - return $this->httpCode; + return $this->httpCode ?? 0; } /** * @return TransbankApiRequest|null */ - public function getFailedRequest() + public function getFailedRequest(): ?TransbankApiRequest { return $this->failedRequest; } /** - * @param $message - * @param $tbkErrorMessage - * @param $httpCode + * @param string $message + * @param string|null $tbkErrorMessage + * @param int|null $httpCode * * @return string */ protected function getExceptionMessage( - $message, - $tbkErrorMessage, - $httpCode - ) { + string $message, + ?string $tbkErrorMessage, + ?int $httpCode + ): string { + if (!$tbkErrorMessage) { $theMessage = $message; } else { From 072260b4b952dafb7a29596cccff6b1ded92bcd2 Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 19 Jun 2024 11:41:15 -0400 Subject: [PATCH 04/51] refactor: functions are improved to make it more readable --- .../Exceptions/WebpayRequestException.php | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Webpay/Exceptions/WebpayRequestException.php b/src/Webpay/Exceptions/WebpayRequestException.php index 7f09fcdf..c8488c4a 100644 --- a/src/Webpay/Exceptions/WebpayRequestException.php +++ b/src/Webpay/Exceptions/WebpayRequestException.php @@ -47,7 +47,8 @@ public function __construct( ?TransbankApiRequest $failedRequest = null, ?\Exception $previous = null ) { - $theMessage = isset($tbkErrorMessage) ? $tbkErrorMessage : $message; + $theMessage = $tbkErrorMessage ?? $message; + if ($failedRequest !== null) { $theMessage = $this->getExceptionMessage($message, $tbkErrorMessage, $httpCode); } @@ -75,8 +76,13 @@ public function getTransbankErrorMessage(): ?string */ public static function raise(WebpayRequestException $exception): self { - return new static($exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), - $exception->getFailedRequest(), $exception); + return new static( + $exception->getMessage(), + $exception->getTransbankErrorMessage(), + $exception->getHttpCode(), + $exception->getFailedRequest(), + $exception + ); } /** @@ -109,12 +115,15 @@ protected function getExceptionMessage( ): string { if (!$tbkErrorMessage) { - $theMessage = $message; - } else { - $theMessage = 'API Response: "'.$tbkErrorMessage.'" ['.$httpCode.'] - '.static::$defaultMessage; + return $message; } - return $theMessage; + return sprintf( + 'API Response: "%s" [%d] - %s', + $tbkErrorMessage, + $httpCode ?? 0, + static::$defaultMessage); + } } From 98ec3c14f2f749610dac785b892f4463d860d3d5 Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 19 Jun 2024 11:43:30 -0400 Subject: [PATCH 05/51] feat: typed default message --- src/Webpay/WebpayPlus/Exceptions/TransactionCommitException.php | 2 +- src/Webpay/WebpayPlus/Exceptions/TransactionCreateException.php | 2 +- src/Webpay/WebpayPlus/Exceptions/TransactionRefundException.php | 2 +- src/Webpay/WebpayPlus/Exceptions/TransactionStatusException.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Webpay/WebpayPlus/Exceptions/TransactionCommitException.php b/src/Webpay/WebpayPlus/Exceptions/TransactionCommitException.php index 7e77db10..a68ce09b 100644 --- a/src/Webpay/WebpayPlus/Exceptions/TransactionCommitException.php +++ b/src/Webpay/WebpayPlus/Exceptions/TransactionCommitException.php @@ -6,5 +6,5 @@ class TransactionCommitException extends WebpayRequestException { - protected static $defaultMessage = 'The transaction could not be confirmed'; + protected static string $defaultMessage = 'The transaction could not be confirmed'; } diff --git a/src/Webpay/WebpayPlus/Exceptions/TransactionCreateException.php b/src/Webpay/WebpayPlus/Exceptions/TransactionCreateException.php index e74e0445..52efa616 100644 --- a/src/Webpay/WebpayPlus/Exceptions/TransactionCreateException.php +++ b/src/Webpay/WebpayPlus/Exceptions/TransactionCreateException.php @@ -6,5 +6,5 @@ class TransactionCreateException extends WebpayRequestException { - protected static $defaultMessage = 'The transaction could not be created.'; + protected static string $defaultMessage = 'The transaction could not be created.'; } diff --git a/src/Webpay/WebpayPlus/Exceptions/TransactionRefundException.php b/src/Webpay/WebpayPlus/Exceptions/TransactionRefundException.php index 89ca5ca8..e86ec718 100644 --- a/src/Webpay/WebpayPlus/Exceptions/TransactionRefundException.php +++ b/src/Webpay/WebpayPlus/Exceptions/TransactionRefundException.php @@ -6,5 +6,5 @@ class TransactionRefundException extends WebpayRequestException { - protected static $defaultMessage = 'The transaction could not be refunded. '; + protected static string $defaultMessage = 'The transaction could not be refunded.'; } diff --git a/src/Webpay/WebpayPlus/Exceptions/TransactionStatusException.php b/src/Webpay/WebpayPlus/Exceptions/TransactionStatusException.php index 322736e0..860eaea7 100644 --- a/src/Webpay/WebpayPlus/Exceptions/TransactionStatusException.php +++ b/src/Webpay/WebpayPlus/Exceptions/TransactionStatusException.php @@ -6,5 +6,5 @@ class TransactionStatusException extends WebpayRequestException { - protected static $defaultMessage = 'Transaction Status could not be confirmed. Please verify given parameters'; + protected static string $defaultMessage = 'Transaction Status could not be confirmed. Please verify given parameters'; } From 54fa7d3f97f61500dfb2cd536b9f95557a9f9eb3 Mon Sep 17 00:00:00 2001 From: Fernando Date: Mon, 1 Jul 2024 09:25:26 -0400 Subject: [PATCH 06/51] refactor: add type in contracts files --- src/Contracts/HttpClientInterface.php | 15 ++++++++++++++- src/Contracts/RequestService.php | 11 ++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/Contracts/HttpClientInterface.php b/src/Contracts/HttpClientInterface.php index 5723dc01..82248592 100644 --- a/src/Contracts/HttpClientInterface.php +++ b/src/Contracts/HttpClientInterface.php @@ -2,7 +2,20 @@ namespace Transbank\Contracts; +use Psr\Http\Message\ResponseInterface; +use GuzzleHttp\Exception\GuzzleException; + interface HttpClientInterface { - public function request($method, $url, $payload = [], $options = null); + /** + * @param string $method + * @param string $url + * @param ?array $payload + * @param ?array $options + * + * @throws GuzzleException + * + * @return ResponseInterface + */ + public function request(string $method, string $url, ?array $payload = [], ?array $options = null); } diff --git a/src/Contracts/RequestService.php b/src/Contracts/RequestService.php index 0b0485f5..fd835e10 100644 --- a/src/Contracts/RequestService.php +++ b/src/Contracts/RequestService.php @@ -3,18 +3,19 @@ namespace Transbank\Contracts; use Transbank\Webpay\Options; +use Transbank\Webpay\Exceptions\WebpayRequestException; interface RequestService { /** - * @param $method - * @param $endpoint - * @param $payload + * @param string $method + * @param string $endpoint + * @param array $payload * @param Options $options * - * @throws Transbank\Webpay\Exceptions\WebpayRequestException + * @throws WebpayRequestException * * @return array Response from the API as json. */ - public function request($method, $endpoint, $payload, Options $options); + public function request(string $method, string $endpoint, array $payload, Options $options); } From 997f409cd45ef921049101b5df1d959b43900da0 Mon Sep 17 00:00:00 2001 From: Fernando Date: Mon, 1 Jul 2024 09:25:48 -0400 Subject: [PATCH 07/51] refactor: add type in patpass comercio files --- src/PatpassComercio/Inscription.php | 68 ++++++++++++------------- src/PatpassComercio/Options.php | 6 ++- src/PatpassComercio/PatpassComercio.php | 36 ++++++++++++- 3 files changed, 71 insertions(+), 39 deletions(-) diff --git a/src/PatpassComercio/Inscription.php b/src/PatpassComercio/Inscription.php index 6284c30a..a13e45fc 100644 --- a/src/PatpassComercio/Inscription.php +++ b/src/PatpassComercio/Inscription.php @@ -27,43 +27,42 @@ class Inscription /** * @var Options */ - protected $options; + protected Options $options; /** * Transaction constructor. * * @param Options $options - * @param RequestService |null $requestService + * @param RequestService|null $requestService */ public function __construct( Options $options, - RequestService $requestService = null + ?RequestService $requestService = null ) { $this->options = $options; - $this->setRequestService($requestService !== null ? $requestService : new HttpClientRequestService()); } /** - * @param $url - * @param $name - * @param $lastName - * @param $secondLastName - * @param $rut - * @param $serviceId - * @param $finalUrl - * @param $maxAmount - * @param $phone - * @param $cellPhone - * @param $patpassName - * @param $personEmail - * @param $commerceEmail - * @param $address - * @param $city + * @param string $url + * @param string $name + * @param string $lastName + * @param string $secondLastName + * @param string $rut + * @param string $serviceId + * @param string $finalUrl + * @param string $maxAmount + * @param string $phone + * @param string $cellPhone + * @param string $patpassName + * @param string $personEmail + * @param string $commerceEmail + * @param string $address + * @param string $city * * @throws InscriptionStartException - * @throws GuzzleHttp\Exception\GuzzleException + * @throws \GuzzleHttp\Exception\GuzzleException * * @return InscriptionStartResponse */ @@ -83,7 +82,7 @@ public function start( $commerceEmail, $address, $city - ) { + ): InscriptionStartResponse { $payload = [ 'url' => $url, 'nombre' => $name, @@ -120,15 +119,14 @@ public function start( } /** - * @param $token - * @param null $options + * @param string $token * * @throws InscriptionStatusException - * @throws GuzzleHttp\Exception\GuzzleException + * @throws \GuzzleHttp\Exception\GuzzleException * * @return InscriptionStatusResponse */ - public function status($token) + public function status(string $token): InscriptionStatusResponse { $payload = [ 'token' => $token, @@ -154,7 +152,7 @@ public function status($token) /** * @return Options */ - public function getOptions() + public function getOptions(): Options { return $this->options; } @@ -170,29 +168,29 @@ public function setOptions(Options $options) /** * @return string */ - protected function getBaseUrl() + protected function getBaseUrl(): string { return $this->getOptions()->getApiBaseUrl(); } /** - * @param $commerceCode - * @param $apiKey + * @param string $commerceCode + * @param string $apiKey * - * @return $this + * @return static */ - public static function buildForIntegration($commerceCode, $apiKey) + public static function buildForIntegration(string $commerceCode, string $apiKey) { return new static(new Options($apiKey, $commerceCode, Options::ENVIRONMENT_INTEGRATION)); } /** - * @param $commerceCode - * @param $apiKey + * @param string $commerceCode + * @param string $apiKey * - * @return $this + * @return static */ - public static function buildForProduction($commerceCode, $apiKey) + public static function buildForProduction(string $commerceCode, string $apiKey) { return new static(new Options($apiKey, $commerceCode, Options::ENVIRONMENT_PRODUCTION)); } diff --git a/src/PatpassComercio/Options.php b/src/PatpassComercio/Options.php index c3818842..20a33bb8 100644 --- a/src/PatpassComercio/Options.php +++ b/src/PatpassComercio/Options.php @@ -2,10 +2,12 @@ namespace Transbank\PatpassComercio; +use Transbank\Webpay\Options as WebpayOptions; + /** * Class Options. */ -class Options extends \Transbank\Webpay\Options +class Options extends WebpayOptions { const BASE_URL_PRODUCTION = 'https://www.pagoautomaticocontarjetas.cl/'; const BASE_URL_INTEGRATION = 'https://pagoautomaticocontarjetasint.transbank.cl/'; @@ -13,7 +15,7 @@ class Options extends \Transbank\Webpay\Options /** * @return array */ - public function getHeaders() + public function getHeaders(): array { return [ 'commercecode' => $this->getCommerceCode(), diff --git a/src/PatpassComercio/PatpassComercio.php b/src/PatpassComercio/PatpassComercio.php index 7e4e5c1b..5bb1ae4c 100644 --- a/src/PatpassComercio/PatpassComercio.php +++ b/src/PatpassComercio/PatpassComercio.php @@ -11,6 +11,38 @@ class PatpassComercio { - const INTEGRATION_API_KEY = 'cxxXQgGD9vrVe4M41FIt'; - const INTEGRATION_COMMERCE_CODE = '28299257'; + public const INTEGRATION_API_KEY = 'cxxXQgGD9vrVe4M41FIt'; + public const INTEGRATION_COMMERCE_CODE = '28299257'; + + /** + * @var string + */ + protected string $integrationApiKey; + + /** + * @var string + */ + protected string $integrationCommerceCode; + + public function __construct() + { + $this->integrationApiKey = self::INTEGRATION_API_KEY; + $this->integrationCommerceCode = self::INTEGRATION_COMMERCE_CODE; + } + + /** + * @return string + */ + public function getIntegrationApiKey(): string + { + return $this->integrationApiKey; + } + + /** + * @return string + */ + public function getIntegrationCommerceCode(): string + { + return $this->integrationCommerceCode; + } } From fbd0937b0c55f62a667148b100b1623e22860fb1 Mon Sep 17 00:00:00 2001 From: Fernando Date: Mon, 1 Jul 2024 09:26:04 -0400 Subject: [PATCH 08/51] refactor: add type in patpass comercio responses files --- .../Responses/InscriptionFinishResponse.php | 16 +++++++-------- .../Responses/InscriptionStartResponse.php | 16 +++++++-------- .../Responses/InscriptionStatusResponse.php | 20 ++++++++++++------- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/PatpassComercio/Responses/InscriptionFinishResponse.php b/src/PatpassComercio/Responses/InscriptionFinishResponse.php index 4e99b6c0..3bb8c4ac 100644 --- a/src/PatpassComercio/Responses/InscriptionFinishResponse.php +++ b/src/PatpassComercio/Responses/InscriptionFinishResponse.php @@ -10,12 +10,13 @@ class InscriptionFinishResponse { - public $status; - public $code; + public ?string $status; + public int $code; - public function __construct($httpCode) + public function __construct(int $httpCode) { $this->code = $httpCode; + $this->status = null; if ($httpCode == 204) { $this->status = 'OK'; @@ -26,19 +27,18 @@ public function __construct($httpCode) } /** - * @return mixed + * @return ?string */ - public function getStatus() + public function getStatus(): string { return $this->status; } /** - * @return mixed + * @return int */ - public function getCode() + public function getCode(): int { return $this->code; } - } diff --git a/src/PatpassComercio/Responses/InscriptionStartResponse.php b/src/PatpassComercio/Responses/InscriptionStartResponse.php index 1681c781..543c8a4c 100644 --- a/src/PatpassComercio/Responses/InscriptionStartResponse.php +++ b/src/PatpassComercio/Responses/InscriptionStartResponse.php @@ -12,32 +12,32 @@ class InscriptionStartResponse { - public $token; - public $urlWebpay; + public ?string $token; + public ?string $urlWebpay; /** * InscriptionStartResponse constructor. * - * @param $token + * @param array $json */ - public function __construct($json) + public function __construct(array $json) { $this->token = Utils::returnValueIfExists($json, 'token'); $this->urlWebpay = Utils::returnValueIfExists($json, 'url'); } /** - * @return mixed + * @return ?string */ - public function getToken() + public function getToken(): ?string { return $this->token; } /** - * @return mixed + * @return ?string */ - public function getUrlWebpay() + public function getUrlWebpay(): ?string { return $this->urlWebpay; } diff --git a/src/PatpassComercio/Responses/InscriptionStatusResponse.php b/src/PatpassComercio/Responses/InscriptionStatusResponse.php index 7d7bb9ba..aaa369b1 100644 --- a/src/PatpassComercio/Responses/InscriptionStatusResponse.php +++ b/src/PatpassComercio/Responses/InscriptionStatusResponse.php @@ -12,27 +12,33 @@ class InscriptionStatusResponse { - public $status; - public $urlVoucher; + public ?string $status; + public ?string $urlVoucher; - public function __construct($json) + /** + * InscriptionStatusResponse constructor. + * + * @param array $json + */ + + public function __construct(array $json) { $this->status = Utils::returnValueIfExists($json, 'authorized'); $this->urlVoucher = Utils::returnValueIfExists($json, 'voucherUrl'); } /** - * @return mixed + * @return ?string */ - public function getStatus() + public function getStatus(): ?string { return $this->status; } /** - * @return mixed + * @return ?string */ - public function getUrlVoucher() + public function getUrlVoucher(): ?string { return $this->urlVoucher; } From e530862e22aa649c13a5e5722dbfde8b8fe9669b Mon Sep 17 00:00:00 2001 From: Fernando Date: Mon, 1 Jul 2024 09:26:21 -0400 Subject: [PATCH 09/51] refactor: add type in utils files --- src/Utils/HasTransactionStatus.php | 90 +++++++++++++------------- src/Utils/HttpClient.php | 73 ++++++++++++--------- src/Utils/HttpClientRequestService.php | 59 +++++++++-------- src/Utils/InteractsWithWebpayApi.php | 32 ++++----- src/Utils/RequestServiceTrait.php | 23 +++---- src/Utils/ResponseCodesEnum.php | 2 +- src/Utils/TransactionStatusEnum.php | 17 +++-- src/Utils/Utils.php | 7 +- 8 files changed, 162 insertions(+), 141 deletions(-) diff --git a/src/Utils/HasTransactionStatus.php b/src/Utils/HasTransactionStatus.php index 4a5a0973..49380829 100644 --- a/src/Utils/HasTransactionStatus.php +++ b/src/Utils/HasTransactionStatus.php @@ -4,81 +4,81 @@ trait HasTransactionStatus { - public $status; - public $responseCode; - public $amount; - public $authorizationCode; - public $paymentTypeCode; - public $accountingDate; - public $installmentsNumber; - public $installmentsAmount; - public $sessionId; - public $buyOrder; - public $cardNumber; - public $cardDetail; - public $transactionDate; - public $balance; + public string $status; + public int $responseCode; + public float $amount; + public string $authorizationCode; + public string $paymentTypeCode; + public string $accountingDate; + public int $installmentsNumber; + public ?float $installmentsAmount; + public string $sessionId; + public string $buyOrder; + public string $cardNumber; + public array $cardDetail; + public string $transactionDate; + public ?float $balance; /** - * @return mixed + * @return ?float */ - public function getBalance() + public function getBalance(): ?float { return $this->balance; } /** - * @return mixed + * @return string */ - public function getStatus() + public function getStatus(): string { return $this->status; } /** - * @return mixed + * @return string */ - public function getAuthorizationCode() + public function getAuthorizationCode(): string { return $this->authorizationCode; } /** - * @return mixed + * @return int */ - public function getInstallmentsNumber() + public function getInstallmentsNumber(): int { return $this->installmentsNumber; } /** - * @return mixed + * @return int */ - public function getResponseCode() + public function getResponseCode(): int { return $this->responseCode; } /** - * @return mixed + * @return string */ - public function getBuyOrder() + public function getBuyOrder(): string { return $this->buyOrder; } /** - * @return mixed + * @return string */ - public function getAccountingDate() + public function getAccountingDate(): string { return $this->accountingDate; } /** - * @param $json + * @param array $json */ - public function setTransactionStatusFields($json) + public function setTransactionStatusFields(array $json): void { $this->amount = Utils::returnValueIfExists($json, 'amount'); $this->status = Utils::returnValueIfExists($json, 'status'); @@ -94,63 +94,61 @@ public function setTransactionStatusFields($json) $this->installmentsAmount = Utils::returnValueIfExists($json, 'installments_amount'); $this->installmentsNumber = Utils::returnValueIfExists($json, 'installments_number'); $this->balance = Utils::returnValueIfExists($json, 'balance'); - } /** - * @return mixed|null + * @return ?array */ - public function getCardDetail() + public function getCardDetail(): ?array { return $this->cardDetail; } /** - * @return mixed + * @return ?string */ - public function getCardNumber() + public function getCardNumber(): ?string { return $this->cardNumber; } /** - * @return mixed + * @return ?string */ - public function getPaymentTypeCode() + public function getPaymentTypeCode(): ?string { return $this->paymentTypeCode; } /** - * @return mixed + * @return ?float */ - public function getInstallmentsAmount() + public function getInstallmentsAmount(): ?float { return $this->installmentsAmount; } /** - * @return mixed + * @return ?string */ - public function getSessionId() + public function getSessionId(): ?string { return $this->sessionId; } /** - * @return mixed + * @return ?float */ - public function getAmount() + public function getAmount(): ?float { return $this->amount; } /** - * @return mixed + * @return ?string */ - public function getTransactionDate() + public function getTransactionDate(): ?string { return $this->transactionDate; } - } diff --git a/src/Utils/HttpClient.php b/src/Utils/HttpClient.php index 0b0010ca..6f2e6793 100644 --- a/src/Utils/HttpClient.php +++ b/src/Utils/HttpClient.php @@ -5,22 +5,24 @@ use Composer\InstalledVersions; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; +use GuzzleHttp\Exception\GuzzleException; use Transbank\Contracts\HttpClientInterface; +use Psr\Http\Message\ResponseInterface; + class HttpClient implements HttpClientInterface { /** - * @param $url - * @param $path - * @param $options - * @param $method - * @param $payload + * @param string $method + * @param string $url + * @param ?array $payload + * @param ?array $options * - *@throws \GuzzleHttp\Exception\GuzzleException + *@throws GuzzleException * - * @return \Psr\Http\Message\ResponseInterface + * @return ResponseInterface */ - public function request($method, $url, $payload = [], $options = null) + public function request(string $method, string $url, ?array $payload = [], ?array $options = null) { $installedVersion = 'unknown'; @@ -36,7 +38,7 @@ public function request($method, $url, $payload = [], $options = null) 'User-Agent' => 'SDK-PHP/'.$installedVersion, ]; - $givenHeaders = isset($options['headers']) ? $options['headers'] : []; + $givenHeaders = $options['headers'] ?? []; $headers = array_merge($baseHeaders, $givenHeaders); if (!$payload) { $payload = null; @@ -55,20 +57,25 @@ public function request($method, $url, $payload = [], $options = null) } /** - * @param $method - * @param $url - * @param array $headers - * @param array $payload + * Sends a Guzzle 5 request. + * + * @param string $method + * @param string $url + * @param array $headers + * @param ?array $payload + * @param int $timeout * - * @throws \GuzzleHttp\Exception\GuzzleException + * @throws GuzzleException * - * @return \Psr\Http\Message\ResponseInterface + * @return ResponseInterface */ - protected function sendGuzzle5Request($method, $url, array $headers, $payload, $timeout) + protected function sendGuzzle5Request($method, $url, array $headers, $payload, int $timeout): ResponseInterface { - $client = new Client(['timeout' => $timeout, - 'read_timeout' => $timeout, - 'connect_timeout' => $timeout]); + $client = new Client([ + 'timeout' => $timeout, + 'read_timeout' => $timeout, + 'connect_timeout' => $timeout, + ]); $request = $client->createRequest($method, $url, [ 'headers' => $headers, @@ -79,24 +86,28 @@ protected function sendGuzzle5Request($method, $url, array $headers, $payload, $ } /** - * @param $method - * @param $url - * @param array $headers - * @param string|null $payload + * Sends a Guzzle request. * - * @throws \GuzzleHttp\Exception\GuzzleException + * @param string $method + * @param string $url + * @param array $headers + * @param ?string $payload + * @param int $timeout * - * @return \Psr\Http\Message\ResponseInterface + * @throws GuzzleException + * + * @return ResponseInterface */ - protected function sendGuzzleRequest($method, $url, array $headers, $payload, $timeout) + protected function sendGuzzleRequest(string $method, string $url, array $headers, ?string $payload, int $timeout): ResponseInterface { $request = new Request($method, $url, $headers, $payload); - $client = new Client(['http_errors' => false, - 'timeout' => $timeout, - 'read_timeout' => $timeout, - 'connect_timeout' => $timeout], - ); + $client = new Client([ + 'http_errors' => false, + 'timeout' => $timeout, + 'read_timeout' => $timeout, + 'connect_timeout' => $timeout, + ]); return $client->send($request); } diff --git a/src/Utils/HttpClientRequestService.php b/src/Utils/HttpClientRequestService.php index 2b48620d..36c2a566 100644 --- a/src/Utils/HttpClientRequestService.php +++ b/src/Utils/HttpClientRequestService.php @@ -7,32 +7,35 @@ use Transbank\Webpay\Exceptions\TransbankApiRequest; use Transbank\Webpay\Exceptions\WebpayRequestException; use Transbank\Webpay\Options; +use GuzzleHttp\Exception\GuzzleException; +use Psr\Http\Message\ResponseInterface; class HttpClientRequestService implements RequestService { /** - * @var Psr\Http\Message\ResponseInterface|null + * @var ?ResponseInterface */ - protected $lastResponse = null; + protected ?ResponseInterface $lastResponse = null; /** - * @var TransbankApiRequest|null + * @var ?TransbankApiRequest */ - protected $lastRequest = null; + protected ?TransbankApiRequest $lastRequest = null; + /** * @var HttpClientInterface */ - protected $httpClient; + protected HttpClientInterface $httpClient; - public function __construct(HttpClientInterface $httpClient = null) + public function __construct(?HttpClientInterface $httpClient = null) { - $this->setHttpClient($httpClient !== null ? $httpClient : new HttpClient()); + $this->setHttpClient($httpClient ?? new HttpClient()); } /** * @return HttpClientInterface */ - public function getHttpClient() + public function getHttpClient(): HttpClientInterface { return $this->httpClient; } @@ -40,28 +43,28 @@ public function getHttpClient() /** * @param HttpClientInterface $httpClient */ - public function setHttpClient($httpClient) + public function setHttpClient(HttpClientInterface $httpClient): void { $this->httpClient = $httpClient; } /** - * @param $method - * @param $endpoint - * @param $payload + * @param string $method + * @param string $endpoint + * @param array $payload * @param Options $options * - * @throws GuzzleHttp\Exception\GuzzleException + * @throws GuzzleException * @throws WebpayRequestException * * @return array */ public function request( - $method, - $endpoint, - $payload, + string $method, + string $endpoint, + array $payload, Options $options - ) { + ): array { $headers = $options->getHeaders(); $client = $this->httpClient; if ($client == null) { @@ -82,11 +85,7 @@ public function request( $reason = $response->getReasonPhrase(); $message = "Could not obtain a response from Transbank API: $reason (HTTP code $responseStatusCode)"; $body = json_decode($response->getBody(), true); - $tbkErrorMessage = null; - if (isset($body['error_message'])) { - $tbkErrorMessage = $body['error_message']; - $message = "Transbank API REST Error: $tbkErrorMessage | $message"; - } + $tbkErrorMessage = $body['error_message'] ?? null; throw new WebpayRequestException($message, $tbkErrorMessage, $responseStatusCode, $request); } @@ -95,33 +94,33 @@ public function request( } /** - * @return Psr\Http\Message\ResponseInterface|null + * @return ?ResponseInterface */ - public function getLastResponse() + public function getLastResponse(): ?ResponseInterface { return $this->lastResponse; } /** - * @param Psr\Http\Message\ResponseInterface|null $lastResponse + * @param ?ResponseInterface $lastResponse */ - protected function setLastResponse($lastResponse) + protected function setLastResponse(?ResponseInterface $lastResponse): void { $this->lastResponse = $lastResponse; } /** - * @return TransbankApiRequest|null + * @return ?TransbankApiRequest */ - public function getLastRequest() + public function getLastRequest(): ?TransbankApiRequest { return $this->lastRequest; } /** - * @param TransbankApiRequest|null $lastRequest + * @param ?TransbankApiRequest $lastRequest */ - protected function setLastRequest($lastRequest) + protected function setLastRequest(?TransbankApiRequest $lastRequest): void { $this->lastRequest = $lastRequest; } diff --git a/src/Utils/InteractsWithWebpayApi.php b/src/Utils/InteractsWithWebpayApi.php index 8fc95acd..ad635c1c 100644 --- a/src/Utils/InteractsWithWebpayApi.php +++ b/src/Utils/InteractsWithWebpayApi.php @@ -15,17 +15,17 @@ trait InteractsWithWebpayApi /** * @var Options */ - protected $options; + protected Options $options; /** * Transaction constructor. * - * @param Options $options - * @param RequestService |null $requestService + * @param Options $options + * @param ?RequestService $requestService */ public function __construct( Options $options, - RequestService $requestService = null + ?RequestService $requestService = null ) { $this->options = $options; @@ -36,7 +36,7 @@ public function __construct( /** * @return Options */ - public function getOptions() + public function getOptions(): Options { return $this->options; } @@ -44,7 +44,7 @@ public function getOptions() /** * @param Options $options */ - public function setOptions(Options $options) + public function setOptions(Options $options): void { $this->options = $options; } @@ -52,29 +52,31 @@ public function setOptions(Options $options) /** * @return string */ - protected function getBaseUrl() + protected function getBaseUrl(): string { return $this->getOptions()->getApiBaseUrl(); } /** - * @param $commerceCode - * @param $apiKey + * Build an instance configured for integration environment. + * @param string $commerceCode + * @param string $apiKey * - * @return $this + * @return static */ - public static function buildForIntegration($commerceCode, $apiKey) + public static function buildForIntegration(string $commerceCode, string $apiKey): self { return new static(new Options($apiKey, $commerceCode, Options::ENVIRONMENT_INTEGRATION)); } /** - * @param $commerceCode - * @param $apiKey + * Build an instance configured for integration environment. + * @param string $commerceCode + * @param string $apiKey * - * @return $this + * @return static */ - public static function buildForProduction($commerceCode, $apiKey) + public static function buildForProduction(string $commerceCode, string $apiKey): self { return new static(new Options($apiKey, $commerceCode, Options::ENVIRONMENT_PRODUCTION)); } diff --git a/src/Utils/RequestServiceTrait.php b/src/Utils/RequestServiceTrait.php index 3a531501..b31c3f2f 100644 --- a/src/Utils/RequestServiceTrait.php +++ b/src/Utils/RequestServiceTrait.php @@ -3,6 +3,7 @@ namespace Transbank\Utils; use Transbank\Contracts\RequestService; +use Transbank\Webpay\Exceptions\WebpayRequestException; /** * Trait RequestServiceTrait . @@ -11,20 +12,20 @@ trait RequestServiceTrait { /** - * @var RequestService |null + * @var ?RequestService */ - protected $requestService; + protected ?RequestService $requestService = null; /** - * @param $method - * @param $endpoint - * @param array|null $payload + * @param string $method + * @param string $endpoint + * @param array $payload * - * @throws \Transbank\Webpay\Exceptions\WebpayRequestException + * @throws WebpayRequestException * * @return mixed */ - public function sendRequest($method, $endpoint, $payload = []) + public function sendRequest(string $method, string $endpoint, array $payload = []) { return $this->getRequestService()->request( $method, @@ -35,17 +36,17 @@ public function sendRequest($method, $endpoint, $payload = []) } /** - * @return RequestService |null + * @return ?RequestService */ - public function getRequestService() + public function getRequestService(): ?RequestService { return $this->requestService; } /** - * @param RequestService |null $requestService + * @param ?RequestService $requestService */ - public function setRequestService(RequestService $requestService = null) + public function setRequestService(?RequestService $requestService = null): void { $this->requestService = $requestService; } diff --git a/src/Utils/ResponseCodesEnum.php b/src/Utils/ResponseCodesEnum.php index c9ac8cfc..19502094 100644 --- a/src/Utils/ResponseCodesEnum.php +++ b/src/Utils/ResponseCodesEnum.php @@ -4,5 +4,5 @@ class ResponseCodesEnum { - const RESPONSE_CODE_APPROVED = 0; + public const RESPONSE_CODE_APPROVED = 0; } diff --git a/src/Utils/TransactionStatusEnum.php b/src/Utils/TransactionStatusEnum.php index 0a568ceb..c5978f0b 100644 --- a/src/Utils/TransactionStatusEnum.php +++ b/src/Utils/TransactionStatusEnum.php @@ -2,12 +2,17 @@ namespace Transbank\Utils; +/** + * Class TransactionStatusEnum + * + * @package Transbank\Utils + */ class TransactionStatusEnum { - const STATUS_AUTHORIZED = 'AUTHORIZED'; - const STATUS_NULLIFIED = 'NULLIFIED'; - const STATUS_REVERSED = 'REVERSED'; - const STATUS_PARTIALLY_NULLIFIED = 'PARTIALLY_NULLIFIED'; - const STATUS_CAPTURED = 'CAPTURED'; - const STATUS_FAILED = 'FAILED'; + public const STATUS_AUTHORIZED = 'AUTHORIZED'; + public const STATUS_NULLIFIED = 'NULLIFIED'; + public const STATUS_REVERSED = 'REVERSED'; + public const STATUS_PARTIALLY_NULLIFIED = 'PARTIALLY_NULLIFIED'; + public const STATUS_CAPTURED = 'CAPTURED'; + public const STATUS_FAILED = 'FAILED'; } diff --git a/src/Utils/Utils.php b/src/Utils/Utils.php index 7a81fcd0..16cd8a7d 100644 --- a/src/Utils/Utils.php +++ b/src/Utils/Utils.php @@ -10,7 +10,12 @@ class Utils { - public static function returnValueIfExists($json, $key) + /** + * @param array $json + * @param string $key + * @return mixed + */ + public static function returnValueIfExists(array $json, string $key): mixed { return isset($json[$key]) ? $json[$key] : null; } From a4d8352b6106bf8d793e983800c2a3d00c48dfd7 Mon Sep 17 00:00:00 2001 From: Fernando Date: Mon, 1 Jul 2024 09:26:37 -0400 Subject: [PATCH 10/51] refactor: add type in webpay files --- src/Webpay/Options.php | 62 ++++++++++++++++++------------ src/Webpay/TransaccionCompleta.php | 26 ++++++++++--- src/Webpay/WebpayPlus.php | 13 +++++-- 3 files changed, 66 insertions(+), 35 deletions(-) diff --git a/src/Webpay/Options.php b/src/Webpay/Options.php index b1bdb722..b9ecfb4f 100644 --- a/src/Webpay/Options.php +++ b/src/Webpay/Options.php @@ -4,6 +4,12 @@ /** * Class Options. + * @var string ENVIRONMENT_PRODUCTION + * @var string ENVIRONMENT_INTEGRATION + * @var string BASE_URL_PRODUCTION + * @var string BASE_URL_INTEGRATION + * @var string INTEGRATION_API_KEY + * @var int DEFAULT_TIMEOUT */ class Options { @@ -19,41 +25,48 @@ class Options /** * @var int Timeout for requests in seconds */ - protected $timeout; + protected int $timeout; /** - * @var string Your api key, given by Transbank.Sent as a header when + * @var ?string Your api key, given by Transbank.Sent as a header when * making requests to Transbank on a field called "Tbk-Api-Key-Secret" */ - public $apiKey = null; + public ?string $apiKey = null; /** - * @var string Your commerce code, given by Transbank. Sent as + * @var ?string Your commerce code, given by Transbank. Sent as * a header when making requests to Transbank on a field called "Tbk-Api-Key-Id" */ - public $commerceCode = null; + public ?string $commerceCode = null; /** * @var string Sets the environment that the SDK is going * to point to (eg. TEST, LIVE, etc). */ - public $integrationType = self::ENVIRONMENT_INTEGRATION; - - public function __construct($apiKey, $commerceCode, $integrationType, $timeout = self::DEFAULT_TIMEOUT) - { + public string $integrationType = self::ENVIRONMENT_INTEGRATION; + + public function __construct( + string $apiKey, + string $commerceCode, + string $integrationType, + int $timeout = self::DEFAULT_TIMEOUT + ) { $this->apiKey = $apiKey; $this->commerceCode = $commerceCode; $this->integrationType = $integrationType; $this->timeout = $timeout; } - public function isProduction() + /** + * @return bool + */ + public function isProduction(): bool { return $this->getIntegrationType() === static::ENVIRONMENT_PRODUCTION; } /** - * @return string + * @return ?string */ - public function getIntegrationType() + public function getIntegrationType(): ?string { return $this->integrationType; } @@ -63,7 +76,7 @@ public function getIntegrationType() * * @return Options */ - public function setIntegrationType($integrationType) + public function setIntegrationType($integrationType): Options { $this->integrationType = $integrationType; @@ -71,9 +84,9 @@ public function setIntegrationType($integrationType) } /** - * @return mixed + * @return ?string */ - public function getApiKey() + public function getApiKey(): ?string { return $this->apiKey; } @@ -83,7 +96,7 @@ public function getApiKey() * * @return Options */ - public function setApiKey($apiKey) + public function setApiKey(string $apiKey): Options { $this->apiKey = $apiKey; @@ -91,19 +104,19 @@ public function setApiKey($apiKey) } /** - * @return mixed + * @return ?string */ - public function getCommerceCode() + public function getCommerceCode(): ?string { return $this->commerceCode; } /** - * @param mixed $commerceCode + * @param string $commerceCode * * @return Options */ - public function setCommerceCode($commerceCode) + public function setCommerceCode(string $commerceCode): Options { $this->commerceCode = $commerceCode; @@ -114,19 +127,18 @@ public function setCommerceCode($commerceCode) * @return string Returns the base URL used for making requests, depending on which * integration types */ - public function getApiBaseUrl() + public function getApiBaseUrl(): string { if ($this->isProduction()) { return static::BASE_URL_PRODUCTION; } - return static::BASE_URL_INTEGRATION; } /** * @return array */ - public function getHeaders() + public function getHeaders(): array { return [ 'Tbk-Api-Key-Id' => $this->getCommerceCode(), @@ -137,7 +149,7 @@ public function getHeaders() /** * @return int */ - public function getTimeout() + public function getTimeout(): int { return $this->timeout; } @@ -147,7 +159,7 @@ public function getTimeout() * * @return Options */ - public function setTimeout($timeout) + public function setTimeout($timeout): Options { $this->timeout = $timeout; diff --git a/src/Webpay/TransaccionCompleta.php b/src/Webpay/TransaccionCompleta.php index 7ca73d26..2b0ab269 100644 --- a/src/Webpay/TransaccionCompleta.php +++ b/src/Webpay/TransaccionCompleta.php @@ -1,15 +1,29 @@ Date: Mon, 1 Jul 2024 09:26:53 -0400 Subject: [PATCH 11/51] refactor: add type in webpay exceptions files --- src/Webpay/Exceptions/TransbankApiRequest.php | 41 +++++++++++-------- src/Webpay/Exceptions/TransbankException.php | 9 +++- src/Webpay/Exceptions/WebpayException.php | 9 +++- .../Exceptions/WebpayRequestException.php | 40 +++++++++--------- 4 files changed, 58 insertions(+), 41 deletions(-) diff --git a/src/Webpay/Exceptions/TransbankApiRequest.php b/src/Webpay/Exceptions/TransbankApiRequest.php index 9fc94ed1..43b41701 100644 --- a/src/Webpay/Exceptions/TransbankApiRequest.php +++ b/src/Webpay/Exceptions/TransbankApiRequest.php @@ -4,23 +4,28 @@ class TransbankApiRequest { - public $method; - public $baseUrl; - public $endpoint; - public $payload; - public $headers; + public string $method; + public string $baseUrl; + public string $endpoint; + public array $payload; + public array $headers; /** * FailedRequestCapturedData constructor. * - * @param $method - * @param $baseUrl - * @param $endpoint + * @param string $method + * @param string $baseUrl + * @param string $endpoint * @param array $payload * @param array $headers */ - public function __construct($method, $baseUrl, $endpoint, $payload = [], $headers = []) - { + public function __construct( + string $method, + string $baseUrl, + string $endpoint, + array $payload = [], + array $headers = [] + ) { $this->method = $method; $this->baseUrl = $baseUrl; $this->endpoint = $endpoint; @@ -29,25 +34,25 @@ public function __construct($method, $baseUrl, $endpoint, $payload = [], $header } /** - * @return mixed + * @return string */ - public function getMethod() + public function getMethod(): string { return $this->method; } /** - * @return mixed + * @return string */ - public function getBaseUrl() + public function getBaseUrl(): string { return $this->baseUrl; } /** - * @return mixed + * @return string */ - public function getEndpoint() + public function getEndpoint(): string { return $this->endpoint; } @@ -55,7 +60,7 @@ public function getEndpoint() /** * @return array */ - public function getPayload() + public function getPayload(): array { return $this->payload; } @@ -63,7 +68,7 @@ public function getPayload() /** * @return array */ - public function getHeaders() + public function getHeaders(): array { return $this->headers; } diff --git a/src/Webpay/Exceptions/TransbankException.php b/src/Webpay/Exceptions/TransbankException.php index 4ab01797..7abe9d86 100644 --- a/src/Webpay/Exceptions/TransbankException.php +++ b/src/Webpay/Exceptions/TransbankException.php @@ -6,7 +6,14 @@ class TransbankException extends \Exception { const DEFAULT_MESSAGE = 'An error has happened, verify given parameters and try again.'; - public function __construct($message = self::DEFAULT_MESSAGE, $code = 0, $previous = null) + /** + * TransbankException constructor. + * + * @param string $message + * @param int $code + * @param ?\Throwable $previous + */ + public function __construct(string $message = self::DEFAULT_MESSAGE, int $code = 0, ?\Throwable $previous = null) { parent::__construct($message, $code, $previous); } diff --git a/src/Webpay/Exceptions/WebpayException.php b/src/Webpay/Exceptions/WebpayException.php index 9fa92f3c..2451ef3f 100644 --- a/src/Webpay/Exceptions/WebpayException.php +++ b/src/Webpay/Exceptions/WebpayException.php @@ -11,7 +11,14 @@ class WebpayException extends \Exception { const DEFAULT_MESSAGE = 'An error has happened, verify given parameters and try again.'; - public function __construct($message = self::DEFAULT_MESSAGE, $code = 0, $previous = null) + /** + * WebpayException constructor. + * + * @param string $message + * @param int $code + * @param \Throwable|null $previous + */ + public function __construct(string $message = self::DEFAULT_MESSAGE, int $code = 0, ?\Throwable $previous = null) { parent::__construct($message, $code, $previous); } diff --git a/src/Webpay/Exceptions/WebpayRequestException.php b/src/Webpay/Exceptions/WebpayRequestException.php index c8488c4a..a36a5d9a 100644 --- a/src/Webpay/Exceptions/WebpayRequestException.php +++ b/src/Webpay/Exceptions/WebpayRequestException.php @@ -13,32 +13,32 @@ class WebpayRequestException extends WebpayException protected static string $defaultMessage = 'An error has happened on the request'; /** - * @var mixed + * @var ?string */ - protected $transbankErrorMessage; + protected ?string $transbankErrorMessage; /** - * @var int + * @var ?int */ protected $httpCode; /** - * @var + * @var mixed */ protected $response; /** - * @var TransbankApiRequest|null + * @var ?TransbankApiRequest */ - protected $failedRequest; + protected ?TransbankApiRequest $failedRequest; /** * WebpayRequestException constructor. * - * @param string $message - * @param string|null $tbkErrorMessage - * @param int|null $httpCode - * @param TransbankApiRequest|null $failedRequest - * @param \Exception|null $previous + * @param string $message + * @param ?string $tbkErrorMessage + * @param ?int $httpCode + * @param ?TransbankApiRequest $failedRequest + * @param ?\Exception $previous */ public function __construct( string $message, @@ -48,7 +48,7 @@ public function __construct( ?\Exception $previous = null ) { $theMessage = $tbkErrorMessage ?? $message; - + if ($failedRequest !== null) { $theMessage = $this->getExceptionMessage($message, $tbkErrorMessage, $httpCode); } @@ -62,7 +62,7 @@ public function __construct( } /** - * @return string|null + * @return ?string */ public function getTransbankErrorMessage(): ?string { @@ -94,7 +94,7 @@ public function getHttpCode(): int } /** - * @return TransbankApiRequest|null + * @return ?TransbankApiRequest */ public function getFailedRequest(): ?TransbankApiRequest { @@ -102,9 +102,9 @@ public function getFailedRequest(): ?TransbankApiRequest } /** - * @param string $message - * @param string|null $tbkErrorMessage - * @param int|null $httpCode + * @param string $message + * @param ?string $tbkErrorMessage + * @param ?int $httpCode * * @return string */ @@ -113,7 +113,6 @@ protected function getExceptionMessage( ?string $tbkErrorMessage, ?int $httpCode ): string { - if (!$tbkErrorMessage) { return $message; } @@ -122,8 +121,7 @@ protected function getExceptionMessage( 'API Response: "%s" [%d] - %s', $tbkErrorMessage, $httpCode ?? 0, - static::$defaultMessage); - + static::$defaultMessage + ); } - } From e166427e22af8bc7725aed8d062a1b5c2b0c5bff Mon Sep 17 00:00:00 2001 From: Fernando Date: Mon, 1 Jul 2024 09:27:01 -0400 Subject: [PATCH 12/51] refactor: add type in oneclick files --- src/Webpay/Oneclick/MallInscription.php | 50 ++++++++++----- src/Webpay/Oneclick/MallTransaction.php | 84 ++++++++++++++++++++----- 2 files changed, 103 insertions(+), 31 deletions(-) diff --git a/src/Webpay/Oneclick/MallInscription.php b/src/Webpay/Oneclick/MallInscription.php index 66de83d0..4c124f9c 100644 --- a/src/Webpay/Oneclick/MallInscription.php +++ b/src/Webpay/Oneclick/MallInscription.php @@ -4,14 +4,13 @@ use Transbank\Utils\InteractsWithWebpayApi; use Transbank\Webpay\Exceptions\WebpayRequestException; -use Transbank\Webpay\Oneclick; use Transbank\Webpay\Oneclick\Exceptions\InscriptionDeleteException; use Transbank\Webpay\Oneclick\Exceptions\InscriptionFinishException; use Transbank\Webpay\Oneclick\Exceptions\InscriptionStartException; use Transbank\Webpay\Oneclick\Responses\InscriptionDeleteResponse; use Transbank\Webpay\Oneclick\Responses\InscriptionFinishResponse; use Transbank\Webpay\Oneclick\Responses\InscriptionStartResponse; -use Transbank\Webpay\Options; +use GuzzleHttp\Exception\GuzzleException; class MallInscription { @@ -22,17 +21,16 @@ class MallInscription const INSCRIPTION_DELETE_ENDPOINT = 'rswebpaytransaction/api/oneclick/v1.2/inscriptions'; /** - * @param $username - * @param $email - * @param $responseUrl - * @param null $options - * - * @throws InscriptionStartException - * @throws \GuzzleHttp\Exception\GuzzleException + * @param string $username + * @param string $email + * @param string $responseUrl * * @return InscriptionStartResponse + * + * @throws InscriptionStartException + * @throws GuzzleException */ - public function start($username, $email, $responseUrl) + public function start($username, $email, $responseUrl): InscriptionStartResponse { $payload = [ 'username' => $username, @@ -47,7 +45,8 @@ public function start($username, $email, $responseUrl) $payload ); } catch (WebpayRequestException $exception) { - throw new InscriptionStartException($exception->getMessage(), + throw new InscriptionStartException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), @@ -58,16 +57,25 @@ public function start($username, $email, $responseUrl) return new InscriptionStartResponse($response); } - public function finish($token) + /** + * @param string $token + * + * @return InscriptionFinishResponse + * + * @throws InscriptionFinishException + * @throws GuzzleException + */ + public function finish($token): InscriptionFinishResponse { try { $response = $this->sendRequest( 'PUT', str_replace('{token}', $token, static::INSCRIPTION_FINISH_ENDPOINT), - null + [] ); } catch (WebpayRequestException $exception) { - throw new InscriptionFinishException($exception->getMessage(), + throw new InscriptionFinishException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), @@ -78,7 +86,16 @@ public function finish($token) return new InscriptionFinishResponse($response); } - public function delete($tbkUser, $username) + /** + * @param string $tbkUser + * @param string $username + * + * @return InscriptionDeleteResponse + * + * @throws InscriptionDeleteException + * @throws GuzzleException + */ + public function delete($tbkUser, $username): InscriptionDeleteResponse { $payload = [ 'tbk_user' => $tbkUser, @@ -96,7 +113,8 @@ public function delete($tbkUser, $username) return new InscriptionDeleteResponse(false, $exception->getHttpCode()); } - throw new InscriptionDeleteException($exception->getMessage(), + throw new InscriptionDeleteException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), diff --git a/src/Webpay/Oneclick/MallTransaction.php b/src/Webpay/Oneclick/MallTransaction.php index 31f54e06..ec8c6510 100644 --- a/src/Webpay/Oneclick/MallTransaction.php +++ b/src/Webpay/Oneclick/MallTransaction.php @@ -12,6 +12,7 @@ use Transbank\Webpay\Oneclick\Responses\MallTransactionCaptureResponse; use Transbank\Webpay\Oneclick\Responses\MallTransactionRefundResponse; use Transbank\Webpay\Oneclick\Responses\MallTransactionStatusResponse; +use GuzzleHttp\Exception\GuzzleException; class MallTransaction { @@ -21,12 +22,23 @@ class MallTransaction const TRANSACTION_REFUND_ENDPOINT = 'rswebpaytransaction/api/oneclick/v1.2/transactions/{buy_order}/refunds'; const TRANSACTION_CAPTURE_ENDPOINT = 'rswebpaytransaction/api/oneclick/v1.2/transactions/capture'; + /** + * @param string $userName + * @param string $tbkUser + * @param string $parentBuyOrder + * @param array $details + * + * @return MallTransactionAuthorizeResponse + * + * @throws MallTransactionAuthorizeException + * @throws GuzzleException + */ public function authorize( - $userName, - $tbkUser, - $parentBuyOrder, - $details - ) { + string $userName, + string $tbkUser, + string $parentBuyOrder, + array $details + ): MallTransactionAuthorizeResponse { $payload = [ 'username' => $userName, 'tbk_user' => $tbkUser, @@ -41,7 +53,8 @@ public function authorize( $payload ); } catch (WebpayRequestException $exception) { - throw new MallTransactionAuthorizeException($exception->getMessage(), + throw new MallTransactionAuthorizeException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), @@ -52,8 +65,23 @@ public function authorize( return new MallTransactionAuthorizeResponse($response); } - public function capture($childCommerceCode, $childBuyOrder, $authorizationCode, $amount) - { + /** + * @param string $childCommerceCode + * @param string $childBuyOrder + * @param string $authorizationCode + * @param float $amount + * + * @return MallTransactionCaptureResponse + * + * @throws MallTransactionCaptureException + * @throws GuzzleException + */ + public function capture( + string $childCommerceCode, + string $childBuyOrder, + string $authorizationCode, + float $amount + ): MallTransactionCaptureResponse { $payload = [ 'commerce_code' => $childCommerceCode, 'buy_order' => $childBuyOrder, @@ -68,7 +96,8 @@ public function capture($childCommerceCode, $childBuyOrder, $authorizationCode, $payload ); } catch (WebpayRequestException $exception) { - throw new MallTransactionCaptureException($exception->getMessage(), + throw new MallTransactionCaptureException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), @@ -79,16 +108,25 @@ public function capture($childCommerceCode, $childBuyOrder, $authorizationCode, return new MallTransactionCaptureResponse($response); } - public function status($buyOrder) + /** + * @param string $buyOrder + * + * @return MallTransactionStatusResponse + * + * @throws MallTransactionStatusException + * @throws GuzzleException + */ + public function status(string $buyOrder): MallTransactionStatusResponse { try { $response = $this->sendRequest( 'GET', str_replace('{buy_order}', $buyOrder, static::TRANSACTION_STATUS_ENDPOINT), - null + [] ); } catch (WebpayRequestException $exception) { - throw new MallTransactionStatusException($exception->getMessage(), + throw new MallTransactionStatusException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), @@ -99,8 +137,23 @@ public function status($buyOrder) return new MallTransactionStatusResponse($response); } - public function refund($buyOrder, $childCommerceCode, $childBuyOrder, $amount) - { + /** + * @param string $buyOrder + * @param string $childCommerceCode + * @param string $childBuyOrder + * @param float $amount + * + * @return MallTransactionRefundResponse + * + * @throws MallRefundTransactionException + * @throws GuzzleException + */ + public function refund( + string $buyOrder, + string $childCommerceCode, + string $childBuyOrder, + float $amount + ): MallTransactionRefundResponse { $payload = [ 'detail_buy_order' => $childBuyOrder, 'commerce_code' => $childCommerceCode, @@ -114,7 +167,8 @@ public function refund($buyOrder, $childCommerceCode, $childBuyOrder, $amount) $payload ); } catch (WebpayRequestException $exception) { - throw new MallRefundTransactionException($exception->getMessage(), + throw new MallRefundTransactionException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), From 09afc764f4bcbede2befcc06097ff4fabf2a4808 Mon Sep 17 00:00:00 2001 From: Fernando Date: Mon, 1 Jul 2024 09:27:16 -0400 Subject: [PATCH 13/51] refactor: add type in oneclick responses files --- .../Responses/InscriptionDeleteResponse.php | 12 ++--- .../Responses/InscriptionFinishResponse.php | 37 +++++++------ .../Responses/InscriptionStartResponse.php | 19 ++++--- .../MallTransactionAuthorizeResponse.php | 12 ++--- .../MallTransactionCaptureResponse.php | 19 ++++--- .../MallTransactionRefundResponse.php | 39 +++++++------- .../MallTransactionStatusResponse.php | 52 ++++++++----------- 7 files changed, 90 insertions(+), 100 deletions(-) diff --git a/src/Webpay/Oneclick/Responses/InscriptionDeleteResponse.php b/src/Webpay/Oneclick/Responses/InscriptionDeleteResponse.php index 629349dd..a450a83f 100644 --- a/src/Webpay/Oneclick/Responses/InscriptionDeleteResponse.php +++ b/src/Webpay/Oneclick/Responses/InscriptionDeleteResponse.php @@ -4,24 +4,24 @@ class InscriptionDeleteResponse { - public $success = false; - public $code; + public bool $success = false; + public ?int $code; - public function __construct($success, $httpCode = null) + public function __construct(bool $success, ?int $httpCode = null) { $this->success = $success; $this->code = $httpCode; } - public function wasSuccessfull() + public function wasSuccessfull(): bool { return $this->success === true; } /** - * @return mixed|null + * @return ?int */ - public function getCode() + public function getCode(): ?int { return $this->code; } diff --git a/src/Webpay/Oneclick/Responses/InscriptionFinishResponse.php b/src/Webpay/Oneclick/Responses/InscriptionFinishResponse.php index ec4f21fb..c33131f8 100644 --- a/src/Webpay/Oneclick/Responses/InscriptionFinishResponse.php +++ b/src/Webpay/Oneclick/Responses/InscriptionFinishResponse.php @@ -7,13 +7,13 @@ class InscriptionFinishResponse { - public $responseCode; - public $tbkUser; - public $authorizationCode; - public $cardType; - public $cardNumber; + public int $responseCode; + public string $tbkUser; + public string $authorizationCode; + public string $cardType; + public string $cardNumber; - public function __construct($json) + public function __construct(array $json) { $this->responseCode = Utils::returnValueIfExists($json, 'response_code'); $this->tbkUser = Utils::returnValueIfExists($json, 'tbk_user'); @@ -22,49 +22,48 @@ public function __construct($json) $this->cardNumber = Utils::returnValueIfExists($json, 'card_number'); } - public function isApproved() + public function isApproved(): bool { return $this->getResponseCode() === ResponseCodesEnum::RESPONSE_CODE_APPROVED; } /** - * @return mixed + * @return int */ - public function getResponseCode() + public function getResponseCode(): int { - return (int) $this->responseCode; + return $this->responseCode; } /** - * @return mixed + * @return string */ - public function getTbkUser() + public function getTbkUser(): string { return $this->tbkUser; } /** - * @return mixed + * @return string */ - public function getAuthorizationCode() + public function getAuthorizationCode(): string { return $this->authorizationCode; } /** - * @return mixed + * @return string */ - public function getCardType() + public function getCardType(): string { return $this->cardType; } /** - * @return mixed + * @return string */ - public function getCardNumber() + public function getCardNumber(): string { return $this->cardNumber; } - } diff --git a/src/Webpay/Oneclick/Responses/InscriptionStartResponse.php b/src/Webpay/Oneclick/Responses/InscriptionStartResponse.php index 221dfa22..ac562ecc 100644 --- a/src/Webpay/Oneclick/Responses/InscriptionStartResponse.php +++ b/src/Webpay/Oneclick/Responses/InscriptionStartResponse.php @@ -6,34 +6,33 @@ class InscriptionStartResponse { - public $token; - public $urlWebpay; + public string $token; + public string $urlWebpay; - public function __construct($json) + public function __construct(array $json) { $this->token = Utils::returnValueIfExists($json, 'token'); $this->urlWebpay = Utils::returnValueIfExists($json, 'url_webpay'); } - public function getRedirectUrl() + public function getRedirectUrl(): string { - return $this->getUrlWebpay().'?TBK_TOKEN='.$this->getToken(); + return $this->getUrlWebpay() . '?TBK_TOKEN=' . $this->getToken(); } /** - * @return mixed + * @return string */ - public function getToken() + public function getToken(): string { return $this->token; } /** - * @return mixed + * @return string */ - public function getUrlWebpay() + public function getUrlWebpay(): string { return $this->urlWebpay; } - } diff --git a/src/Webpay/Oneclick/Responses/MallTransactionAuthorizeResponse.php b/src/Webpay/Oneclick/Responses/MallTransactionAuthorizeResponse.php index a361a206..e28cfd36 100644 --- a/src/Webpay/Oneclick/Responses/MallTransactionAuthorizeResponse.php +++ b/src/Webpay/Oneclick/Responses/MallTransactionAuthorizeResponse.php @@ -4,11 +4,11 @@ class MallTransactionAuthorizeResponse extends MallTransactionStatusResponse { - public function __construct($json) - { - parent::__construct($json); - foreach ($this->details as $index => $detail) { - unset($this->details[$index]->balance); - } + public function __construct(array $json) + { + parent::__construct($json); + foreach ($this->details as &$detail) { + unset($detail->balance); } + } } diff --git a/src/Webpay/Oneclick/Responses/MallTransactionCaptureResponse.php b/src/Webpay/Oneclick/Responses/MallTransactionCaptureResponse.php index ea2e5f35..38a251f5 100644 --- a/src/Webpay/Oneclick/Responses/MallTransactionCaptureResponse.php +++ b/src/Webpay/Oneclick/Responses/MallTransactionCaptureResponse.php @@ -6,12 +6,12 @@ class MallTransactionCaptureResponse { - public $authorizationCode; - public $authorizationDate; - public $capturedAmount; - public $responseCode; + public ?string $authorizationCode; + public ?string $authorizationDate; + public ?float $capturedAmount; + public ?int $responseCode; - public function __construct($json) + public function __construct(array $json) { $this->authorizationCode = Utils::returnValueIfExists($json, 'authorization_code'); $this->authorizationDate = Utils::returnValueIfExists($json, 'authorization_date'); @@ -19,24 +19,23 @@ public function __construct($json) $this->responseCode = Utils::returnValueIfExists($json, 'response_code'); } - public function getAuthorizationCode() + public function getAuthorizationCode(): ?string { return $this->authorizationCode; } - public function getAuthorizationDate() + public function getAuthorizationDate(): ?string { return $this->authorizationDate; } - public function getCapturedAmount() + public function getCapturedAmount(): ?float { return $this->capturedAmount; } - public function getResponseCode() + public function getResponseCode(): ?int { return $this->responseCode; } - } diff --git a/src/Webpay/Oneclick/Responses/MallTransactionRefundResponse.php b/src/Webpay/Oneclick/Responses/MallTransactionRefundResponse.php index 7c6ccef3..a59e8d68 100644 --- a/src/Webpay/Oneclick/Responses/MallTransactionRefundResponse.php +++ b/src/Webpay/Oneclick/Responses/MallTransactionRefundResponse.php @@ -6,14 +6,14 @@ class MallTransactionRefundResponse { - public $type; - public $authorizationCode; - public $authorizationDate; - public $nullifiedAmount; - public $balance; - public $responseCode; + public string $type; + public ?string $authorizationCode; + public ?string $authorizationDate; + public ?float $nullifiedAmount; + public ?float $balance; + public ?int $responseCode; - public function __construct($json) + public function __construct(array $json) { $this->type = Utils::returnValueIfExists($json, 'type'); $this->authorizationCode = Utils::returnValueIfExists($json, 'authorization_code'); @@ -24,51 +24,50 @@ public function __construct($json) } /** - * @return mixed + * @return string */ - public function getType() + public function getType(): string { return $this->type; } /** - * @return mixed + * @return ?string */ - public function getAuthorizationCode() + public function getAuthorizationCode(): ?string { return $this->authorizationCode; } /** - * @return mixed + * @return ?string */ - public function getAuthorizationDate() + public function getAuthorizationDate(): ?string { return $this->authorizationDate; } /** - * @return mixed + * @return ?float */ - public function getNullifiedAmount() + public function getNullifiedAmount(): ?float { return $this->nullifiedAmount; } /** - * @return mixed + * @return ?float */ - public function getBalance() + public function getBalance(): ?float { return $this->balance; } /** - * @return mixed + * @return ?int */ - public function getResponseCode() + public function getResponseCode(): ?int { return $this->responseCode; } - } diff --git a/src/Webpay/Oneclick/Responses/MallTransactionStatusResponse.php b/src/Webpay/Oneclick/Responses/MallTransactionStatusResponse.php index 07010ce3..954c510e 100644 --- a/src/Webpay/Oneclick/Responses/MallTransactionStatusResponse.php +++ b/src/Webpay/Oneclick/Responses/MallTransactionStatusResponse.php @@ -6,32 +6,27 @@ class MallTransactionStatusResponse { - public $buyOrder; - public $cardNumber; - public $accountingDate; - public $transactionDate; + public string $buyOrder; + public array $cardDetail; + public string $cardNumber; + public string $accountingDate; + public string $transactionDate; + public array $details; - /** - * @var TransactionDetail[] - */ - public $details; - - public function __construct($json) + public function __construct(array $json) { $this->buyOrder = Utils::returnValueIfExists($json, 'buy_order'); $this->accountingDate = Utils::returnValueIfExists($json, 'accounting_date'); $this->transactionDate = Utils::returnValueIfExists($json, 'transaction_date'); - $cardDetail = Utils::returnValueIfExists($json, 'card_detail'); - $this->cardNumber = Utils::returnValueIfExists($cardDetail, 'card_number'); + $this->cardDetail = Utils::returnValueIfExists($json, 'card_detail'); + $this->cardNumber = Utils::returnValueIfExists($this->cardDetail, 'card_number'); - $details = Utils::returnValueIfExists($json, 'details'); - $detailsObjectArray = []; - if (is_array($details)) { - foreach ($details as $detail) { - $detailsObjectArray[] = TransactionDetail::createFromArray($detail); + $this->details = []; + if (is_array($json['details'])) { + foreach ($json['details'] as $detail) { + $this->details[] = TransactionDetail::createFromArray($detail); } } - $this->details = $detailsObjectArray; } /** @@ -39,7 +34,7 @@ public function __construct($json) * * @return bool */ - public function isApproved() + public function isApproved(): bool { if (!$details = $this->getDetails()) { return false; @@ -55,25 +50,25 @@ public function isApproved() } /** - * @return mixed + * @return ?string */ - public function getTransactionDate() + public function getTransactionDate(): ?string { return $this->transactionDate; } /** - * @return mixed + * @return string */ - public function getCardNumber() + public function getCardNumber(): string { return $this->cardNumber; } /** - * @return mixed + * @return string */ - public function getAccountingDate() + public function getAccountingDate(): string { return $this->accountingDate; } @@ -81,17 +76,16 @@ public function getAccountingDate() /** * @return TransactionDetail[] */ - public function getDetails() + public function getDetails(): array { return $this->details; } /** - * @return mixed + * @return string */ - public function getBuyOrder() + public function getBuyOrder(): string { return $this->buyOrder; } - } From 0b5d995b8d833fd60b21b859d886253800a86d66 Mon Sep 17 00:00:00 2001 From: Fernando Date: Mon, 1 Jul 2024 09:27:28 -0400 Subject: [PATCH 14/51] refactor: add type in transaccion completa files --- .../TransaccionCompleta/MallTransaction.php | 130 +++++++++++++----- .../TransaccionCompleta/Transaction.php | 112 ++++++++------- 2 files changed, 154 insertions(+), 88 deletions(-) diff --git a/src/Webpay/TransaccionCompleta/MallTransaction.php b/src/Webpay/TransaccionCompleta/MallTransaction.php index ad5a8736..c63ac8aa 100644 --- a/src/Webpay/TransaccionCompleta/MallTransaction.php +++ b/src/Webpay/TransaccionCompleta/MallTransaction.php @@ -19,9 +19,10 @@ use Transbank\Webpay\TransaccionCompleta\Responses\MallTransactionInstallmentsResponse; use Transbank\Webpay\TransaccionCompleta\Responses\MallTransactionRefundResponse; use Transbank\Webpay\TransaccionCompleta\Responses\MallTransactionStatusResponse; +use Transbank\Webpay\TransaccionCompleta\Responses\MallTransactionCaptureResponse; use Transbank\Utils\InteractsWithWebpayApi; +use GuzzleHttp\Exception\GuzzleException; use Transbank\Webpay\Exceptions\WebpayRequestException; -use Transbank\Webpay\Options; class MallTransaction { @@ -33,14 +34,27 @@ class MallTransaction const ENDPOINT_REFUND = 'rswebpaytransaction/api/webpay/v1.2/transactions/{token}/refunds'; const ENDPOINT_STATUS = 'rswebpaytransaction/api/webpay/v1.2/transactions/{token}'; const ENDPOINT_CAPTURE = 'rswebpaytransaction/api/webpay/v1.2/transactions/{token}/capture'; + const SEARCH_STRING = '{token}'; + /** + * @param string $buyOrder + * @param string $sessionId + * @param string $cardNumber + * @param string $cardExpirationDate + * @param array $details + * @param ?string $cvv + * + * @throws MallTransactionCreateException + * + * @return MallTransactionCreateResponse + */ public function create( - $buyOrder, - $sessionId, - $cardNumber, - $cardExpirationDate, - $details, - $cvv = null + string $buyOrder, + string $sessionId, + string $cardNumber, + string $cardExpirationDate, + array $details, + ?string $cvv = null ) { $payload = [ 'buy_order' => $buyOrder, @@ -56,7 +70,8 @@ public function create( try { $response = $this->sendRequest('POST', static::ENDPOINT_CREATE, $payload); } catch (WebpayRequestException $exception) { - throw new MallTransactionCreateException($exception->getMessage(), + throw new MallTransactionCreateException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), @@ -67,11 +82,19 @@ public function create( return new MallTransactionCreateResponse($response); } + /** + * @param string $token + * @param array $details + * + * @throws TransactionInstallmentsException + * + * @return MallTransactionInstallmentsResponse[] + */ public function installments( - $token, - $details + string $token, + array $details ) { - $endpoint = str_replace('{token}', $token, static::ENDPOINT_INSTALLMENTS); + $endpoint = str_replace(self::SEARCH_STRING, $token, static::ENDPOINT_INSTALLMENTS); try { return array_map(function ($detail) use ($endpoint) { @@ -85,7 +108,8 @@ public function installments( return new MallTransactionInstallmentsResponse($response); }, $details); } catch (WebpayRequestException $exception) { - throw new TransactionInstallmentsException($exception->getMessage(), + throw new TransactionInstallmentsException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), @@ -94,6 +118,14 @@ public function installments( } } + /** + * @param string $token + * @param array $details + * + * @throws MallTransactionCommitException + * + * @return MallTransactionCommitResponse + */ public function commit( $token, $details @@ -102,12 +134,13 @@ public function commit( 'details' => $details, ]; - $endpoint = str_replace('{token}', $token, static::ENDPOINT_COMMIT); + $endpoint = str_replace(self::SEARCH_STRING, $token, static::ENDPOINT_COMMIT); try { $response = $this->sendRequest('PUT', $endpoint, $payload); } catch (WebpayRequestException $exception) { - throw new MallTransactionCommitException($exception->getMessage(), + throw new MallTransactionCommitException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), @@ -118,11 +151,21 @@ public function commit( return new MallTransactionCommitResponse($response); } + /** + * @param string $token + * @param string $buyOrder + * @param string $commerceCodeChild + * @param float $amount + * + * @throws MallTransactionRefundException + * + * @return MallTransactionRefundResponse + */ public function refund( - $token, - $buyOrder, - $commerceCodeChild, - $amount + string $token, + string $buyOrder, + string $commerceCodeChild, + float $amount ) { $payload = [ 'buy_order' => $buyOrder, @@ -130,12 +173,13 @@ public function refund( 'amount' => $amount, ]; - $endpoint = str_replace('{token}', $token, static::ENDPOINT_REFUND); + $endpoint = str_replace(self::SEARCH_STRING, $token, static::ENDPOINT_REFUND); try { $response = $this->sendRequest('POST', $endpoint, $payload); } catch (WebpayRequestException $exception) { - throw new MallTransactionRefundException($exception->getMessage(), + throw new MallTransactionRefundException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), @@ -146,14 +190,22 @@ public function refund( return new MallTransactionRefundResponse($response); } - public function status($token) + /** + * @param string $token + * + * @throws MallTransactionStatusException + * + * @return MallTransactionStatusResponse + */ + public function status(string $token) { - $endpoint = str_replace('{token}', $token, static::ENDPOINT_STATUS); + $endpoint = str_replace(self::SEARCH_STRING, $token, static::ENDPOINT_STATUS); try { - $response = $this->sendRequest('GET', $endpoint, null); + $response = $this->sendRequest('GET', $endpoint, []); } catch (WebpayRequestException $exception) { - throw new MallTransactionStatusException($exception->getMessage(), + throw new MallTransactionStatusException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), @@ -165,20 +217,25 @@ public function status($token) } /** - * @param $token - * @param $commerceCode - * @param $buyOrder - * @param $authorizationCode - * @param $captureAmount + * @param string $token + * @param string $commerceCode + * @param string $buyOrder + * @param string $authorizationCode + * @param float $captureAmount * * @throws MallTransactionCaptureException - * @throws \GuzzleHttp\Exception\GuzzleException + * @throws GuzzleException * - * @return Responses\MallTransactionCaptureResponse + * @return MallTransactionCaptureResponse */ - public function capture($token, $commerceCode, $buyOrder, $authorizationCode, $captureAmount) - { - $endpoint = str_replace('{token}', $token, static::ENDPOINT_CAPTURE); + public function capture( + string $token, + string $commerceCode, + string $buyOrder, + string $authorizationCode, + float $captureAmount + ) { + $endpoint = str_replace(self::SEARCH_STRING, $token, static::ENDPOINT_CAPTURE); $payload = [ 'buy_order' => $buyOrder, @@ -190,7 +247,8 @@ public function capture($token, $commerceCode, $buyOrder, $authorizationCode, $c try { $response = $this->sendRequest('PUT', $endpoint, $payload); } catch (WebpayRequestException $exception) { - throw new MallTransactionCaptureException($exception->getMessage(), + throw new MallTransactionCaptureException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), @@ -198,6 +256,6 @@ public function capture($token, $commerceCode, $buyOrder, $authorizationCode, $c ); } - return new Responses\MallTransactionCaptureResponse($response); + return new MallTransactionCaptureResponse($response); } } diff --git a/src/Webpay/TransaccionCompleta/Transaction.php b/src/Webpay/TransaccionCompleta/Transaction.php index ceabedc4..cd5c5c5f 100644 --- a/src/Webpay/TransaccionCompleta/Transaction.php +++ b/src/Webpay/TransaccionCompleta/Transaction.php @@ -16,6 +16,7 @@ use Transbank\Webpay\TransaccionCompleta\Responses\TransactionCaptureResponse; use Transbank\Utils\InteractsWithWebpayApi; use Transbank\Webpay\Exceptions\WebpayRequestException; +use GuzzleHttp\Exception\GuzzleException; /** * Class Transaction. @@ -30,27 +31,28 @@ class Transaction const ENDPOINT_REFUND = 'rswebpaytransaction/api/webpay/v1.2/transactions/{token}/refunds'; const ENDPOINT_STATUS = 'rswebpaytransaction/api/webpay/v1.2/transactions/{token}'; const ENDPOINT_CAPTURE = 'rswebpaytransaction/api/webpay/v1.2/transactions/{token}/capture'; + const SEARCH_STRING = '{token}'; /** - * @param $buyOrder - * @param $sessionId - * @param $amount - * @param $cvv - * @param $cardNumber - * @param $cardExpirationDate + * @param string $buyOrder + * @param string $sessionId + * @param float $amount + * @param string $cardNumber + * @param string $cardExpirationDate + * @param ?string $cvv * * @throws TransactionCreateException - * @throws \GuzzleHttp\Exception\GuzzleException + * @throws GuzzleException * * @return TransactionCreateResponse */ public function create( - $buyOrder, - $sessionId, - $amount, - $cvv, - $cardNumber, - $cardExpirationDate + string $buyOrder, + string $sessionId, + float $amount, + string $cardNumber, + string $cardExpirationDate, + ?string $cvv = null, ) { $payload = [ 'buy_order' => $buyOrder, @@ -64,9 +66,10 @@ public function create( try { $response = $this->sendRequest('POST', static::ENDPOINT_CREATE, $payload); } catch (WebpayRequestException $exception) { - throw new TransactionCreateException($exception->getMessage(), + throw new TransactionCreateException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), - $exception->getHttpCode(), + $exception->getHttpCode() ?? 0, $exception->getFailedRequest(), $exception ); @@ -76,28 +79,29 @@ public function create( } /** - * @param $token - * @param $installmentsNumber + * @param string $token + * @param int $installmentsNumber * * @throws TransactionInstallmentsException - * @throws \GuzzleHttp\Exception\GuzzleException + * @throws GuzzleException * * @return TransactionInstallmentsResponse */ public function installments( - $token, - $installmentsNumber + string $token, + int $installmentsNumber ) { $payload = [ 'installments_number' => $installmentsNumber, ]; - $endpoint = str_replace('{token}', $token, static::ENDPOINT_INSTALLMENTS); + $endpoint = str_replace(self::SEARCH_STRING, $token, static::ENDPOINT_INSTALLMENTS); try { $response = $this->sendRequest('POST', $endpoint, $payload); } catch (WebpayRequestException $exception) { - throw new TransactionInstallmentsException($exception->getMessage(), + throw new TransactionInstallmentsException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), @@ -109,21 +113,21 @@ public function installments( } /** - * @param $token - * @param $idQueryInstallments - * @param $deferredPeriodIndex - * @param $gracePeriod + * @param string $token + * @param ?int $idQueryInstallments + * @param ?int $deferredPeriodIndex + * @param ?bool $gracePeriod * * @throws TransactionCommitException - * @throws \GuzzleHttp\Exception\GuzzleException + * @throws GuzzleException * * @return TransactionCommitResponse */ public function commit( - $token, - $idQueryInstallments = null, - $deferredPeriodIndex = null, - $gracePeriod = null + string $token, + ?int $idQueryInstallments = null, + ?int $deferredPeriodIndex = null, + ?bool $gracePeriod = null ) { $payload = [ 'id_query_installments' => $idQueryInstallments, @@ -131,12 +135,13 @@ public function commit( 'grace_period' => $gracePeriod, ]; - $endpoint = str_replace('{token}', $token, static::ENDPOINT_COMMIT); + $endpoint = str_replace(self::SEARCH_STRING, $token, static::ENDPOINT_COMMIT); try { $response = $this->sendRequest('PUT', $endpoint, $payload); } catch (WebpayRequestException $exception) { - throw new TransactionCommitException($exception->getMessage(), + throw new TransactionCommitException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), @@ -148,26 +153,27 @@ public function commit( } /** - * @param $token - * @param $amount + * @param string $token + * @param float $amount * * @throws TransactionRefundException - * @throws \GuzzleHttp\Exception\GuzzleException + * @throws GuzzleException * * @return TransactionRefundResponse */ - public function refund($token, $amount) + public function refund(string $token, float $amount) { $payload = [ 'amount' => $amount, ]; - $endpoint = str_replace('{token}', $token, static::ENDPOINT_REFUND); + $endpoint = str_replace(self::SEARCH_STRING, $token, static::ENDPOINT_REFUND); try { $response = $this->sendRequest('POST', $endpoint, $payload); } catch (WebpayRequestException $exception) { - throw new TransactionRefundException($exception->getMessage(), + throw new TransactionRefundException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), @@ -179,21 +185,22 @@ public function refund($token, $amount) } /** - * @param $token + * @param string $token * * @throws TransactionStatusException - * @throws \GuzzleHttp\Exception\GuzzleException + * @throws GuzzleException * * @return TransactionStatusResponse */ public function status($token) { - $endpoint = str_replace('{token}', $token, static::ENDPOINT_STATUS); + $endpoint = str_replace(self::SEARCH_STRING, $token, static::ENDPOINT_STATUS); try { - $response = $this->sendRequest('GET', $endpoint, null); + $response = $this->sendRequest('GET', $endpoint, []); } catch (WebpayRequestException $exception) { - throw new TransactionStatusException($exception->getMessage(), + throw new TransactionStatusException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), @@ -205,19 +212,19 @@ public function status($token) } /** - * @param $token - * @param $buyOrder - * @param $authorizationCode - * @param $captureAmount + * @param string $token + * @param string $buyOrder + * @param string $authorizationCode + * @param float $captureAmount * * @throws TransactionCaptureException - * @throws \GuzzleHttp\Exception\GuzzleException + * @throws GuzzleException * * @return TransactionCaptureResponse */ - public function capture($token, $buyOrder, $authorizationCode, $captureAmount) + public function capture(string $token, string $buyOrder, string $authorizationCode, float $captureAmount) { - $endpoint = str_replace('{token}', $token, static::ENDPOINT_CAPTURE); + $endpoint = str_replace(self::SEARCH_STRING, $token, static::ENDPOINT_CAPTURE); $payload = [ 'buy_order' => $buyOrder, @@ -228,7 +235,8 @@ public function capture($token, $buyOrder, $authorizationCode, $captureAmount) try { $response = $this->sendRequest('PUT', $endpoint, $payload); } catch (WebpayRequestException $exception) { - throw new TransactionCaptureException($exception->getMessage(), + throw new TransactionCaptureException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), From cfa576c3eecf2eb25eee254ad7e40d0e8568fcf4 Mon Sep 17 00:00:00 2001 From: Fernando Date: Mon, 1 Jul 2024 09:27:45 -0400 Subject: [PATCH 15/51] refactor: add type in transaccion completa responses files --- .../MallTransactionCommitResponse.php | 12 ++--- .../MallTransactionCreateResponse.php | 9 ++-- .../MallTransactionInstallmentsResponse.php | 21 ++++---- .../MallTransactionRefundResponse.php | 39 ++++++++------- .../MallTransactionStatusResponse.php | 48 +++++++++---------- .../Responses/TransactionCommitResponse.php | 2 +- .../Responses/TransactionCreateResponse.php | 9 ++-- .../Responses/TransactionDetail.php | 14 ++++-- .../TransactionInstallmentsResponse.php | 21 ++++---- .../Responses/TransactionRefundResponse.php | 41 ++++++++-------- .../Responses/TransactionStatusResponse.php | 17 ++++--- 11 files changed, 115 insertions(+), 118 deletions(-) diff --git a/src/Webpay/TransaccionCompleta/Responses/MallTransactionCommitResponse.php b/src/Webpay/TransaccionCompleta/Responses/MallTransactionCommitResponse.php index ff046141..2073cc02 100644 --- a/src/Webpay/TransaccionCompleta/Responses/MallTransactionCommitResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/MallTransactionCommitResponse.php @@ -4,11 +4,11 @@ class MallTransactionCommitResponse extends MallTransactionStatusResponse { - public function __construct($json) - { - parent::__construct($json); - foreach ($this->details as $index => $detail) { - unset($this->details[$index]->balance); - } + public function __construct(array $json) + { + parent::__construct($json); + foreach ($this->details as &$detail) { + unset($detail->balance); } + } } diff --git a/src/Webpay/TransaccionCompleta/Responses/MallTransactionCreateResponse.php b/src/Webpay/TransaccionCompleta/Responses/MallTransactionCreateResponse.php index eee96b54..4767aa65 100644 --- a/src/Webpay/TransaccionCompleta/Responses/MallTransactionCreateResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/MallTransactionCreateResponse.php @@ -6,19 +6,18 @@ class MallTransactionCreateResponse { - public $token; + public string $token; - public function __construct($json) + public function __construct(array $json) { $this->token = Utils::returnValueIfExists($json, 'token'); } /** - * @return mixed + * @return ?string */ - public function getToken() + public function getToken(): ?string { return $this->token; } - } diff --git a/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php b/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php index 4750488a..563ff331 100644 --- a/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php @@ -6,11 +6,11 @@ class MallTransactionInstallmentsResponse { - public $installmentsAmount; - public $idQueryInstallments; - public $deferredPeriods; + public float $installmentsAmount; + public string $idQueryInstallments; + public array $deferredPeriods; - public function __construct($json) + public function __construct(array $json) { $this->installmentsAmount = Utils::returnValueIfExists($json, 'installments_amount'); $this->idQueryInstallments = Utils::returnValueIfExists($json, 'id_query_installments'); @@ -18,27 +18,26 @@ public function __construct($json) } /** - * @return mixed + * @return float */ - public function getInstallmentsAmount() + public function getInstallmentsAmount(): float { return $this->installmentsAmount; } /** - * @return mixed + * @return string */ - public function getIdQueryInstallments() + public function getIdQueryInstallments(): string { return $this->idQueryInstallments; } /** - * @return mixed + * @return array */ - public function getDeferredPeriods() + public function getDeferredPeriods(): array { return $this->deferredPeriods; } - } diff --git a/src/Webpay/TransaccionCompleta/Responses/MallTransactionRefundResponse.php b/src/Webpay/TransaccionCompleta/Responses/MallTransactionRefundResponse.php index 6f719e42..1ae9f210 100644 --- a/src/Webpay/TransaccionCompleta/Responses/MallTransactionRefundResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/MallTransactionRefundResponse.php @@ -6,14 +6,14 @@ class MallTransactionRefundResponse { - public $type; - public $authorizationCode; - public $authorizationDate; - public $nullifiedAmount; - public $balance; - public $responseCode; + public string $type; + public ?string $authorizationCode; + public ?string $authorizationDate; + public ?float $nullifiedAmount; + public ?float $balance; + public int $responseCode; - public function __construct($json) + public function __construct(array $json) { $this->type = Utils::returnValueIfExists($json, 'type'); $this->authorizationCode = Utils::returnValueIfExists($json, 'authorization_code'); @@ -24,51 +24,50 @@ public function __construct($json) } /** - * @return mixed + * @return string */ - public function getType() + public function getType(): string { return $this->type; } /** - * @return mixed + * @return ?string */ - public function getAuthorizationCode() + public function getAuthorizationCode(): ?string { return $this->authorizationCode; } /** - * @return mixed + * @return ?string */ - public function getAuthorizationDate() + public function getAuthorizationDate(): ?string { return $this->authorizationDate; } /** - * @return mixed + * @return ?float */ - public function getNullifiedAmount() + public function getNullifiedAmount(): ?float { return $this->nullifiedAmount; } /** - * @return mixed + * @return ?float */ - public function getBalance() + public function getBalance(): ?float { return $this->balance; } /** - * @return mixed + * @return int */ - public function getResponseCode() + public function getResponseCode(): int { return (int) $this->responseCode; } - } diff --git a/src/Webpay/TransaccionCompleta/Responses/MallTransactionStatusResponse.php b/src/Webpay/TransaccionCompleta/Responses/MallTransactionStatusResponse.php index 73dd2eab..5b20be91 100644 --- a/src/Webpay/TransaccionCompleta/Responses/MallTransactionStatusResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/MallTransactionStatusResponse.php @@ -6,75 +6,73 @@ class MallTransactionStatusResponse { - protected $buyOrder; - protected $cardDetail; - protected $cardNumber; - protected $accountingDate; - protected $transactionDate; - protected $details; + protected string $buyOrder; + protected array $cardDetail; + protected string $cardNumber; + protected string $accountingDate; + protected string $transactionDate; + protected array $details; - public function __construct($json) + public function __construct(array $json) { - $this->buyOrder = Utils::returnValueIfExists($json, 'buyOrder'); + $this->buyOrder = Utils::returnValueIfExists($json, 'buy_order'); $this->accountingDate = Utils::returnValueIfExists($json, 'accounting_date'); $this->transactionDate = Utils::returnValueIfExists($json, 'transaction_date'); $this->cardDetail = Utils::returnValueIfExists($json, 'card_detail'); $this->cardNumber = Utils::returnValueIfExists($this->cardDetail, 'card_number'); - $details = Utils::returnValueIfExists($json, 'details'); - $this->details = null; - if (is_array($details)) { - $this->details = []; - foreach ($details as $detail) { + $this->details = []; + if (is_array($json['details'])) { + foreach ($json['details'] as $detail) { $this->details[] = TransactionDetail::createFromArray($detail); } } } /** - * @return mixed + * @return string */ - public function getBuyOrder() + public function getBuyOrder(): string { return $this->buyOrder; } /** - * @return mixed + * @return array */ - public function getCardDetail() + public function getCardDetail(): array { return $this->cardDetail; } /** - * @return mixed + * @return string */ - public function getAccountingDate() + public function getAccountingDate(): string { return $this->accountingDate; } /** - * @return mixed + * @return string */ - public function getTransactionDate() + public function getTransactionDate(): string { return $this->transactionDate; } /** - * @return mixed + * @return array */ - public function getDetails() + public function getDetails(): array { return $this->details; } /** - * @return mixed|null + * @return string */ - public function getCardNumber() + public function getCardNumber(): string { return $this->cardNumber; } diff --git a/src/Webpay/TransaccionCompleta/Responses/TransactionCommitResponse.php b/src/Webpay/TransaccionCompleta/Responses/TransactionCommitResponse.php index ad5fe876..ef4c4a41 100644 --- a/src/Webpay/TransaccionCompleta/Responses/TransactionCommitResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/TransactionCommitResponse.php @@ -4,7 +4,7 @@ class TransactionCommitResponse extends TransactionStatusResponse { - public function __construct($json) + public function __construct(array $json) { parent::__construct($json); unset($this->balance); diff --git a/src/Webpay/TransaccionCompleta/Responses/TransactionCreateResponse.php b/src/Webpay/TransaccionCompleta/Responses/TransactionCreateResponse.php index d7332afa..c17b0a44 100644 --- a/src/Webpay/TransaccionCompleta/Responses/TransactionCreateResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/TransactionCreateResponse.php @@ -6,19 +6,18 @@ class TransactionCreateResponse { - public $token; + public string $token; - public function __construct($json) + public function __construct(array $json) { $this->token = Utils::returnValueIfExists($json, 'token'); } /** - * @return mixed + * @return string */ - public function getToken() + public function getToken(): string { return $this->token; } - } diff --git a/src/Webpay/TransaccionCompleta/Responses/TransactionDetail.php b/src/Webpay/TransaccionCompleta/Responses/TransactionDetail.php index 9ee50059..9ae3f3e6 100644 --- a/src/Webpay/TransaccionCompleta/Responses/TransactionDetail.php +++ b/src/Webpay/TransaccionCompleta/Responses/TransactionDetail.php @@ -7,8 +7,15 @@ class TransactionDetail extends BaseTransactionDetail { - public $prepaidBalance; + public ?int $prepaidBalance; + /** + * Creates an instance of TransactionDetail from an array + * + * @param array $array + * + * @return TransactionDetail + */ public static function createFromArray(array $array) { $result = new TransactionDetail(); @@ -28,11 +35,10 @@ public static function createFromArray(array $array) } /** - * @return mixed + * @return ?int */ - public function getPrepaidBalance() + public function getPrepaidBalance(): ?int { return $this->prepaidBalance; } - } diff --git a/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php b/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php index 3894b3ea..488c20f4 100644 --- a/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php @@ -6,11 +6,11 @@ class TransactionInstallmentsResponse { - public $installmentsAmount; - public $idQueryInstallments; - public $deferredPeriods; + public float $installmentsAmount; + public string $idQueryInstallments; + public array $deferredPeriods; - public function __construct($json) + public function __construct(array $json) { $this->installmentsAmount = Utils::returnValueIfExists($json, 'installments_amount'); $this->idQueryInstallments = Utils::returnValueIfExists($json, 'id_query_installments'); @@ -18,27 +18,26 @@ public function __construct($json) } /** - * @return mixed + * @return float */ - public function getInstallmentsAmount() + public function getInstallmentsAmount(): float { return $this->installmentsAmount; } /** - * @return mixed + * @return string */ - public function getIdQueryInstallments() + public function getIdQueryInstallments(): string { return $this->idQueryInstallments; } /** - * @return mixed + * @return array */ - public function getDeferredPeriods() + public function getDeferredPeriods(): array { return $this->deferredPeriods; } - } diff --git a/src/Webpay/TransaccionCompleta/Responses/TransactionRefundResponse.php b/src/Webpay/TransaccionCompleta/Responses/TransactionRefundResponse.php index e263dbfb..18d34cff 100644 --- a/src/Webpay/TransaccionCompleta/Responses/TransactionRefundResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/TransactionRefundResponse.php @@ -6,14 +6,14 @@ class TransactionRefundResponse { - public $type; - public $authorizationCode; - public $authorizationDate; - public $nullifiedAmount; - public $balance; - public $responseCode; + public string $type; + public ?string $authorizationCode; + public ?string $authorizationDate; + public ?float $nullifiedAmount; + public ?float $balance; + public ?int $responseCode; - public function __construct($json) + public function __construct(array $json) { $this->type = Utils::returnValueIfExists($json, 'type'); $this->authorizationCode = Utils::returnValueIfExists($json, 'authorization_code'); @@ -24,51 +24,50 @@ public function __construct($json) } /** - * @return mixed + * @return string */ - public function getType() + public function getType(): string { return $this->type; } /** - * @return mixed + * @return ?string */ - public function getAuthorizationCode() + public function getAuthorizationCode(): ?string { return $this->authorizationCode; } /** - * @return mixed + * @return ?string */ - public function getAuthorizationDate() + public function getAuthorizationDate(): ?string { return $this->authorizationDate; } /** - * @return mixed + * @return ?float */ - public function getNullifiedAmount() + public function getNullifiedAmount(): ?float { return $this->nullifiedAmount; } /** - * @return mixed + * @return ?float */ - public function getBalance() + public function getBalance(): ?float { return $this->balance; } /** - * @return mixed + * @return ?int */ - public function getResponseCode() + public function getResponseCode(): ?int { - return (int) $this->responseCode; + return $this->responseCode; } - } diff --git a/src/Webpay/TransaccionCompleta/Responses/TransactionStatusResponse.php b/src/Webpay/TransaccionCompleta/Responses/TransactionStatusResponse.php index 2661ba5d..904d1594 100644 --- a/src/Webpay/TransaccionCompleta/Responses/TransactionStatusResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/TransactionStatusResponse.php @@ -9,10 +9,10 @@ class TransactionStatusResponse { use HasTransactionStatus; - public $vci; - public $prepaidBalance; + public ?string $vci; + public ?float $prepaidBalance; - public function __construct($json) + public function __construct(array $json) { $this->vci = Utils::returnValueIfExists($json, 'vci'); $this->setTransactionStatusFields($json); @@ -20,19 +20,18 @@ public function __construct($json) } /** - * @return mixed + * @return ?string */ - public function getVci() + public function getVci(): ?string { return $this->vci; } - /** - * @return mixed + /** + * @return ?float */ - public function getPrepaidBalance() + public function getPrepaidBalance(): ?float { return $this->prepaidBalance; } - } From d40fb2e24ce81728e3044525224057327b72883b Mon Sep 17 00:00:00 2001 From: Fernando Date: Mon, 1 Jul 2024 09:27:55 -0400 Subject: [PATCH 16/51] refactor: add type in webpay plus files --- src/Webpay/WebpayPlus/MallTransaction.php | 87 +++++++++++---------- src/Webpay/WebpayPlus/Transaction.php | 92 ++++++++++++++--------- 2 files changed, 103 insertions(+), 76 deletions(-) diff --git a/src/Webpay/WebpayPlus/MallTransaction.php b/src/Webpay/WebpayPlus/MallTransaction.php index acccfee5..abac3657 100644 --- a/src/Webpay/WebpayPlus/MallTransaction.php +++ b/src/Webpay/WebpayPlus/MallTransaction.php @@ -16,6 +16,7 @@ use Transbank\Webpay\WebpayPlus\Responses\MallTransactionCreateResponse; use Transbank\Webpay\WebpayPlus\Responses\MallTransactionRefundResponse; use Transbank\Webpay\WebpayPlus\Responses\MallTransactionStatusResponse; +use GuzzleHttp\Exception\GuzzleException; class MallTransaction { @@ -26,19 +27,20 @@ class MallTransaction const ENDPOINT_REFUND = 'rswebpaytransaction/api/webpay/v1.2/transactions/{token}/refunds'; const ENDPOINT_STATUS = 'rswebpaytransaction/api/webpay/v1.2/transactions/{token}'; const ENDPOINT_CAPTURE = 'rswebpaytransaction/api/webpay/v1.2/transactions/{token}/capture'; + const SEARCH_STRING = '{token}'; /** - * @param $buyOrder - * @param $sessionId - * @param $returnUrl - * @param $details + * @param string $buyOrder + * @param string $sessionId + * @param string $returnUrl + * @param array $details * * @throws MallTransactionCreateException - * @throws \GuzzleHttp\Exception\GuzzleException + * @throws GuzzleException * * @return MallTransactionCreateResponse */ - public function create($buyOrder, $sessionId, $returnUrl, $details) + public function create(string $buyOrder, string $sessionId, string $returnUrl, array $details) { $payload = [ 'buy_order' => $buyOrder, @@ -54,7 +56,8 @@ public function create($buyOrder, $sessionId, $returnUrl, $details) $payload ); } catch (WebpayRequestException $exception) { - throw new MallTransactionCreateException($exception->getMessage(), + throw new MallTransactionCreateException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), @@ -66,14 +69,14 @@ public function create($buyOrder, $sessionId, $returnUrl, $details) } /** - * @param $token + * @param string $token * * @throws MallTransactionCommitException - * @throws \GuzzleHttp\Exception\GuzzleException + * @throws GuzzleException * * @return MallTransactionCommitResponse */ - public function commit($token) + public function commit(string $token) { if (!is_string($token)) { throw new \InvalidArgumentException('Token parameter given is not string.'); @@ -85,11 +88,12 @@ public function commit($token) try { $response = $this->sendRequest( 'PUT', - str_replace('{token}', $token, static::ENDPOINT_COMMIT), - null + str_replace(self::SEARCH_STRING, $token, static::ENDPOINT_COMMIT), + [] ); } catch (WebpayRequestException $exception) { - throw new MallTransactionCommitException($exception->getMessage(), + throw new MallTransactionCommitException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), @@ -101,17 +105,17 @@ public function commit($token) } /** - * @param $token - * @param $buyOrder - * @param $childCommerceCode - * @param $amount + * @param string $token + * @param string $buyOrder + * @param string $childCommerceCode + * @param float $amount * * @throws MallTransactionRefundException - * @throws \GuzzleHttp\Exception\GuzzleException + * @throws GuzzleException * * @return MallTransactionRefundResponse */ - public function refund($token, $buyOrder, $childCommerceCode, $amount) + public function refund(string $token, string $buyOrder, string $childCommerceCode, float $amount) { $payload = [ 'buy_order' => $buyOrder, @@ -122,11 +126,12 @@ public function refund($token, $buyOrder, $childCommerceCode, $amount) try { $response = $this->sendRequest( 'POST', - str_replace('{token}', $token, static::ENDPOINT_REFUND), + str_replace(self::SEARCH_STRING, $token, static::ENDPOINT_REFUND), $payload ); } catch (WebpayRequestException $exception) { - throw new MallTransactionRefundException($exception->getMessage(), + throw new MallTransactionRefundException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), @@ -138,23 +143,24 @@ public function refund($token, $buyOrder, $childCommerceCode, $amount) } /** - * @param $token + * @param string $token * * @throws MallTransactionStatusException - * @throws \GuzzleHttp\Exception\GuzzleException + * @throws GuzzleException * * @return MallTransactionStatusResponse */ - public function status($token) + public function status(string $token) { try { $response = $this->sendRequest( 'GET', - str_replace('{token}', $token, static::ENDPOINT_STATUS), - null + str_replace(self::SEARCH_STRING, $token, static::ENDPOINT_STATUS), + [] ); } catch (WebpayRequestException $exception) { - throw new MallTransactionStatusException($exception->getMessage(), + throw new MallTransactionStatusException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), @@ -166,23 +172,23 @@ public function status($token) } /** - * @param $childCommerceCode - * @param $token - * @param $buyOrder - * @param $authorizationCode - * @param null $captureAmount + * @param string $childCommerceCode + * @param string $token + * @param string $buyOrder + * @param string $authorizationCode + * @param float $captureAmount * * @throws MallTransactionCaptureException - * @throws \GuzzleHttp\Exception\GuzzleException + * @throws GuzzleException * * @return MallTransactionCaptureResponse */ public function capture( - $childCommerceCode, - $token, - $buyOrder, - $authorizationCode, - $captureAmount + string $childCommerceCode, + string $token, + string $buyOrder, + string $authorizationCode, + float $captureAmount ) { $payload = [ 'commerce_code' => $childCommerceCode, @@ -194,11 +200,12 @@ public function capture( try { $response = $this->sendRequest( 'PUT', - str_replace('{token}', $token, static::ENDPOINT_CAPTURE), + str_replace(self::SEARCH_STRING, $token, static::ENDPOINT_CAPTURE), $payload ); } catch (WebpayRequestException $exception) { - throw new MallTransactionCaptureException($exception->getMessage(), + throw new MallTransactionCaptureException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), diff --git a/src/Webpay/WebpayPlus/Transaction.php b/src/Webpay/WebpayPlus/Transaction.php index 853c597a..8a10d767 100644 --- a/src/Webpay/WebpayPlus/Transaction.php +++ b/src/Webpay/WebpayPlus/Transaction.php @@ -3,6 +3,7 @@ namespace Transbank\Webpay\WebpayPlus; use Transbank\Utils\InteractsWithWebpayApi; +use GuzzleHttp\Exception\GuzzleException; use Transbank\Webpay\Exceptions\WebpayRequestException; use Transbank\Webpay\WebpayPlus\Exceptions\TransactionCaptureException; use Transbank\Webpay\WebpayPlus\Exceptions\TransactionCommitException; @@ -17,6 +18,12 @@ /** * Class Transaction. + * @var string ENDPOINT_CREATE + * @var string ENDPOINT_COMMIT + * @var string ENDPOINT_REFUND + * @var string ENDPOINT_STATUS + * @var string ENDPOINT_CAPTURE + * @var string SEARCH_STRING */ class Transaction { @@ -27,20 +34,25 @@ class Transaction const ENDPOINT_REFUND = 'rswebpaytransaction/api/webpay/v1.2/transactions/{token}/refunds'; const ENDPOINT_STATUS = 'rswebpaytransaction/api/webpay/v1.2/transactions/{token}'; const ENDPOINT_CAPTURE = 'rswebpaytransaction/api/webpay/v1.2/transactions/{token}/capture'; + const SEARCH_STRING = '{token}'; /** - * @param string $buyOrder - * @param string $sessionId - * @param int $amount - * @param string $returnUrl + * @param string $buyOrder + * @param string $sessionId + * @param float $amount + * @param string $returnUrl * * @throws TransactionCreateException - * @throws GuzzleHttp\Exception\GuzzleException + * @throws GuzzleException * * @return TransactionCreateResponse */ - public function create($buyOrder, $sessionId, $amount, $returnUrl) - { + public function create( + string $buyOrder, + string $sessionId, + float $amount, + string $returnUrl + ): TransactionCreateResponse { $payload = [ 'buy_order' => $buyOrder, 'session_id' => $sessionId, @@ -51,7 +63,8 @@ public function create($buyOrder, $sessionId, $amount, $returnUrl) try { $response = $this->sendRequest('POST', static::ENDPOINT_CREATE, $payload); } catch (WebpayRequestException $exception) { - throw new TransactionCreateException($exception->getMessage(), + throw new TransactionCreateException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), @@ -63,14 +76,14 @@ public function create($buyOrder, $sessionId, $amount, $returnUrl) } /** - * @param $token + * @param string $token * * @throws TransactionCommitException - * @throws GuzzleHttp\Exception\GuzzleException + * @throws GuzzleException * * @return TransactionCommitResponse */ - public function commit($token) + public function commit(string $token): TransactionCommitResponse { if (!is_string($token)) { throw new \InvalidArgumentException('Token parameter given is not string.'); @@ -82,11 +95,12 @@ public function commit($token) try { $response = $this->sendRequest( 'PUT', - str_replace('{token}', $token, static::ENDPOINT_COMMIT), - null + str_replace(self::SEARCH_STRING, $token, static::ENDPOINT_COMMIT), + [] ); } catch (WebpayRequestException $exception) { - throw new TransactionCommitException($exception->getMessage(), + throw new TransactionCommitException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), @@ -98,24 +112,25 @@ public function commit($token) } /** - * @param $token - * @param $amount + * @param string $token + * @param float $amount * * @throws TransactionRefundException - * @throws GuzzleHttp\Exception\GuzzleException + * @throws GuzzleException * * @return TransactionRefundResponse */ - public function refund($token, $amount) + public function refund(string $token, float $amount): TransactionRefundResponse { try { $response = $this->sendRequest( 'POST', - str_replace('{token}', $token, static::ENDPOINT_REFUND), + str_replace(self::SEARCH_STRING, $token, static::ENDPOINT_REFUND), ['amount' => $amount] ); } catch (WebpayRequestException $exception) { - throw new TransactionRefundException($exception->getMessage(), + throw new TransactionRefundException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), @@ -127,23 +142,24 @@ public function refund($token, $amount) } /** - * @param $token + * @param string $token * * @throws TransactionStatusException - * @throws GuzzleHttp\Exception\GuzzleException + * @throws GuzzleException * * @return TransactionStatusResponse */ - public function status($token) + public function status(string $token): TransactionStatusResponse { try { $response = $this->sendRequest( 'GET', - str_replace('{token}', $token, static::ENDPOINT_STATUS), - null + str_replace(self::SEARCH_STRING, $token, static::ENDPOINT_STATUS), + [] ); } catch (WebpayRequestException $exception) { - throw new TransactionStatusException($exception->getMessage(), + throw new TransactionStatusException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), @@ -155,18 +171,22 @@ public function status($token) } /** - * @param $token - * @param $buyOrder - * @param $authorizationCode - * @param $captureAmount + * @param string $token + * @param string $buyOrder + * @param string $authorizationCode + * @param float $captureAmount * * @throws TransactionCaptureException - * @throws GuzzleHttp\Exception\GuzzleException + * @throws GuzzleException * * @return TransactionCaptureResponse */ - public function capture($token, $buyOrder, $authorizationCode, $captureAmount) - { + public function capture( + string $token, + string $buyOrder, + string $authorizationCode, + float $captureAmount + ): TransactionCaptureResponse { $payload = [ 'buy_order' => $buyOrder, 'authorization_code' => $authorizationCode, @@ -176,11 +196,12 @@ public function capture($token, $buyOrder, $authorizationCode, $captureAmount) try { $response = $this->sendRequest( 'PUT', - str_replace('{token}', $token, static::ENDPOINT_CAPTURE), + str_replace(self::SEARCH_STRING, $token, static::ENDPOINT_CAPTURE), $payload ); } catch (WebpayRequestException $exception) { - throw new TransactionCaptureException($exception->getMessage(), + throw new TransactionCaptureException( + $exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(), $exception->getFailedRequest(), @@ -190,5 +211,4 @@ public function capture($token, $buyOrder, $authorizationCode, $captureAmount) return new TransactionCaptureResponse($response); } - } From ce8637e4af53545b2ff78a311b40c009dcdda8c3 Mon Sep 17 00:00:00 2001 From: Fernando Date: Mon, 1 Jul 2024 09:28:08 -0400 Subject: [PATCH 17/51] refactor: add type in webpay plus responses files --- .../MallTransactionStatusResponse.php | 68 +++++++++--------- .../Responses/TransactionCaptureResponse.php | 34 ++++----- .../Responses/TransactionCreateResponse.php | 17 +++-- .../Responses/TransactionDetail.php | 72 ++++++++++--------- .../Responses/TransactionRefundResponse.php | 48 +++++++------ .../Responses/TransactionStatusResponse.php | 20 +++--- 6 files changed, 130 insertions(+), 129 deletions(-) diff --git a/src/Webpay/WebpayPlus/Responses/MallTransactionStatusResponse.php b/src/Webpay/WebpayPlus/Responses/MallTransactionStatusResponse.php index abef71b6..33371ac5 100644 --- a/src/Webpay/WebpayPlus/Responses/MallTransactionStatusResponse.php +++ b/src/Webpay/WebpayPlus/Responses/MallTransactionStatusResponse.php @@ -9,21 +9,20 @@ */ class MallTransactionStatusResponse { - public $vci; - public $buyOrder; - public $sessionId; - public $cardNumber; - public $cardDetail; - public $expirationDate; - public $accountingDate; - public $transactionDate; + public string $vci; + public string $buyOrder; + public string $sessionId; + public string $cardNumber; + public array $cardDetail; + public ?string $expirationDate; + public string $accountingDate; + public string $transactionDate; + public array $details; /** * @var TransactionDetail[] */ - public $details; - - public function __construct($json) + public function __construct(array $json) { $this->vci = Utils::returnValueIfExists($json, 'vci'); $this->buyOrder = Utils::returnValueIfExists($json, 'buy_order'); @@ -33,12 +32,10 @@ public function __construct($json) $this->expirationDate = Utils::returnValueIfExists($json, 'expiration_date'); $this->accountingDate = Utils::returnValueIfExists($json, 'accounting_date'); $this->transactionDate = Utils::returnValueIfExists($json, 'transaction_date'); - $details = Utils::returnValueIfExists($json, 'details'); - $this->details = null; - if (is_array($details)) { - $this->details = []; - foreach ($details as $detail) { + $this->details = []; + if (is_array($json['details'])) { + foreach ($json['details'] as $detail) { $this->details[] = TransactionDetail::createFromArray($detail); } } @@ -49,7 +46,7 @@ public function __construct($json) * * @return bool */ - public function isApproved() + public function isApproved(): bool { if (!$details = $this->getDetails()) { return false; @@ -65,75 +62,74 @@ public function isApproved() } /** - * @return mixed + * @return string */ - public function getBuyOrder() + public function getBuyOrder(): string { return $this->buyOrder; } /** - * @return mixed + * @return string */ - public function getSessionId() + public function getSessionId(): string { return $this->sessionId; } /** - * @return mixed + * @return string */ - public function getCardNumber() + public function getCardNumber(): string { return $this->cardNumber; } /** - * @return mixed + * @return ?string */ - public function getExpirationDate() + public function getExpirationDate(): ?string { return $this->expirationDate; } /** - * @return mixed + * @return string */ - public function getAccountingDate() + public function getAccountingDate(): string { return $this->accountingDate; } /** - * @return mixed + * @return string */ - public function getTransactionDate() + public function getTransactionDate(): string { return $this->transactionDate; } /** - * @return TransactionDetail[]|null + * @return ?TransactionDetail[] */ - public function getDetails() + public function getDetails(): ?array { return $this->details; } /** - * @return mixed + * @return string */ - public function getVci() + public function getVci(): string { return $this->vci; } /** - * @return mixed|null + * @return ?array */ - public function getCardDetail() + public function getCardDetail(): ?array { return $this->cardDetail; } - } diff --git a/src/Webpay/WebpayPlus/Responses/TransactionCaptureResponse.php b/src/Webpay/WebpayPlus/Responses/TransactionCaptureResponse.php index ba6acaaa..2fb9c9fd 100644 --- a/src/Webpay/WebpayPlus/Responses/TransactionCaptureResponse.php +++ b/src/Webpay/WebpayPlus/Responses/TransactionCaptureResponse.php @@ -10,14 +10,14 @@ class TransactionCaptureResponse /** * TransactionCaptureResponse constructor. * - * @param mixed $responseJson + * @param array $json */ - public $authorizationCode; - public $authorizationDate; - public $capturedAmount; - public $responseCode; + public string $authorizationCode; + public string $authorizationDate; + public float $capturedAmount; + public int $responseCode; - public function __construct($json) + public function __construct(array $json) { $this->authorizationCode = Utils::returnValueIfExists($json, 'authorization_code'); $this->authorizationDate = Utils::returnValueIfExists($json, 'authorization_date'); @@ -25,41 +25,43 @@ public function __construct($json) $this->responseCode = Utils::returnValueIfExists($json, 'response_code'); } - public function isApproved() + /** + * @return bool + */ + public function isApproved(): bool { return $this->responseCode === ResponseCodesEnum::RESPONSE_CODE_APPROVED; } /** - * @return mixed + * @return string */ - public function getAuthorizationCode() + public function getAuthorizationCode(): string { return $this->authorizationCode; } /** - * @return mixed + * @return string */ - public function getAuthorizationDate() + public function getAuthorizationDate(): string { return $this->authorizationDate; } /** - * @return mixed + * @return float */ - public function getCapturedAmount() + public function getCapturedAmount(): float { return $this->capturedAmount; } /** - * @return mixed + * @return int */ - public function getResponseCode() + public function getResponseCode(): int { return $this->responseCode; } - } diff --git a/src/Webpay/WebpayPlus/Responses/TransactionCreateResponse.php b/src/Webpay/WebpayPlus/Responses/TransactionCreateResponse.php index 4ad95def..55072933 100644 --- a/src/Webpay/WebpayPlus/Responses/TransactionCreateResponse.php +++ b/src/Webpay/WebpayPlus/Responses/TransactionCreateResponse.php @@ -7,12 +7,12 @@ class TransactionCreateResponse { /** - * @var string|null + * @var ?string */ public $token; /** - * @var string|null + * @var ?string */ public $url; @@ -25,7 +25,7 @@ class TransactionCreateResponse * + url (string, required) - the url returned from a successful call to * 'create' */ - public function __construct($json) + public function __construct(array $json) { $this->token = Utils::returnValueIfExists($json, 'token'); $this->url = Utils::returnValueIfExists($json, 'url'); @@ -40,7 +40,7 @@ public function __construct($json) * * @return $this */ - public function fromJSON($json) + public function fromJSON(array $json) { $this->token = Utils::returnValueIfExists($json, 'token'); $this->url = Utils::returnValueIfExists($json, 'url'); @@ -49,19 +49,18 @@ public function fromJSON($json) } /** - * @return string|null + * @return ?string */ - public function getToken() + public function getToken(): ?string { return $this->token; } /** - * @return string|null + * @return ?string */ - public function getUrl() + public function getUrl(): ?string { return $this->url; } - } diff --git a/src/Webpay/WebpayPlus/Responses/TransactionDetail.php b/src/Webpay/WebpayPlus/Responses/TransactionDetail.php index 6caa90ca..f3983c75 100644 --- a/src/Webpay/WebpayPlus/Responses/TransactionDetail.php +++ b/src/Webpay/WebpayPlus/Responses/TransactionDetail.php @@ -8,16 +8,16 @@ class TransactionDetail { - public $amount; - public $status; - public $authorizationCode; - public $paymentTypeCode; - public $responseCode; - public $installmentsNumber; - public $installmentsAmount; - public $commerceCode; - public $buyOrder; - public $balance; + public float $amount; + public string $status; + public string $authorizationCode; + public string $paymentTypeCode; + public int $responseCode; + public int $installmentsNumber; + public ?float $installmentsAmount; + public ?string $commerceCode; + public string $buyOrder; + public ?float $balance; public static function createFromArray(array $array) { @@ -36,102 +36,104 @@ public static function createFromArray(array $array) return $result; } - public function isApproved() + /** + * @return bool + */ + public function isApproved(): bool { - if($this->getResponseCode() !== ResponseCodesEnum::RESPONSE_CODE_APPROVED) { + if ($this->getResponseCode() !== ResponseCodesEnum::RESPONSE_CODE_APPROVED) { return false; } - switch($this->getStatus()) { + switch ($this->getStatus()) { case TransactionStatusEnum::STATUS_CAPTURED: case TransactionStatusEnum::STATUS_REVERSED: case TransactionStatusEnum::STATUS_NULLIFIED: case TransactionStatusEnum::STATUS_AUTHORIZED: case TransactionStatusEnum::STATUS_PARTIALLY_NULLIFIED: return true; - default : + default: return false; } } /** - * @return mixed + * @return float */ - public function getAmount() + public function getAmount(): float { return $this->amount; } /** - * @return mixed + * @return string */ - public function getStatus() + public function getStatus(): string { return $this->status; } /** - * @return mixed + * @return string */ - public function getAuthorizationCode() + public function getAuthorizationCode(): string { return $this->authorizationCode; } /** - * @return mixed + * @return string */ - public function getPaymentTypeCode() + public function getPaymentTypeCode(): string { return $this->paymentTypeCode; } /** - * @return mixed + * @return int */ - public function getResponseCode() + public function getResponseCode(): int { return $this->responseCode; } /** - * @return mixed + * @return int */ - public function getInstallmentsNumber() + public function getInstallmentsNumber(): int { return $this->installmentsNumber; } /** - * @return mixed + * @return int */ - public function getCommerceCode() + public function getCommerceCode(): string { return $this->commerceCode; } /** - * @return mixed + * @return string */ - public function getBuyOrder() + public function getBuyOrder(): string { return $this->buyOrder; } /** - * @return mixed + * @return ?float */ - public function getInstallmentsAmount() + public function getInstallmentsAmount(): ?float { return $this->installmentsAmount; } /** - * @return mixed + * @return float */ - public function getBalance() + public function getBalance(): float { return $this->balance; } - } diff --git a/src/Webpay/WebpayPlus/Responses/TransactionRefundResponse.php b/src/Webpay/WebpayPlus/Responses/TransactionRefundResponse.php index 5432d725..98fc75e7 100644 --- a/src/Webpay/WebpayPlus/Responses/TransactionRefundResponse.php +++ b/src/Webpay/WebpayPlus/Responses/TransactionRefundResponse.php @@ -8,36 +8,36 @@ class TransactionRefundResponse { /** - * @var mixed|null + * @var string */ public $type; /** - * @var mixed|null + * @var ?string */ public $authorizationCode; /** - * @var mixed|null + * @var ?string */ public $authorizationDate; /** - * @var mixed|null + * @var ?float */ public $nullifiedAmount; /** - * @var mixed|null + * @var ?float */ public $balance; /** - * @var mixed|null + * @var ?int */ public $responseCode; /** * TransactionRefundResponse constructor. * - * @param $json + * @param array $json */ - public function __construct($json) + public function __construct(array $json) { $this->type = Utils::returnValueIfExists($json, 'type'); $this->authorizationCode = Utils::returnValueIfExists($json, 'authorization_code'); @@ -47,58 +47,60 @@ public function __construct($json) $this->responseCode = Utils::returnValueIfExists($json, 'response_code'); } - public function success() + /** + * @return bool + */ + public function success(): bool { return $this->getType() === TransactionStatusEnum::STATUS_REVERSED || ($this->getType() === TransactionStatusEnum::STATUS_NULLIFIED && $this->getResponseCode() === 0); } /** - * @return mixed|null + * @return ?float */ - public function getNullifiedAmount() + public function getNullifiedAmount(): ?float { return $this->nullifiedAmount; } /** - * @return mixed|null + * @return ?float */ - public function getBalance() + public function getBalance(): ?float { return $this->balance; } /** - * @return mixed|null + * @return ?int */ - public function getResponseCode() + public function getResponseCode(): int { - return (int) $this->responseCode; + return $this->responseCode; } /** - * @return mixed|null + * @return string */ - public function getType() + public function getType(): string { return $this->type; } /** - * @return mixed|null + * @return ?string */ - public function getAuthorizationCode() + public function getAuthorizationCode(): ?string { return $this->authorizationCode; } /** - * @return mixed|null + * @return ?string */ - public function getAuthorizationDate() + public function getAuthorizationDate(): string { return $this->authorizationDate; } - } diff --git a/src/Webpay/WebpayPlus/Responses/TransactionStatusResponse.php b/src/Webpay/WebpayPlus/Responses/TransactionStatusResponse.php index 35c3b861..89960170 100644 --- a/src/Webpay/WebpayPlus/Responses/TransactionStatusResponse.php +++ b/src/Webpay/WebpayPlus/Responses/TransactionStatusResponse.php @@ -10,9 +10,9 @@ class TransactionStatusResponse { use HasTransactionStatus; - public $vci; + public string $vci; - public function __construct($json) + public function __construct(array $json) { $this->vci = Utils::returnValueIfExists($json, 'vci'); $this->setTransactionStatusFields($json); @@ -23,38 +23,38 @@ public function __construct($json) * * @return bool */ - public function isApproved() + public function isApproved(): bool { - if($this->getResponseCode() !== ResponseCodesEnum::RESPONSE_CODE_APPROVED) { + if ($this->getResponseCode() !== ResponseCodesEnum::RESPONSE_CODE_APPROVED) { return false; } - switch($this->getStatus()) { + switch ($this->getStatus()) { case TransactionStatusEnum::STATUS_CAPTURED: case TransactionStatusEnum::STATUS_REVERSED: case TransactionStatusEnum::STATUS_NULLIFIED: case TransactionStatusEnum::STATUS_AUTHORIZED: case TransactionStatusEnum::STATUS_PARTIALLY_NULLIFIED: return true; - default : + default: return false; } } /** - * @return mixed + * @return string */ - public function getVci() + public function getVci(): string { return $this->vci; } /** - * @param mixed $vci + * @param string $vci * * @return TransactionStatusResponse */ - public function setVci($vci) + public function setVci(string $vci): TransactionStatusResponse { $this->vci = $vci; From aeb6dc65fdf67c581d43e98a592bc77924d08f0b Mon Sep 17 00:00:00 2001 From: Fernando Date: Mon, 1 Jul 2024 09:44:55 -0400 Subject: [PATCH 18/51] chore: update PHP version to 8.2 in CI workflow --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b9083e99..b2c22c30 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-versions: [7.4] + php-versions: [8.2] steps: - name: Checkout repository uses: actions/checkout@v2 From ab7b626c0675727629cded0efe891c6ea03c4264 Mon Sep 17 00:00:00 2001 From: Fernando Date: Mon, 1 Jul 2024 09:48:56 -0400 Subject: [PATCH 19/51] refactor: add null type to installmentsAmount --- .../Responses/MallTransactionInstallmentsResponse.php | 6 +++--- .../Responses/TransactionInstallmentsResponse.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php b/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php index 563ff331..e9ef4a1f 100644 --- a/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php @@ -6,7 +6,7 @@ class MallTransactionInstallmentsResponse { - public float $installmentsAmount; + public ?float $installmentsAmount; public string $idQueryInstallments; public array $deferredPeriods; @@ -18,9 +18,9 @@ public function __construct(array $json) } /** - * @return float + * @return ?float */ - public function getInstallmentsAmount(): float + public function getInstallmentsAmount(): ?float { return $this->installmentsAmount; } diff --git a/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php b/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php index 488c20f4..90807759 100644 --- a/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php @@ -6,7 +6,7 @@ class TransactionInstallmentsResponse { - public float $installmentsAmount; + public ?float $installmentsAmount; public string $idQueryInstallments; public array $deferredPeriods; @@ -18,7 +18,7 @@ public function __construct(array $json) } /** - * @return float + * @return ?float */ public function getInstallmentsAmount(): float { From 1bcb6f37c5beac751d9136d888c1ce713ae6ffd9 Mon Sep 17 00:00:00 2001 From: Fernando Date: Tue, 2 Jul 2024 09:10:07 -0400 Subject: [PATCH 20/51] feat: add the return type of the request --- src/Contracts/HttpClientInterface.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Contracts/HttpClientInterface.php b/src/Contracts/HttpClientInterface.php index 82248592..4e18ef68 100644 --- a/src/Contracts/HttpClientInterface.php +++ b/src/Contracts/HttpClientInterface.php @@ -17,5 +17,10 @@ interface HttpClientInterface * * @return ResponseInterface */ - public function request(string $method, string $url, ?array $payload = [], ?array $options = null); + public function request( + string $method, + string $url, + ?array $payload = [], + ?array $options = null + ): ResponseInterface; } From eb013d5235610733a375b3c095113767a70402c9 Mon Sep 17 00:00:00 2001 From: Fernando Date: Tue, 2 Jul 2024 09:11:24 -0400 Subject: [PATCH 21/51] feat: add last response and request in requestservice interface --- src/Contracts/RequestService.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Contracts/RequestService.php b/src/Contracts/RequestService.php index fd835e10..6346957f 100644 --- a/src/Contracts/RequestService.php +++ b/src/Contracts/RequestService.php @@ -4,6 +4,8 @@ use Transbank\Webpay\Options; use Transbank\Webpay\Exceptions\WebpayRequestException; +use Psr\Http\Message\ResponseInterface; +use Transbank\Webpay\Exceptions\TransbankApiRequest; interface RequestService { @@ -17,5 +19,12 @@ interface RequestService * * @return array Response from the API as json. */ - public function request(string $method, string $endpoint, array $payload, Options $options); + public function request( + string $method, + string $endpoint, + array $payload, + Options $options + ): array; + public function getLastResponse(): ?ResponseInterface; + public function getLastRequest(): ?TransbankApiRequest; } From c008cfccb1efdb90a864b32a4715fdcfe1048bcb Mon Sep 17 00:00:00 2001 From: Fernando Date: Tue, 2 Jul 2024 09:14:05 -0400 Subject: [PATCH 22/51] refactor: add type in request for httpclient class --- src/Utils/HttpClient.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Utils/HttpClient.php b/src/Utils/HttpClient.php index 6f2e6793..bb983a8f 100644 --- a/src/Utils/HttpClient.php +++ b/src/Utils/HttpClient.php @@ -22,8 +22,12 @@ class HttpClient implements HttpClientInterface * * @return ResponseInterface */ - public function request(string $method, string $url, ?array $payload = [], ?array $options = null) - { + public function request( + string $method, + string $url, + ?array $payload = [], + ?array $options = null + ): ResponseInterface { $installedVersion = 'unknown'; if (class_exists('\Composer\InstalledVersions')) { @@ -35,7 +39,7 @@ public function request(string $method, string $url, ?array $payload = [], ?arra $baseHeaders = [ 'Content-Type' => 'application/json', - 'User-Agent' => 'SDK-PHP/'.$installedVersion, + 'User-Agent' => 'SDK-PHP/' . $installedVersion, ]; $givenHeaders = $options['headers'] ?? []; @@ -98,8 +102,13 @@ protected function sendGuzzle5Request($method, $url, array $headers, $payload, i * * @return ResponseInterface */ - protected function sendGuzzleRequest(string $method, string $url, array $headers, ?string $payload, int $timeout): ResponseInterface - { + protected function sendGuzzleRequest( + string $method, + string $url, + array $headers, + ?string $payload, + int $timeout + ): ResponseInterface { $request = new Request($method, $url, $headers, $payload); $client = new Client([ From 1e03a1b746ecc1f69b5f78371e17664c50bc5281 Mon Sep 17 00:00:00 2001 From: Fernando Date: Tue, 2 Jul 2024 09:15:22 -0400 Subject: [PATCH 23/51] refactor: add type in mallinscription --- src/Webpay/Oneclick/MallInscription.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Webpay/Oneclick/MallInscription.php b/src/Webpay/Oneclick/MallInscription.php index 4c124f9c..a0a49bb3 100644 --- a/src/Webpay/Oneclick/MallInscription.php +++ b/src/Webpay/Oneclick/MallInscription.php @@ -30,7 +30,7 @@ class MallInscription * @throws InscriptionStartException * @throws GuzzleException */ - public function start($username, $email, $responseUrl): InscriptionStartResponse + public function start(string $username, string $email, string $responseUrl): InscriptionStartResponse { $payload = [ 'username' => $username, @@ -65,7 +65,7 @@ public function start($username, $email, $responseUrl): InscriptionStartResponse * @throws InscriptionFinishException * @throws GuzzleException */ - public function finish($token): InscriptionFinishResponse + public function finish(string $token): InscriptionFinishResponse { try { $response = $this->sendRequest( @@ -95,7 +95,7 @@ public function finish($token): InscriptionFinishResponse * @throws InscriptionDeleteException * @throws GuzzleException */ - public function delete($tbkUser, $username): InscriptionDeleteResponse + public function delete(string $tbkUser, string $username): InscriptionDeleteResponse { $payload = [ 'tbk_user' => $tbkUser, From 02d43f7db3ffcb34ae6feaaeaa3272c557e2f8f7 Mon Sep 17 00:00:00 2001 From: Fernando Date: Tue, 2 Jul 2024 09:33:48 -0400 Subject: [PATCH 24/51] refactor: add null type in inscription finish props --- .../Responses/InscriptionFinishResponse.php | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Webpay/Oneclick/Responses/InscriptionFinishResponse.php b/src/Webpay/Oneclick/Responses/InscriptionFinishResponse.php index c33131f8..da3c9c7d 100644 --- a/src/Webpay/Oneclick/Responses/InscriptionFinishResponse.php +++ b/src/Webpay/Oneclick/Responses/InscriptionFinishResponse.php @@ -8,10 +8,10 @@ class InscriptionFinishResponse { public int $responseCode; - public string $tbkUser; - public string $authorizationCode; - public string $cardType; - public string $cardNumber; + public ?string $tbkUser; + public ?string $authorizationCode; + public ?string $cardType; + public ?string $cardNumber; public function __construct(array $json) { @@ -36,33 +36,33 @@ public function getResponseCode(): int } /** - * @return string + * @return ?string */ - public function getTbkUser(): string + public function getTbkUser(): ?string { return $this->tbkUser; } /** - * @return string + * @return ?string */ - public function getAuthorizationCode(): string + public function getAuthorizationCode(): ?string { return $this->authorizationCode; } /** - * @return string + * @return ?string */ - public function getCardType(): string + public function getCardType(): ?string { return $this->cardType; } /** - * @return string + * @return ?string */ - public function getCardNumber(): string + public function getCardNumber(): ?string { return $this->cardNumber; } From 53894bc15eed7c0de8966bda506fac8d58d03ef6 Mon Sep 17 00:00:00 2001 From: Fernando Date: Tue, 2 Jul 2024 15:59:33 -0400 Subject: [PATCH 25/51] refactor: add type in get status function return of patpass inscription --- src/PatpassComercio/Responses/InscriptionFinishResponse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PatpassComercio/Responses/InscriptionFinishResponse.php b/src/PatpassComercio/Responses/InscriptionFinishResponse.php index 3bb8c4ac..c4cf64de 100644 --- a/src/PatpassComercio/Responses/InscriptionFinishResponse.php +++ b/src/PatpassComercio/Responses/InscriptionFinishResponse.php @@ -29,7 +29,7 @@ public function __construct(int $httpCode) /** * @return ?string */ - public function getStatus(): string + public function getStatus(): ?string { return $this->status; } From 88a02d96dcf1e37b0191940e749266a472beaab0 Mon Sep 17 00:00:00 2001 From: Fernando Date: Tue, 2 Jul 2024 17:55:44 -0400 Subject: [PATCH 26/51] refactor: add null type in patpass comercio --- src/PatpassComercio/Inscription.php | 43 +++++++++++++++-------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/PatpassComercio/Inscription.php b/src/PatpassComercio/Inscription.php index a13e45fc..21dcf83f 100644 --- a/src/PatpassComercio/Inscription.php +++ b/src/PatpassComercio/Inscription.php @@ -17,6 +17,7 @@ use Transbank\Utils\RequestServiceTrait; use Transbank\Contracts\RequestService; use Transbank\PatpassComercio\Options; +use GuzzleHttp\Exception\GuzzleException; class Inscription { @@ -32,8 +33,8 @@ class Inscription /** * Transaction constructor. * - * @param Options $options - * @param RequestService|null $requestService + * @param Options $options + * @param ?RequestService $requestService */ public function __construct( Options $options, @@ -62,26 +63,26 @@ public function __construct( * @param string $city * * @throws InscriptionStartException - * @throws \GuzzleHttp\Exception\GuzzleException + * @throws GuzzleException * * @return InscriptionStartResponse */ public function start( - $url, - $name, - $lastName, - $secondLastName, - $rut, - $serviceId, - $finalUrl, - $maxAmount, - $phone, - $cellPhone, - $patpassName, - $personEmail, - $commerceEmail, - $address, - $city + string $url, + string $name, + string $lastName, + string $secondLastName, + string $rut, + string $serviceId, + string $finalUrl, + string $maxAmount, + string $phone, + string $cellPhone, + string $patpassName, + string $personEmail, + string $commerceEmail, + string $address, + string $city ): InscriptionStartResponse { $payload = [ 'url' => $url, @@ -122,7 +123,7 @@ public function start( * @param string $token * * @throws InscriptionStatusException - * @throws \GuzzleHttp\Exception\GuzzleException + * @throws GuzzleException * * @return InscriptionStatusResponse */ @@ -159,8 +160,10 @@ public function getOptions(): Options /** * @param Options $options + * + * @return void */ - public function setOptions(Options $options) + public function setOptions(Options $options): void { $this->options = $options; } From b5d075664ffa86a9c5c98cc80c413f5ab32c023f Mon Sep 17 00:00:00 2001 From: Fernando Date: Tue, 2 Jul 2024 17:55:57 -0400 Subject: [PATCH 27/51] refactor: add null type in utils files --- src/Utils/HasTransactionStatus.php | 48 +++++++++++++------------- src/Utils/HttpClientRequestService.php | 10 ++++-- src/Utils/RequestServiceTrait.php | 8 ++--- 3 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/Utils/HasTransactionStatus.php b/src/Utils/HasTransactionStatus.php index 49380829..bfe579f1 100644 --- a/src/Utils/HasTransactionStatus.php +++ b/src/Utils/HasTransactionStatus.php @@ -4,19 +4,19 @@ trait HasTransactionStatus { - public string $status; - public int $responseCode; - public float $amount; - public string $authorizationCode; - public string $paymentTypeCode; - public string $accountingDate; - public int $installmentsNumber; + public ?string $status; + public ?int $responseCode; + public ?float $amount; + public ?string $authorizationCode; + public ?string $paymentTypeCode; + public ?string $accountingDate; + public ?int $installmentsNumber; public ?float $installmentsAmount; - public string $sessionId; - public string $buyOrder; - public string $cardNumber; - public array $cardDetail; - public string $transactionDate; + public ?string $sessionId; + public ?string $buyOrder; + public ?string $cardNumber; + public ?array $cardDetail; + public ?string $transactionDate; public ?float $balance; /** @@ -28,49 +28,49 @@ public function getBalance(): ?float } /** - * @return string + * @return ?string */ - public function getStatus(): string + public function getStatus(): ?string { return $this->status; } /** - * @return string + * @return ?string */ - public function getAuthorizationCode(): string + public function getAuthorizationCode(): ?string { return $this->authorizationCode; } /** - * @return int + * @return ?int */ - public function getInstallmentsNumber(): int + public function getInstallmentsNumber(): ?int { return $this->installmentsNumber; } /** - * @return int + * @return ?int */ - public function getResponseCode(): int + public function getResponseCode(): ?int { return $this->responseCode; } /** - * @return string + * @return ?string */ - public function getBuyOrder(): string + public function getBuyOrder(): ?string { return $this->buyOrder; } /** - * @return string + * @return ?string */ - public function getAccountingDate(): string + public function getAccountingDate(): ?string { return $this->accountingDate; } diff --git a/src/Utils/HttpClientRequestService.php b/src/Utils/HttpClientRequestService.php index 36c2a566..ea2284ed 100644 --- a/src/Utils/HttpClientRequestService.php +++ b/src/Utils/HttpClientRequestService.php @@ -25,7 +25,7 @@ class HttpClientRequestService implements RequestService /** * @var HttpClientInterface */ - protected HttpClientInterface $httpClient; + protected ?HttpClientInterface $httpClient; public function __construct(?HttpClientInterface $httpClient = null) { @@ -42,6 +42,8 @@ public function getHttpClient(): HttpClientInterface /** * @param HttpClientInterface $httpClient + * + * @return void */ public function setHttpClient(HttpClientInterface $httpClient): void { @@ -75,8 +77,10 @@ public function request( $request = new TransbankApiRequest($method, $baseUrl, $endpoint, $payload, $headers); $this->setLastRequest($request); - $response = $client->request($method, $baseUrl.$endpoint, $payload, ['headers' => $headers, - 'timeout' => $options->getTimeout()]); + $response = $client->request($method, $baseUrl . $endpoint, $payload, [ + 'headers' => $headers, + 'timeout' => $options->getTimeout() + ]); $this->setLastResponse($response); $responseStatusCode = $response->getStatusCode(); diff --git a/src/Utils/RequestServiceTrait.php b/src/Utils/RequestServiceTrait.php index b31c3f2f..223cd13c 100644 --- a/src/Utils/RequestServiceTrait.php +++ b/src/Utils/RequestServiceTrait.php @@ -17,15 +17,15 @@ trait RequestServiceTrait protected ?RequestService $requestService = null; /** - * @param string $method - * @param string $endpoint + * @param string $method + * @param string $endpoint * @param array $payload * * @throws WebpayRequestException * - * @return mixed + * @return array */ - public function sendRequest(string $method, string $endpoint, array $payload = []) + public function sendRequest(string $method, string $endpoint, array $payload = []): array { return $this->getRequestService()->request( $method, From 1fb3ddd61091c8ec08882e170d7fd19925071ce5 Mon Sep 17 00:00:00 2001 From: Fernando Date: Tue, 2 Jul 2024 17:56:12 -0400 Subject: [PATCH 28/51] refactor: add null type in webpay options file --- src/Webpay/Options.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Webpay/Options.php b/src/Webpay/Options.php index b9ecfb4f..ddea1e6b 100644 --- a/src/Webpay/Options.php +++ b/src/Webpay/Options.php @@ -41,7 +41,7 @@ class Options * @var string Sets the environment that the SDK is going * to point to (eg. TEST, LIVE, etc). */ - public string $integrationType = self::ENVIRONMENT_INTEGRATION; + public ?string $integrationType = null; public function __construct( string $apiKey, From badef99a05dec80141283d1c718b2da60a04304a Mon Sep 17 00:00:00 2001 From: Fernando Date: Tue, 2 Jul 2024 17:56:33 -0400 Subject: [PATCH 29/51] refactor: add null type in oneclick responses files --- .../Responses/InscriptionFinishResponse.php | 6 ++-- .../Responses/InscriptionStartResponse.php | 12 ++++---- .../MallTransactionCaptureResponse.php | 12 ++++++++ .../MallTransactionRefundResponse.php | 6 ++-- .../MallTransactionStatusResponse.php | 28 +++++++++---------- 5 files changed, 38 insertions(+), 26 deletions(-) diff --git a/src/Webpay/Oneclick/Responses/InscriptionFinishResponse.php b/src/Webpay/Oneclick/Responses/InscriptionFinishResponse.php index da3c9c7d..600ed541 100644 --- a/src/Webpay/Oneclick/Responses/InscriptionFinishResponse.php +++ b/src/Webpay/Oneclick/Responses/InscriptionFinishResponse.php @@ -7,7 +7,7 @@ class InscriptionFinishResponse { - public int $responseCode; + public ?int $responseCode; public ?string $tbkUser; public ?string $authorizationCode; public ?string $cardType; @@ -28,9 +28,9 @@ public function isApproved(): bool } /** - * @return int + * @return ?int */ - public function getResponseCode(): int + public function getResponseCode(): ?int { return $this->responseCode; } diff --git a/src/Webpay/Oneclick/Responses/InscriptionStartResponse.php b/src/Webpay/Oneclick/Responses/InscriptionStartResponse.php index ac562ecc..e1c08507 100644 --- a/src/Webpay/Oneclick/Responses/InscriptionStartResponse.php +++ b/src/Webpay/Oneclick/Responses/InscriptionStartResponse.php @@ -6,8 +6,8 @@ class InscriptionStartResponse { - public string $token; - public string $urlWebpay; + public ?string $token; + public ?string $urlWebpay; public function __construct(array $json) { @@ -21,17 +21,17 @@ public function getRedirectUrl(): string } /** - * @return string + * @return ?string */ - public function getToken(): string + public function getToken(): ?string { return $this->token; } /** - * @return string + * @return ?string */ - public function getUrlWebpay(): string + public function getUrlWebpay(): ?string { return $this->urlWebpay; } diff --git a/src/Webpay/Oneclick/Responses/MallTransactionCaptureResponse.php b/src/Webpay/Oneclick/Responses/MallTransactionCaptureResponse.php index 38a251f5..23334797 100644 --- a/src/Webpay/Oneclick/Responses/MallTransactionCaptureResponse.php +++ b/src/Webpay/Oneclick/Responses/MallTransactionCaptureResponse.php @@ -19,21 +19,33 @@ public function __construct(array $json) $this->responseCode = Utils::returnValueIfExists($json, 'response_code'); } + /** + * @return ?string + */ public function getAuthorizationCode(): ?string { return $this->authorizationCode; } + /** + * @return ?string + */ public function getAuthorizationDate(): ?string { return $this->authorizationDate; } + /** + * @return ?float + */ public function getCapturedAmount(): ?float { return $this->capturedAmount; } + /** + * @return ?int + */ public function getResponseCode(): ?int { return $this->responseCode; diff --git a/src/Webpay/Oneclick/Responses/MallTransactionRefundResponse.php b/src/Webpay/Oneclick/Responses/MallTransactionRefundResponse.php index a59e8d68..182cf62d 100644 --- a/src/Webpay/Oneclick/Responses/MallTransactionRefundResponse.php +++ b/src/Webpay/Oneclick/Responses/MallTransactionRefundResponse.php @@ -6,7 +6,7 @@ class MallTransactionRefundResponse { - public string $type; + public ?string $type; public ?string $authorizationCode; public ?string $authorizationDate; public ?float $nullifiedAmount; @@ -24,9 +24,9 @@ public function __construct(array $json) } /** - * @return string + * @return ?string */ - public function getType(): string + public function getType(): ?string { return $this->type; } diff --git a/src/Webpay/Oneclick/Responses/MallTransactionStatusResponse.php b/src/Webpay/Oneclick/Responses/MallTransactionStatusResponse.php index 954c510e..3bca30df 100644 --- a/src/Webpay/Oneclick/Responses/MallTransactionStatusResponse.php +++ b/src/Webpay/Oneclick/Responses/MallTransactionStatusResponse.php @@ -6,12 +6,12 @@ class MallTransactionStatusResponse { - public string $buyOrder; - public array $cardDetail; - public string $cardNumber; - public string $accountingDate; - public string $transactionDate; - public array $details; + public ?string $buyOrder; + public ?array $cardDetail; + public ?string $cardNumber; + public ?string $accountingDate; + public ?string $transactionDate; + public ?array $details; public function __construct(array $json) { @@ -58,33 +58,33 @@ public function getTransactionDate(): ?string } /** - * @return string + * @return ?string */ - public function getCardNumber(): string + public function getCardNumber(): ?string { return $this->cardNumber; } /** - * @return string + * @return ?string */ - public function getAccountingDate(): string + public function getAccountingDate(): ?string { return $this->accountingDate; } /** - * @return TransactionDetail[] + * @return ?TransactionDetail[] */ - public function getDetails(): array + public function getDetails(): ?array { return $this->details; } /** - * @return string + * @return ?string */ - public function getBuyOrder(): string + public function getBuyOrder(): ?string { return $this->buyOrder; } From 434c17bf21e2ce11b10cc0bd22e368e19038595f Mon Sep 17 00:00:00 2001 From: Fernando Date: Tue, 2 Jul 2024 17:56:58 -0400 Subject: [PATCH 30/51] refactor: add null type in transaccion completa responses files --- .../MallTransactionCreateResponse.php | 2 +- .../MallTransactionInstallmentsResponse.php | 12 +++---- .../MallTransactionRefundResponse.php | 14 ++++---- .../MallTransactionStatusResponse.php | 36 +++++++++---------- .../Responses/TransactionCreateResponse.php | 6 ++-- .../TransactionInstallmentsResponse.php | 14 ++++---- .../Responses/TransactionRefundResponse.php | 6 ++-- 7 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/Webpay/TransaccionCompleta/Responses/MallTransactionCreateResponse.php b/src/Webpay/TransaccionCompleta/Responses/MallTransactionCreateResponse.php index 4767aa65..3ef51d37 100644 --- a/src/Webpay/TransaccionCompleta/Responses/MallTransactionCreateResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/MallTransactionCreateResponse.php @@ -6,7 +6,7 @@ class MallTransactionCreateResponse { - public string $token; + public ?string $token; public function __construct(array $json) { diff --git a/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php b/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php index e9ef4a1f..b826cef3 100644 --- a/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php @@ -7,8 +7,8 @@ class MallTransactionInstallmentsResponse { public ?float $installmentsAmount; - public string $idQueryInstallments; - public array $deferredPeriods; + public ?string $idQueryInstallments; + public ?array $deferredPeriods; public function __construct(array $json) { @@ -26,17 +26,17 @@ public function getInstallmentsAmount(): ?float } /** - * @return string + * @return ?string */ - public function getIdQueryInstallments(): string + public function getIdQueryInstallments(): ?string { return $this->idQueryInstallments; } /** - * @return array + * @return ?array */ - public function getDeferredPeriods(): array + public function getDeferredPeriods(): ?array { return $this->deferredPeriods; } diff --git a/src/Webpay/TransaccionCompleta/Responses/MallTransactionRefundResponse.php b/src/Webpay/TransaccionCompleta/Responses/MallTransactionRefundResponse.php index 1ae9f210..c038b4f3 100644 --- a/src/Webpay/TransaccionCompleta/Responses/MallTransactionRefundResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/MallTransactionRefundResponse.php @@ -6,12 +6,12 @@ class MallTransactionRefundResponse { - public string $type; + public ?string $type; public ?string $authorizationCode; public ?string $authorizationDate; public ?float $nullifiedAmount; public ?float $balance; - public int $responseCode; + public ?int $responseCode; public function __construct(array $json) { @@ -24,9 +24,9 @@ public function __construct(array $json) } /** - * @return string + * @return ?string */ - public function getType(): string + public function getType(): ?string { return $this->type; } @@ -64,10 +64,10 @@ public function getBalance(): ?float } /** - * @return int + * @return ?int */ - public function getResponseCode(): int + public function getResponseCode(): ?int { - return (int) $this->responseCode; + return $this->responseCode; } } diff --git a/src/Webpay/TransaccionCompleta/Responses/MallTransactionStatusResponse.php b/src/Webpay/TransaccionCompleta/Responses/MallTransactionStatusResponse.php index 5b20be91..682dce26 100644 --- a/src/Webpay/TransaccionCompleta/Responses/MallTransactionStatusResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/MallTransactionStatusResponse.php @@ -6,12 +6,12 @@ class MallTransactionStatusResponse { - protected string $buyOrder; - protected array $cardDetail; - protected string $cardNumber; - protected string $accountingDate; - protected string $transactionDate; - protected array $details; + protected ?string $buyOrder; + protected ?array $cardDetail; + protected ?string $cardNumber; + protected ?string $accountingDate; + protected ?string $transactionDate; + protected ?array $details; public function __construct(array $json) { @@ -30,49 +30,49 @@ public function __construct(array $json) } /** - * @return string + * @return ?string */ - public function getBuyOrder(): string + public function getBuyOrder(): ?string { return $this->buyOrder; } /** - * @return array + * @return ?array */ - public function getCardDetail(): array + public function getCardDetail(): ?array { return $this->cardDetail; } /** - * @return string + * @return ?string */ - public function getAccountingDate(): string + public function getAccountingDate(): ?string { return $this->accountingDate; } /** - * @return string + * @return ?string */ - public function getTransactionDate(): string + public function getTransactionDate(): ?string { return $this->transactionDate; } /** - * @return array + * @return ?array */ - public function getDetails(): array + public function getDetails(): ?array { return $this->details; } /** - * @return string + * @return ?string */ - public function getCardNumber(): string + public function getCardNumber(): ?string { return $this->cardNumber; } diff --git a/src/Webpay/TransaccionCompleta/Responses/TransactionCreateResponse.php b/src/Webpay/TransaccionCompleta/Responses/TransactionCreateResponse.php index c17b0a44..ab5d9b41 100644 --- a/src/Webpay/TransaccionCompleta/Responses/TransactionCreateResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/TransactionCreateResponse.php @@ -6,7 +6,7 @@ class TransactionCreateResponse { - public string $token; + public ?string $token; public function __construct(array $json) { @@ -14,9 +14,9 @@ public function __construct(array $json) } /** - * @return string + * @return ?string */ - public function getToken(): string + public function getToken(): ?string { return $this->token; } diff --git a/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php b/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php index 90807759..96a8eac0 100644 --- a/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php @@ -7,8 +7,8 @@ class TransactionInstallmentsResponse { public ?float $installmentsAmount; - public string $idQueryInstallments; - public array $deferredPeriods; + public ?string $idQueryInstallments; + public ?array $deferredPeriods; public function __construct(array $json) { @@ -20,23 +20,23 @@ public function __construct(array $json) /** * @return ?float */ - public function getInstallmentsAmount(): float + public function getInstallmentsAmount(): ?float { return $this->installmentsAmount; } /** - * @return string + * @return ?string */ - public function getIdQueryInstallments(): string + public function getIdQueryInstallments(): ?string { return $this->idQueryInstallments; } /** - * @return array + * @return ?array */ - public function getDeferredPeriods(): array + public function getDeferredPeriods(): ?array { return $this->deferredPeriods; } diff --git a/src/Webpay/TransaccionCompleta/Responses/TransactionRefundResponse.php b/src/Webpay/TransaccionCompleta/Responses/TransactionRefundResponse.php index 18d34cff..1ffb959f 100644 --- a/src/Webpay/TransaccionCompleta/Responses/TransactionRefundResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/TransactionRefundResponse.php @@ -6,7 +6,7 @@ class TransactionRefundResponse { - public string $type; + public ?string $type; public ?string $authorizationCode; public ?string $authorizationDate; public ?float $nullifiedAmount; @@ -24,9 +24,9 @@ public function __construct(array $json) } /** - * @return string + * @return ?string */ - public function getType(): string + public function getType(): ?string { return $this->type; } From 0dd1804f2568c7c6093a37e112bb222b8ecaea4c Mon Sep 17 00:00:00 2001 From: Fernando Date: Tue, 2 Jul 2024 17:57:14 -0400 Subject: [PATCH 31/51] refactor: add null type in webpay plus responses files --- .../MallTransactionStatusResponse.php | 40 +++++++-------- .../Responses/TransactionCaptureResponse.php | 24 ++++----- .../Responses/TransactionCreateResponse.php | 4 +- .../Responses/TransactionDetail.php | 50 +++++++++---------- .../Responses/TransactionRefundResponse.php | 20 ++++---- .../Responses/TransactionStatusResponse.php | 6 +-- 6 files changed, 72 insertions(+), 72 deletions(-) diff --git a/src/Webpay/WebpayPlus/Responses/MallTransactionStatusResponse.php b/src/Webpay/WebpayPlus/Responses/MallTransactionStatusResponse.php index 33371ac5..f49d0f28 100644 --- a/src/Webpay/WebpayPlus/Responses/MallTransactionStatusResponse.php +++ b/src/Webpay/WebpayPlus/Responses/MallTransactionStatusResponse.php @@ -9,15 +9,15 @@ */ class MallTransactionStatusResponse { - public string $vci; - public string $buyOrder; - public string $sessionId; - public string $cardNumber; - public array $cardDetail; + public ?string $vci; + public ?string $buyOrder; + public ?string $sessionId; + public ?string $cardNumber; + public ?array $cardDetail; public ?string $expirationDate; - public string $accountingDate; - public string $transactionDate; - public array $details; + public ?string $accountingDate; + public ?string $transactionDate; + public ?array $details; /** * @var TransactionDetail[] @@ -62,25 +62,25 @@ public function isApproved(): bool } /** - * @return string + * @return ?string */ - public function getBuyOrder(): string + public function getBuyOrder(): ?string { return $this->buyOrder; } /** - * @return string + * @return ?string */ - public function getSessionId(): string + public function getSessionId(): ?string { return $this->sessionId; } /** - * @return string + * @return ?string */ - public function getCardNumber(): string + public function getCardNumber(): ?string { return $this->cardNumber; } @@ -94,17 +94,17 @@ public function getExpirationDate(): ?string } /** - * @return string + * @return ?string */ - public function getAccountingDate(): string + public function getAccountingDate(): ?string { return $this->accountingDate; } /** - * @return string + * @return ?string */ - public function getTransactionDate(): string + public function getTransactionDate(): ?string { return $this->transactionDate; } @@ -118,9 +118,9 @@ public function getDetails(): ?array } /** - * @return string + * @return ?string */ - public function getVci(): string + public function getVci(): ?string { return $this->vci; } diff --git a/src/Webpay/WebpayPlus/Responses/TransactionCaptureResponse.php b/src/Webpay/WebpayPlus/Responses/TransactionCaptureResponse.php index 2fb9c9fd..d666e767 100644 --- a/src/Webpay/WebpayPlus/Responses/TransactionCaptureResponse.php +++ b/src/Webpay/WebpayPlus/Responses/TransactionCaptureResponse.php @@ -12,10 +12,10 @@ class TransactionCaptureResponse * * @param array $json */ - public string $authorizationCode; - public string $authorizationDate; - public float $capturedAmount; - public int $responseCode; + public ?string $authorizationCode; + public ?string $authorizationDate; + public ?float $capturedAmount; + public ?int $responseCode; public function __construct(array $json) { @@ -34,33 +34,33 @@ public function isApproved(): bool } /** - * @return string + * @return ?string */ - public function getAuthorizationCode(): string + public function getAuthorizationCode(): ?string { return $this->authorizationCode; } /** - * @return string + * @return ?string */ - public function getAuthorizationDate(): string + public function getAuthorizationDate(): ?string { return $this->authorizationDate; } /** - * @return float + * @return ?float */ - public function getCapturedAmount(): float + public function getCapturedAmount(): ?float { return $this->capturedAmount; } /** - * @return int + * @return ?int */ - public function getResponseCode(): int + public function getResponseCode(): ?int { return $this->responseCode; } diff --git a/src/Webpay/WebpayPlus/Responses/TransactionCreateResponse.php b/src/Webpay/WebpayPlus/Responses/TransactionCreateResponse.php index 55072933..bbf61bb8 100644 --- a/src/Webpay/WebpayPlus/Responses/TransactionCreateResponse.php +++ b/src/Webpay/WebpayPlus/Responses/TransactionCreateResponse.php @@ -9,12 +9,12 @@ class TransactionCreateResponse /** * @var ?string */ - public $token; + public ?string $token; /** * @var ?string */ - public $url; + public ?string $url; /** * TransactionCreateResponse constructor. diff --git a/src/Webpay/WebpayPlus/Responses/TransactionDetail.php b/src/Webpay/WebpayPlus/Responses/TransactionDetail.php index f3983c75..9ce240fa 100644 --- a/src/Webpay/WebpayPlus/Responses/TransactionDetail.php +++ b/src/Webpay/WebpayPlus/Responses/TransactionDetail.php @@ -8,15 +8,15 @@ class TransactionDetail { - public float $amount; - public string $status; - public string $authorizationCode; - public string $paymentTypeCode; - public int $responseCode; - public int $installmentsNumber; + public ?float $amount; + public ?string $status; + public ?string $authorizationCode; + public ?string $paymentTypeCode; + public ?int $responseCode; + public ?int $installmentsNumber; public ?float $installmentsAmount; public ?string $commerceCode; - public string $buyOrder; + public ?string $buyOrder; public ?float $balance; public static function createFromArray(array $array) @@ -58,65 +58,65 @@ public function isApproved(): bool } /** - * @return float + * @return ?float */ - public function getAmount(): float + public function getAmount(): ?float { return $this->amount; } /** - * @return string + * @return ?string */ - public function getStatus(): string + public function getStatus(): ?string { return $this->status; } /** - * @return string + * @return ?string */ - public function getAuthorizationCode(): string + public function getAuthorizationCode(): ?string { return $this->authorizationCode; } /** - * @return string + * @return ?string */ - public function getPaymentTypeCode(): string + public function getPaymentTypeCode(): ?string { return $this->paymentTypeCode; } /** - * @return int + * @return ?int */ - public function getResponseCode(): int + public function getResponseCode(): ?int { return $this->responseCode; } /** - * @return int + * @return ?int */ - public function getInstallmentsNumber(): int + public function getInstallmentsNumber(): ?int { return $this->installmentsNumber; } /** - * @return int + * @return ?int */ - public function getCommerceCode(): string + public function getCommerceCode(): ?string { return $this->commerceCode; } /** - * @return string + * @return ?string */ - public function getBuyOrder(): string + public function getBuyOrder(): ?string { return $this->buyOrder; } @@ -130,9 +130,9 @@ public function getInstallmentsAmount(): ?float } /** - * @return float + * @return ?float */ - public function getBalance(): float + public function getBalance(): ?float { return $this->balance; } diff --git a/src/Webpay/WebpayPlus/Responses/TransactionRefundResponse.php b/src/Webpay/WebpayPlus/Responses/TransactionRefundResponse.php index 98fc75e7..f9ede336 100644 --- a/src/Webpay/WebpayPlus/Responses/TransactionRefundResponse.php +++ b/src/Webpay/WebpayPlus/Responses/TransactionRefundResponse.php @@ -10,27 +10,27 @@ class TransactionRefundResponse /** * @var string */ - public $type; + public ?string $type; /** * @var ?string */ - public $authorizationCode; + public ?string $authorizationCode; /** * @var ?string */ - public $authorizationDate; + public ?string $authorizationDate; /** * @var ?float */ - public $nullifiedAmount; + public ?float $nullifiedAmount; /** * @var ?float */ - public $balance; + public ?float $balance; /** * @var ?int */ - public $responseCode; + public ?int $responseCode; /** * TransactionRefundResponse constructor. @@ -75,15 +75,15 @@ public function getBalance(): ?float /** * @return ?int */ - public function getResponseCode(): int + public function getResponseCode(): ?int { return $this->responseCode; } /** - * @return string + * @return ?string */ - public function getType(): string + public function getType(): ?string { return $this->type; } @@ -99,7 +99,7 @@ public function getAuthorizationCode(): ?string /** * @return ?string */ - public function getAuthorizationDate(): string + public function getAuthorizationDate(): ?string { return $this->authorizationDate; } diff --git a/src/Webpay/WebpayPlus/Responses/TransactionStatusResponse.php b/src/Webpay/WebpayPlus/Responses/TransactionStatusResponse.php index 89960170..d2d979c9 100644 --- a/src/Webpay/WebpayPlus/Responses/TransactionStatusResponse.php +++ b/src/Webpay/WebpayPlus/Responses/TransactionStatusResponse.php @@ -10,7 +10,7 @@ class TransactionStatusResponse { use HasTransactionStatus; - public string $vci; + public ?string $vci; public function __construct(array $json) { @@ -42,9 +42,9 @@ public function isApproved(): bool } /** - * @return string + * @return ?string */ - public function getVci(): string + public function getVci(): ?string { return $this->vci; } From 53c40a14723f0a1a791411894d09dee7ddfc970e Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 3 Jul 2024 11:38:48 -0400 Subject: [PATCH 32/51] refactor: add return type in build function for inscription class --- src/PatpassComercio/Inscription.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/PatpassComercio/Inscription.php b/src/PatpassComercio/Inscription.php index 21dcf83f..40f5a04d 100644 --- a/src/PatpassComercio/Inscription.php +++ b/src/PatpassComercio/Inscription.php @@ -180,21 +180,21 @@ protected function getBaseUrl(): string * @param string $commerceCode * @param string $apiKey * - * @return static + * @return self */ - public static function buildForIntegration(string $commerceCode, string $apiKey) + public static function buildForIntegration(string $commerceCode, string $apiKey): self { - return new static(new Options($apiKey, $commerceCode, Options::ENVIRONMENT_INTEGRATION)); + return new self(new Options($apiKey, $commerceCode, Options::ENVIRONMENT_INTEGRATION)); } /** * @param string $commerceCode * @param string $apiKey * - * @return static + * @return self */ - public static function buildForProduction(string $commerceCode, string $apiKey) + public static function buildForProduction(string $commerceCode, string $apiKey): self { - return new static(new Options($apiKey, $commerceCode, Options::ENVIRONMENT_PRODUCTION)); + return new self(new Options($apiKey, $commerceCode, Options::ENVIRONMENT_PRODUCTION)); } } From 65fbd2425d0a6cf80b3bedaccbb43066642e715a Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 3 Jul 2024 12:35:23 -0400 Subject: [PATCH 33/51] refactor: delete unnecesary patpass comerce props --- src/PatpassComercio/PatpassComercio.php | 34 +------------------------ 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/src/PatpassComercio/PatpassComercio.php b/src/PatpassComercio/PatpassComercio.php index 5bb1ae4c..e44e19c0 100644 --- a/src/PatpassComercio/PatpassComercio.php +++ b/src/PatpassComercio/PatpassComercio.php @@ -6,43 +6,11 @@ * @category */ - namespace Transbank\PatpassComercio; +namespace Transbank\PatpassComercio; class PatpassComercio { public const INTEGRATION_API_KEY = 'cxxXQgGD9vrVe4M41FIt'; public const INTEGRATION_COMMERCE_CODE = '28299257'; - - /** - * @var string - */ - protected string $integrationApiKey; - - /** - * @var string - */ - protected string $integrationCommerceCode; - - public function __construct() - { - $this->integrationApiKey = self::INTEGRATION_API_KEY; - $this->integrationCommerceCode = self::INTEGRATION_COMMERCE_CODE; - } - - /** - * @return string - */ - public function getIntegrationApiKey(): string - { - return $this->integrationApiKey; - } - - /** - * @return string - */ - public function getIntegrationCommerceCode(): string - { - return $this->integrationCommerceCode; - } } From 74c02f981590c9b2f9a283bc9b1ad677aa3f207c Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 3 Jul 2024 13:12:38 -0400 Subject: [PATCH 34/51] refactor: change nullable string type by union types --- .../Responses/InscriptionFinishResponse.php | 6 +-- .../Responses/InscriptionStartResponse.php | 13 +++-- .../Responses/InscriptionStatusResponse.php | 13 +++-- src/Utils/HasTransactionStatus.php | 48 +++++++++---------- src/Utils/HttpClient.php | 4 +- .../Exceptions/WebpayRequestException.php | 16 +++---- .../Responses/InscriptionFinishResponse.php | 24 +++++----- .../Responses/InscriptionStartResponse.php | 12 ++--- .../MallTransactionCaptureResponse.php | 12 ++--- .../MallTransactionRefundResponse.php | 18 +++---- .../MallTransactionStatusResponse.php | 24 +++++----- src/Webpay/Options.php | 22 ++++----- .../TransaccionCompleta/MallTransaction.php | 4 +- .../MallTransactionCreateResponse.php | 6 +-- .../MallTransactionInstallmentsResponse.php | 6 +-- .../MallTransactionRefundResponse.php | 18 +++---- .../MallTransactionStatusResponse.php | 24 +++++----- .../Responses/TransactionCreateResponse.php | 6 +-- .../TransactionInstallmentsResponse.php | 6 +-- .../Responses/TransactionRefundResponse.php | 18 +++---- .../Responses/TransactionStatusResponse.php | 6 +-- .../TransaccionCompleta/Transaction.php | 4 +- .../MallTransactionStatusResponse.php | 42 ++++++++-------- .../Responses/TransactionCaptureResponse.php | 12 ++--- .../Responses/TransactionCreateResponse.php | 16 +++---- .../Responses/TransactionDetail.php | 28 +++++------ .../Responses/TransactionRefundResponse.php | 22 ++++----- .../Responses/TransactionStatusResponse.php | 6 +-- 28 files changed, 217 insertions(+), 219 deletions(-) diff --git a/src/PatpassComercio/Responses/InscriptionFinishResponse.php b/src/PatpassComercio/Responses/InscriptionFinishResponse.php index c4cf64de..0e172615 100644 --- a/src/PatpassComercio/Responses/InscriptionFinishResponse.php +++ b/src/PatpassComercio/Responses/InscriptionFinishResponse.php @@ -10,7 +10,7 @@ class InscriptionFinishResponse { - public ?string $status; + public string|null $status; public int $code; public function __construct(int $httpCode) @@ -27,9 +27,9 @@ public function __construct(int $httpCode) } /** - * @return ?string + * @return string|null */ - public function getStatus(): ?string + public function getStatus(): string|null { return $this->status; } diff --git a/src/PatpassComercio/Responses/InscriptionStartResponse.php b/src/PatpassComercio/Responses/InscriptionStartResponse.php index 543c8a4c..7fbd5631 100644 --- a/src/PatpassComercio/Responses/InscriptionStartResponse.php +++ b/src/PatpassComercio/Responses/InscriptionStartResponse.php @@ -12,8 +12,8 @@ class InscriptionStartResponse { - public ?string $token; - public ?string $urlWebpay; + public string|null $token; + public string|null $urlWebpay; /** * InscriptionStartResponse constructor. @@ -27,19 +27,18 @@ public function __construct(array $json) } /** - * @return ?string + * @return string|null */ - public function getToken(): ?string + public function getToken(): string|null { return $this->token; } /** - * @return ?string + * @return string|null */ - public function getUrlWebpay(): ?string + public function getUrlWebpay(): string|null { return $this->urlWebpay; } - } diff --git a/src/PatpassComercio/Responses/InscriptionStatusResponse.php b/src/PatpassComercio/Responses/InscriptionStatusResponse.php index aaa369b1..516e2047 100644 --- a/src/PatpassComercio/Responses/InscriptionStatusResponse.php +++ b/src/PatpassComercio/Responses/InscriptionStatusResponse.php @@ -12,8 +12,8 @@ class InscriptionStatusResponse { - public ?string $status; - public ?string $urlVoucher; + public string|null $status; + public string|null $urlVoucher; /** * InscriptionStatusResponse constructor. @@ -28,19 +28,18 @@ public function __construct(array $json) } /** - * @return ?string + * @return string|null */ - public function getStatus(): ?string + public function getStatus(): string|null { return $this->status; } /** - * @return ?string + * @return string|null */ - public function getUrlVoucher(): ?string + public function getUrlVoucher(): string|null { return $this->urlVoucher; } - } diff --git a/src/Utils/HasTransactionStatus.php b/src/Utils/HasTransactionStatus.php index bfe579f1..b0e1d42d 100644 --- a/src/Utils/HasTransactionStatus.php +++ b/src/Utils/HasTransactionStatus.php @@ -4,19 +4,19 @@ trait HasTransactionStatus { - public ?string $status; + public string|null $status; public ?int $responseCode; public ?float $amount; - public ?string $authorizationCode; - public ?string $paymentTypeCode; - public ?string $accountingDate; + public string|null $authorizationCode; + public string|null $paymentTypeCode; + public string|null $accountingDate; public ?int $installmentsNumber; public ?float $installmentsAmount; - public ?string $sessionId; - public ?string $buyOrder; - public ?string $cardNumber; + public string|null $sessionId; + public string|null $buyOrder; + public string|null $cardNumber; public ?array $cardDetail; - public ?string $transactionDate; + public string|null $transactionDate; public ?float $balance; /** @@ -28,17 +28,17 @@ public function getBalance(): ?float } /** - * @return ?string + * @return string|null */ - public function getStatus(): ?string + public function getStatus(): string|null { return $this->status; } /** - * @return ?string + * @return string|null */ - public function getAuthorizationCode(): ?string + public function getAuthorizationCode(): string|null { return $this->authorizationCode; } @@ -60,17 +60,17 @@ public function getResponseCode(): ?int } /** - * @return ?string + * @return string|null */ - public function getBuyOrder(): ?string + public function getBuyOrder(): string|null { return $this->buyOrder; } /** - * @return ?string + * @return string|null */ - public function getAccountingDate(): ?string + public function getAccountingDate(): string|null { return $this->accountingDate; } @@ -105,17 +105,17 @@ public function getCardDetail(): ?array } /** - * @return ?string + * @return string|null */ - public function getCardNumber(): ?string + public function getCardNumber(): string|null { return $this->cardNumber; } /** - * @return ?string + * @return string|null */ - public function getPaymentTypeCode(): ?string + public function getPaymentTypeCode(): string|null { return $this->paymentTypeCode; } @@ -129,9 +129,9 @@ public function getInstallmentsAmount(): ?float } /** - * @return ?string + * @return string|null */ - public function getSessionId(): ?string + public function getSessionId(): string|null { return $this->sessionId; } @@ -145,9 +145,9 @@ public function getAmount(): ?float } /** - * @return ?string + * @return string|null */ - public function getTransactionDate(): ?string + public function getTransactionDate(): string|null { return $this->transactionDate; } diff --git a/src/Utils/HttpClient.php b/src/Utils/HttpClient.php index bb983a8f..dc2697fc 100644 --- a/src/Utils/HttpClient.php +++ b/src/Utils/HttpClient.php @@ -95,7 +95,7 @@ protected function sendGuzzle5Request($method, $url, array $headers, $payload, i * @param string $method * @param string $url * @param array $headers - * @param ?string $payload + * @param string|null $payload * @param int $timeout * * @throws GuzzleException @@ -106,7 +106,7 @@ protected function sendGuzzleRequest( string $method, string $url, array $headers, - ?string $payload, + string|null $payload, int $timeout ): ResponseInterface { $request = new Request($method, $url, $headers, $payload); diff --git a/src/Webpay/Exceptions/WebpayRequestException.php b/src/Webpay/Exceptions/WebpayRequestException.php index a36a5d9a..a493a638 100644 --- a/src/Webpay/Exceptions/WebpayRequestException.php +++ b/src/Webpay/Exceptions/WebpayRequestException.php @@ -13,9 +13,9 @@ class WebpayRequestException extends WebpayException protected static string $defaultMessage = 'An error has happened on the request'; /** - * @var ?string + * @var string|null */ - protected ?string $transbankErrorMessage; + protected string|null $transbankErrorMessage; /** * @var ?int */ @@ -35,14 +35,14 @@ class WebpayRequestException extends WebpayException * WebpayRequestException constructor. * * @param string $message - * @param ?string $tbkErrorMessage + * @param string|null $tbkErrorMessage * @param ?int $httpCode * @param ?TransbankApiRequest $failedRequest * @param ?\Exception $previous */ public function __construct( string $message, - ?string $tbkErrorMessage = null, + string|null $tbkErrorMessage = null, ?int $httpCode = null, ?TransbankApiRequest $failedRequest = null, ?\Exception $previous = null @@ -62,9 +62,9 @@ public function __construct( } /** - * @return ?string + * @return string|null */ - public function getTransbankErrorMessage(): ?string + public function getTransbankErrorMessage(): string|null { return $this->transbankErrorMessage; } @@ -103,14 +103,14 @@ public function getFailedRequest(): ?TransbankApiRequest /** * @param string $message - * @param ?string $tbkErrorMessage + * @param string|null $tbkErrorMessage * @param ?int $httpCode * * @return string */ protected function getExceptionMessage( string $message, - ?string $tbkErrorMessage, + string|null $tbkErrorMessage, ?int $httpCode ): string { if (!$tbkErrorMessage) { diff --git a/src/Webpay/Oneclick/Responses/InscriptionFinishResponse.php b/src/Webpay/Oneclick/Responses/InscriptionFinishResponse.php index 600ed541..af0d201e 100644 --- a/src/Webpay/Oneclick/Responses/InscriptionFinishResponse.php +++ b/src/Webpay/Oneclick/Responses/InscriptionFinishResponse.php @@ -8,10 +8,10 @@ class InscriptionFinishResponse { public ?int $responseCode; - public ?string $tbkUser; - public ?string $authorizationCode; - public ?string $cardType; - public ?string $cardNumber; + public string|null $tbkUser; + public string|null $authorizationCode; + public string|null $cardType; + public string|null $cardNumber; public function __construct(array $json) { @@ -36,33 +36,33 @@ public function getResponseCode(): ?int } /** - * @return ?string + * @return string|null */ - public function getTbkUser(): ?string + public function getTbkUser(): string|null { return $this->tbkUser; } /** - * @return ?string + * @return string|null */ - public function getAuthorizationCode(): ?string + public function getAuthorizationCode(): string|null { return $this->authorizationCode; } /** - * @return ?string + * @return string|null */ - public function getCardType(): ?string + public function getCardType(): string|null { return $this->cardType; } /** - * @return ?string + * @return string|null */ - public function getCardNumber(): ?string + public function getCardNumber(): string|null { return $this->cardNumber; } diff --git a/src/Webpay/Oneclick/Responses/InscriptionStartResponse.php b/src/Webpay/Oneclick/Responses/InscriptionStartResponse.php index e1c08507..dd75fd9b 100644 --- a/src/Webpay/Oneclick/Responses/InscriptionStartResponse.php +++ b/src/Webpay/Oneclick/Responses/InscriptionStartResponse.php @@ -6,8 +6,8 @@ class InscriptionStartResponse { - public ?string $token; - public ?string $urlWebpay; + public string|null $token; + public string|null $urlWebpay; public function __construct(array $json) { @@ -21,17 +21,17 @@ public function getRedirectUrl(): string } /** - * @return ?string + * @return string|null */ - public function getToken(): ?string + public function getToken(): string|null { return $this->token; } /** - * @return ?string + * @return string|null */ - public function getUrlWebpay(): ?string + public function getUrlWebpay(): string|null { return $this->urlWebpay; } diff --git a/src/Webpay/Oneclick/Responses/MallTransactionCaptureResponse.php b/src/Webpay/Oneclick/Responses/MallTransactionCaptureResponse.php index 23334797..e13d3e5f 100644 --- a/src/Webpay/Oneclick/Responses/MallTransactionCaptureResponse.php +++ b/src/Webpay/Oneclick/Responses/MallTransactionCaptureResponse.php @@ -6,8 +6,8 @@ class MallTransactionCaptureResponse { - public ?string $authorizationCode; - public ?string $authorizationDate; + public string|null $authorizationCode; + public string|null $authorizationDate; public ?float $capturedAmount; public ?int $responseCode; @@ -20,17 +20,17 @@ public function __construct(array $json) } /** - * @return ?string + * @return string|null */ - public function getAuthorizationCode(): ?string + public function getAuthorizationCode(): string|null { return $this->authorizationCode; } /** - * @return ?string + * @return string|null */ - public function getAuthorizationDate(): ?string + public function getAuthorizationDate(): string|null { return $this->authorizationDate; } diff --git a/src/Webpay/Oneclick/Responses/MallTransactionRefundResponse.php b/src/Webpay/Oneclick/Responses/MallTransactionRefundResponse.php index 182cf62d..a39abb4b 100644 --- a/src/Webpay/Oneclick/Responses/MallTransactionRefundResponse.php +++ b/src/Webpay/Oneclick/Responses/MallTransactionRefundResponse.php @@ -6,9 +6,9 @@ class MallTransactionRefundResponse { - public ?string $type; - public ?string $authorizationCode; - public ?string $authorizationDate; + public string|null $type; + public string|null $authorizationCode; + public string|null $authorizationDate; public ?float $nullifiedAmount; public ?float $balance; public ?int $responseCode; @@ -24,25 +24,25 @@ public function __construct(array $json) } /** - * @return ?string + * @return string|null */ - public function getType(): ?string + public function getType(): string|null { return $this->type; } /** - * @return ?string + * @return string|null */ - public function getAuthorizationCode(): ?string + public function getAuthorizationCode(): string|null { return $this->authorizationCode; } /** - * @return ?string + * @return string|null */ - public function getAuthorizationDate(): ?string + public function getAuthorizationDate(): string|null { return $this->authorizationDate; } diff --git a/src/Webpay/Oneclick/Responses/MallTransactionStatusResponse.php b/src/Webpay/Oneclick/Responses/MallTransactionStatusResponse.php index 3bca30df..c4ab9463 100644 --- a/src/Webpay/Oneclick/Responses/MallTransactionStatusResponse.php +++ b/src/Webpay/Oneclick/Responses/MallTransactionStatusResponse.php @@ -6,11 +6,11 @@ class MallTransactionStatusResponse { - public ?string $buyOrder; + public string|null $buyOrder; public ?array $cardDetail; - public ?string $cardNumber; - public ?string $accountingDate; - public ?string $transactionDate; + public string|null $cardNumber; + public string|null $accountingDate; + public string|null $transactionDate; public ?array $details; public function __construct(array $json) @@ -50,25 +50,25 @@ public function isApproved(): bool } /** - * @return ?string + * @return string|null */ - public function getTransactionDate(): ?string + public function getTransactionDate(): string|null { return $this->transactionDate; } /** - * @return ?string + * @return string|null */ - public function getCardNumber(): ?string + public function getCardNumber(): string|null { return $this->cardNumber; } /** - * @return ?string + * @return string|null */ - public function getAccountingDate(): ?string + public function getAccountingDate(): string|null { return $this->accountingDate; } @@ -82,9 +82,9 @@ public function getDetails(): ?array } /** - * @return ?string + * @return string|null */ - public function getBuyOrder(): ?string + public function getBuyOrder(): string|null { return $this->buyOrder; } diff --git a/src/Webpay/Options.php b/src/Webpay/Options.php index ddea1e6b..c4dbefd2 100644 --- a/src/Webpay/Options.php +++ b/src/Webpay/Options.php @@ -28,20 +28,20 @@ class Options protected int $timeout; /** - * @var ?string Your api key, given by Transbank.Sent as a header when + * @var string|null Your api key, given by Transbank.Sent as a header when * making requests to Transbank on a field called "Tbk-Api-Key-Secret" */ - public ?string $apiKey = null; + public string|null $apiKey = null; /** - * @var ?string Your commerce code, given by Transbank. Sent as + * @var string|null Your commerce code, given by Transbank. Sent as * a header when making requests to Transbank on a field called "Tbk-Api-Key-Id" */ - public ?string $commerceCode = null; + public string|null $commerceCode = null; /** * @var string Sets the environment that the SDK is going * to point to (eg. TEST, LIVE, etc). */ - public ?string $integrationType = null; + public string|null $integrationType = null; public function __construct( string $apiKey, @@ -64,9 +64,9 @@ public function isProduction(): bool } /** - * @return ?string + * @return string|null */ - public function getIntegrationType(): ?string + public function getIntegrationType(): string|null { return $this->integrationType; } @@ -84,9 +84,9 @@ public function setIntegrationType($integrationType): Options } /** - * @return ?string + * @return string|null */ - public function getApiKey(): ?string + public function getApiKey(): string|null { return $this->apiKey; } @@ -104,9 +104,9 @@ public function setApiKey(string $apiKey): Options } /** - * @return ?string + * @return string|null */ - public function getCommerceCode(): ?string + public function getCommerceCode(): string|null { return $this->commerceCode; } diff --git a/src/Webpay/TransaccionCompleta/MallTransaction.php b/src/Webpay/TransaccionCompleta/MallTransaction.php index c63ac8aa..d150db66 100644 --- a/src/Webpay/TransaccionCompleta/MallTransaction.php +++ b/src/Webpay/TransaccionCompleta/MallTransaction.php @@ -42,7 +42,7 @@ class MallTransaction * @param string $cardNumber * @param string $cardExpirationDate * @param array $details - * @param ?string $cvv + * @param string|null $cvv * * @throws MallTransactionCreateException * @@ -54,7 +54,7 @@ public function create( string $cardNumber, string $cardExpirationDate, array $details, - ?string $cvv = null + string|null $cvv = null ) { $payload = [ 'buy_order' => $buyOrder, diff --git a/src/Webpay/TransaccionCompleta/Responses/MallTransactionCreateResponse.php b/src/Webpay/TransaccionCompleta/Responses/MallTransactionCreateResponse.php index 3ef51d37..42b10fa6 100644 --- a/src/Webpay/TransaccionCompleta/Responses/MallTransactionCreateResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/MallTransactionCreateResponse.php @@ -6,7 +6,7 @@ class MallTransactionCreateResponse { - public ?string $token; + public string|null $token; public function __construct(array $json) { @@ -14,9 +14,9 @@ public function __construct(array $json) } /** - * @return ?string + * @return string|null */ - public function getToken(): ?string + public function getToken(): string|null { return $this->token; } diff --git a/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php b/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php index b826cef3..07c21482 100644 --- a/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php @@ -7,7 +7,7 @@ class MallTransactionInstallmentsResponse { public ?float $installmentsAmount; - public ?string $idQueryInstallments; + public string|null $idQueryInstallments; public ?array $deferredPeriods; public function __construct(array $json) @@ -26,9 +26,9 @@ public function getInstallmentsAmount(): ?float } /** - * @return ?string + * @return string|null */ - public function getIdQueryInstallments(): ?string + public function getIdQueryInstallments(): string|null { return $this->idQueryInstallments; } diff --git a/src/Webpay/TransaccionCompleta/Responses/MallTransactionRefundResponse.php b/src/Webpay/TransaccionCompleta/Responses/MallTransactionRefundResponse.php index c038b4f3..92cef897 100644 --- a/src/Webpay/TransaccionCompleta/Responses/MallTransactionRefundResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/MallTransactionRefundResponse.php @@ -6,9 +6,9 @@ class MallTransactionRefundResponse { - public ?string $type; - public ?string $authorizationCode; - public ?string $authorizationDate; + public string|null $type; + public string|null $authorizationCode; + public string|null $authorizationDate; public ?float $nullifiedAmount; public ?float $balance; public ?int $responseCode; @@ -24,25 +24,25 @@ public function __construct(array $json) } /** - * @return ?string + * @return string|null */ - public function getType(): ?string + public function getType(): string|null { return $this->type; } /** - * @return ?string + * @return string|null */ - public function getAuthorizationCode(): ?string + public function getAuthorizationCode(): string|null { return $this->authorizationCode; } /** - * @return ?string + * @return string|null */ - public function getAuthorizationDate(): ?string + public function getAuthorizationDate(): string|null { return $this->authorizationDate; } diff --git a/src/Webpay/TransaccionCompleta/Responses/MallTransactionStatusResponse.php b/src/Webpay/TransaccionCompleta/Responses/MallTransactionStatusResponse.php index 682dce26..02434ece 100644 --- a/src/Webpay/TransaccionCompleta/Responses/MallTransactionStatusResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/MallTransactionStatusResponse.php @@ -6,11 +6,11 @@ class MallTransactionStatusResponse { - protected ?string $buyOrder; + protected string|null $buyOrder; protected ?array $cardDetail; - protected ?string $cardNumber; - protected ?string $accountingDate; - protected ?string $transactionDate; + protected string|null $cardNumber; + protected string|null $accountingDate; + protected string|null $transactionDate; protected ?array $details; public function __construct(array $json) @@ -30,9 +30,9 @@ public function __construct(array $json) } /** - * @return ?string + * @return string|null */ - public function getBuyOrder(): ?string + public function getBuyOrder(): string|null { return $this->buyOrder; } @@ -46,17 +46,17 @@ public function getCardDetail(): ?array } /** - * @return ?string + * @return string|null */ - public function getAccountingDate(): ?string + public function getAccountingDate(): string|null { return $this->accountingDate; } /** - * @return ?string + * @return string|null */ - public function getTransactionDate(): ?string + public function getTransactionDate(): string|null { return $this->transactionDate; } @@ -70,9 +70,9 @@ public function getDetails(): ?array } /** - * @return ?string + * @return string|null */ - public function getCardNumber(): ?string + public function getCardNumber(): string|null { return $this->cardNumber; } diff --git a/src/Webpay/TransaccionCompleta/Responses/TransactionCreateResponse.php b/src/Webpay/TransaccionCompleta/Responses/TransactionCreateResponse.php index ab5d9b41..558cab1f 100644 --- a/src/Webpay/TransaccionCompleta/Responses/TransactionCreateResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/TransactionCreateResponse.php @@ -6,7 +6,7 @@ class TransactionCreateResponse { - public ?string $token; + public string|null $token; public function __construct(array $json) { @@ -14,9 +14,9 @@ public function __construct(array $json) } /** - * @return ?string + * @return string|null */ - public function getToken(): ?string + public function getToken(): string|null { return $this->token; } diff --git a/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php b/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php index 96a8eac0..a3649be2 100644 --- a/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php @@ -7,7 +7,7 @@ class TransactionInstallmentsResponse { public ?float $installmentsAmount; - public ?string $idQueryInstallments; + public string|null $idQueryInstallments; public ?array $deferredPeriods; public function __construct(array $json) @@ -26,9 +26,9 @@ public function getInstallmentsAmount(): ?float } /** - * @return ?string + * @return string|null */ - public function getIdQueryInstallments(): ?string + public function getIdQueryInstallments(): string|null { return $this->idQueryInstallments; } diff --git a/src/Webpay/TransaccionCompleta/Responses/TransactionRefundResponse.php b/src/Webpay/TransaccionCompleta/Responses/TransactionRefundResponse.php index 1ffb959f..3c429780 100644 --- a/src/Webpay/TransaccionCompleta/Responses/TransactionRefundResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/TransactionRefundResponse.php @@ -6,9 +6,9 @@ class TransactionRefundResponse { - public ?string $type; - public ?string $authorizationCode; - public ?string $authorizationDate; + public string|null $type; + public string|null $authorizationCode; + public string|null $authorizationDate; public ?float $nullifiedAmount; public ?float $balance; public ?int $responseCode; @@ -24,25 +24,25 @@ public function __construct(array $json) } /** - * @return ?string + * @return string|null */ - public function getType(): ?string + public function getType(): string|null { return $this->type; } /** - * @return ?string + * @return string|null */ - public function getAuthorizationCode(): ?string + public function getAuthorizationCode(): string|null { return $this->authorizationCode; } /** - * @return ?string + * @return string|null */ - public function getAuthorizationDate(): ?string + public function getAuthorizationDate(): string|null { return $this->authorizationDate; } diff --git a/src/Webpay/TransaccionCompleta/Responses/TransactionStatusResponse.php b/src/Webpay/TransaccionCompleta/Responses/TransactionStatusResponse.php index 904d1594..982b7abb 100644 --- a/src/Webpay/TransaccionCompleta/Responses/TransactionStatusResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/TransactionStatusResponse.php @@ -9,7 +9,7 @@ class TransactionStatusResponse { use HasTransactionStatus; - public ?string $vci; + public string|null $vci; public ?float $prepaidBalance; public function __construct(array $json) @@ -20,9 +20,9 @@ public function __construct(array $json) } /** - * @return ?string + * @return string|null */ - public function getVci(): ?string + public function getVci(): string|null { return $this->vci; } diff --git a/src/Webpay/TransaccionCompleta/Transaction.php b/src/Webpay/TransaccionCompleta/Transaction.php index cd5c5c5f..70f98c9d 100644 --- a/src/Webpay/TransaccionCompleta/Transaction.php +++ b/src/Webpay/TransaccionCompleta/Transaction.php @@ -39,7 +39,7 @@ class Transaction * @param float $amount * @param string $cardNumber * @param string $cardExpirationDate - * @param ?string $cvv + * @param string|null $cvv * * @throws TransactionCreateException * @throws GuzzleException @@ -52,7 +52,7 @@ public function create( float $amount, string $cardNumber, string $cardExpirationDate, - ?string $cvv = null, + string|null $cvv = null, ) { $payload = [ 'buy_order' => $buyOrder, diff --git a/src/Webpay/WebpayPlus/Responses/MallTransactionStatusResponse.php b/src/Webpay/WebpayPlus/Responses/MallTransactionStatusResponse.php index f49d0f28..3c06c691 100644 --- a/src/Webpay/WebpayPlus/Responses/MallTransactionStatusResponse.php +++ b/src/Webpay/WebpayPlus/Responses/MallTransactionStatusResponse.php @@ -9,14 +9,14 @@ */ class MallTransactionStatusResponse { - public ?string $vci; - public ?string $buyOrder; - public ?string $sessionId; - public ?string $cardNumber; + public string|null $vci; + public string|null $buyOrder; + public string|null $sessionId; + public string|null $cardNumber; public ?array $cardDetail; - public ?string $expirationDate; - public ?string $accountingDate; - public ?string $transactionDate; + public string|null $expirationDate; + public string|null $accountingDate; + public string|null $transactionDate; public ?array $details; /** @@ -62,49 +62,49 @@ public function isApproved(): bool } /** - * @return ?string + * @return string|null */ - public function getBuyOrder(): ?string + public function getBuyOrder(): string|null { return $this->buyOrder; } /** - * @return ?string + * @return string|null */ - public function getSessionId(): ?string + public function getSessionId(): string|null { return $this->sessionId; } /** - * @return ?string + * @return string|null */ - public function getCardNumber(): ?string + public function getCardNumber(): string|null { return $this->cardNumber; } /** - * @return ?string + * @return string|null */ - public function getExpirationDate(): ?string + public function getExpirationDate(): string|null { return $this->expirationDate; } /** - * @return ?string + * @return string|null */ - public function getAccountingDate(): ?string + public function getAccountingDate(): string|null { return $this->accountingDate; } /** - * @return ?string + * @return string|null */ - public function getTransactionDate(): ?string + public function getTransactionDate(): string|null { return $this->transactionDate; } @@ -118,9 +118,9 @@ public function getDetails(): ?array } /** - * @return ?string + * @return string|null */ - public function getVci(): ?string + public function getVci(): string|null { return $this->vci; } diff --git a/src/Webpay/WebpayPlus/Responses/TransactionCaptureResponse.php b/src/Webpay/WebpayPlus/Responses/TransactionCaptureResponse.php index d666e767..e317af6d 100644 --- a/src/Webpay/WebpayPlus/Responses/TransactionCaptureResponse.php +++ b/src/Webpay/WebpayPlus/Responses/TransactionCaptureResponse.php @@ -12,8 +12,8 @@ class TransactionCaptureResponse * * @param array $json */ - public ?string $authorizationCode; - public ?string $authorizationDate; + public string|null $authorizationCode; + public string|null $authorizationDate; public ?float $capturedAmount; public ?int $responseCode; @@ -34,17 +34,17 @@ public function isApproved(): bool } /** - * @return ?string + * @return string|null */ - public function getAuthorizationCode(): ?string + public function getAuthorizationCode(): string|null { return $this->authorizationCode; } /** - * @return ?string + * @return string|null */ - public function getAuthorizationDate(): ?string + public function getAuthorizationDate(): string|null { return $this->authorizationDate; } diff --git a/src/Webpay/WebpayPlus/Responses/TransactionCreateResponse.php b/src/Webpay/WebpayPlus/Responses/TransactionCreateResponse.php index bbf61bb8..ef7e6d46 100644 --- a/src/Webpay/WebpayPlus/Responses/TransactionCreateResponse.php +++ b/src/Webpay/WebpayPlus/Responses/TransactionCreateResponse.php @@ -7,14 +7,14 @@ class TransactionCreateResponse { /** - * @var ?string + * @var string|null */ - public ?string $token; + public string|null $token; /** - * @var ?string + * @var string|null */ - public ?string $url; + public string|null $url; /** * TransactionCreateResponse constructor. @@ -49,17 +49,17 @@ public function fromJSON(array $json) } /** - * @return ?string + * @return string|null */ - public function getToken(): ?string + public function getToken(): string|null { return $this->token; } /** - * @return ?string + * @return string|null */ - public function getUrl(): ?string + public function getUrl(): string|null { return $this->url; } diff --git a/src/Webpay/WebpayPlus/Responses/TransactionDetail.php b/src/Webpay/WebpayPlus/Responses/TransactionDetail.php index 9ce240fa..dcc5f974 100644 --- a/src/Webpay/WebpayPlus/Responses/TransactionDetail.php +++ b/src/Webpay/WebpayPlus/Responses/TransactionDetail.php @@ -9,14 +9,14 @@ class TransactionDetail { public ?float $amount; - public ?string $status; - public ?string $authorizationCode; - public ?string $paymentTypeCode; + public string|null $status; + public string|null $authorizationCode; + public string|null $paymentTypeCode; public ?int $responseCode; public ?int $installmentsNumber; public ?float $installmentsAmount; - public ?string $commerceCode; - public ?string $buyOrder; + public string|null $commerceCode; + public string|null $buyOrder; public ?float $balance; public static function createFromArray(array $array) @@ -66,25 +66,25 @@ public function getAmount(): ?float } /** - * @return ?string + * @return string|null */ - public function getStatus(): ?string + public function getStatus(): string|null { return $this->status; } /** - * @return ?string + * @return string|null */ - public function getAuthorizationCode(): ?string + public function getAuthorizationCode(): string|null { return $this->authorizationCode; } /** - * @return ?string + * @return string|null */ - public function getPaymentTypeCode(): ?string + public function getPaymentTypeCode(): string|null { return $this->paymentTypeCode; } @@ -108,15 +108,15 @@ public function getInstallmentsNumber(): ?int /** * @return ?int */ - public function getCommerceCode(): ?string + public function getCommerceCode(): string|null { return $this->commerceCode; } /** - * @return ?string + * @return string|null */ - public function getBuyOrder(): ?string + public function getBuyOrder(): string|null { return $this->buyOrder; } diff --git a/src/Webpay/WebpayPlus/Responses/TransactionRefundResponse.php b/src/Webpay/WebpayPlus/Responses/TransactionRefundResponse.php index f9ede336..ba50ee86 100644 --- a/src/Webpay/WebpayPlus/Responses/TransactionRefundResponse.php +++ b/src/Webpay/WebpayPlus/Responses/TransactionRefundResponse.php @@ -10,15 +10,15 @@ class TransactionRefundResponse /** * @var string */ - public ?string $type; + public string|null $type; /** - * @var ?string + * @var string|null */ - public ?string $authorizationCode; + public string|null $authorizationCode; /** - * @var ?string + * @var string|null */ - public ?string $authorizationDate; + public string|null $authorizationDate; /** * @var ?float */ @@ -81,25 +81,25 @@ public function getResponseCode(): ?int } /** - * @return ?string + * @return string|null */ - public function getType(): ?string + public function getType(): string|null { return $this->type; } /** - * @return ?string + * @return string|null */ - public function getAuthorizationCode(): ?string + public function getAuthorizationCode(): string|null { return $this->authorizationCode; } /** - * @return ?string + * @return string|null */ - public function getAuthorizationDate(): ?string + public function getAuthorizationDate(): string|null { return $this->authorizationDate; } diff --git a/src/Webpay/WebpayPlus/Responses/TransactionStatusResponse.php b/src/Webpay/WebpayPlus/Responses/TransactionStatusResponse.php index d2d979c9..d689b5bb 100644 --- a/src/Webpay/WebpayPlus/Responses/TransactionStatusResponse.php +++ b/src/Webpay/WebpayPlus/Responses/TransactionStatusResponse.php @@ -10,7 +10,7 @@ class TransactionStatusResponse { use HasTransactionStatus; - public ?string $vci; + public string|null $vci; public function __construct(array $json) { @@ -42,9 +42,9 @@ public function isApproved(): bool } /** - * @return ?string + * @return string|null */ - public function getVci(): ?string + public function getVci(): string|null { return $this->vci; } From 7c3ff89e1429db2a23a2591cdc618204360b0928 Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 3 Jul 2024 13:13:32 -0400 Subject: [PATCH 35/51] refactor: change nullable array type by union types --- src/Contracts/HttpClientInterface.php | 8 ++++---- src/Utils/HasTransactionStatus.php | 6 +++--- src/Utils/HttpClient.php | 10 +++++----- .../Responses/MallTransactionStatusResponse.php | 6 +++--- .../MallTransactionInstallmentsResponse.php | 6 +++--- .../Responses/MallTransactionStatusResponse.php | 12 ++++++------ .../Responses/TransactionInstallmentsResponse.php | 6 +++--- .../Responses/MallTransactionStatusResponse.php | 10 +++++----- 8 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/Contracts/HttpClientInterface.php b/src/Contracts/HttpClientInterface.php index 4e18ef68..5c9a7eef 100644 --- a/src/Contracts/HttpClientInterface.php +++ b/src/Contracts/HttpClientInterface.php @@ -10,8 +10,8 @@ interface HttpClientInterface /** * @param string $method * @param string $url - * @param ?array $payload - * @param ?array $options + * @param array|null $payload + * @param array|null $options * * @throws GuzzleException * @@ -20,7 +20,7 @@ interface HttpClientInterface public function request( string $method, string $url, - ?array $payload = [], - ?array $options = null + array|null $payload = [], + array|null $options = null ): ResponseInterface; } diff --git a/src/Utils/HasTransactionStatus.php b/src/Utils/HasTransactionStatus.php index b0e1d42d..dc2d3fb3 100644 --- a/src/Utils/HasTransactionStatus.php +++ b/src/Utils/HasTransactionStatus.php @@ -15,7 +15,7 @@ trait HasTransactionStatus public string|null $sessionId; public string|null $buyOrder; public string|null $cardNumber; - public ?array $cardDetail; + public array|null $cardDetail; public string|null $transactionDate; public ?float $balance; @@ -97,9 +97,9 @@ public function setTransactionStatusFields(array $json): void } /** - * @return ?array + * @return array|null */ - public function getCardDetail(): ?array + public function getCardDetail(): array|null { return $this->cardDetail; } diff --git a/src/Utils/HttpClient.php b/src/Utils/HttpClient.php index dc2697fc..8947fc72 100644 --- a/src/Utils/HttpClient.php +++ b/src/Utils/HttpClient.php @@ -15,8 +15,8 @@ class HttpClient implements HttpClientInterface /** * @param string $method * @param string $url - * @param ?array $payload - * @param ?array $options + * @param array|null $payload + * @param array|null $options * *@throws GuzzleException * @@ -25,8 +25,8 @@ class HttpClient implements HttpClientInterface public function request( string $method, string $url, - ?array $payload = [], - ?array $options = null + array|null $payload = [], + array|null $options = null ): ResponseInterface { $installedVersion = 'unknown'; @@ -66,7 +66,7 @@ public function request( * @param string $method * @param string $url * @param array $headers - * @param ?array $payload + * @param array|null $payload * @param int $timeout * * @throws GuzzleException diff --git a/src/Webpay/Oneclick/Responses/MallTransactionStatusResponse.php b/src/Webpay/Oneclick/Responses/MallTransactionStatusResponse.php index c4ab9463..56b390b9 100644 --- a/src/Webpay/Oneclick/Responses/MallTransactionStatusResponse.php +++ b/src/Webpay/Oneclick/Responses/MallTransactionStatusResponse.php @@ -7,11 +7,11 @@ class MallTransactionStatusResponse { public string|null $buyOrder; - public ?array $cardDetail; + public array|null $cardDetail; public string|null $cardNumber; public string|null $accountingDate; public string|null $transactionDate; - public ?array $details; + public array|null $details; public function __construct(array $json) { @@ -76,7 +76,7 @@ public function getAccountingDate(): string|null /** * @return ?TransactionDetail[] */ - public function getDetails(): ?array + public function getDetails(): array|null { return $this->details; } diff --git a/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php b/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php index 07c21482..aa06f8c6 100644 --- a/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php @@ -8,7 +8,7 @@ class MallTransactionInstallmentsResponse { public ?float $installmentsAmount; public string|null $idQueryInstallments; - public ?array $deferredPeriods; + public array|null $deferredPeriods; public function __construct(array $json) { @@ -34,9 +34,9 @@ public function getIdQueryInstallments(): string|null } /** - * @return ?array + * @return array|null */ - public function getDeferredPeriods(): ?array + public function getDeferredPeriods(): array|null { return $this->deferredPeriods; } diff --git a/src/Webpay/TransaccionCompleta/Responses/MallTransactionStatusResponse.php b/src/Webpay/TransaccionCompleta/Responses/MallTransactionStatusResponse.php index 02434ece..5b5adea0 100644 --- a/src/Webpay/TransaccionCompleta/Responses/MallTransactionStatusResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/MallTransactionStatusResponse.php @@ -7,11 +7,11 @@ class MallTransactionStatusResponse { protected string|null $buyOrder; - protected ?array $cardDetail; + protected array|null $cardDetail; protected string|null $cardNumber; protected string|null $accountingDate; protected string|null $transactionDate; - protected ?array $details; + protected array|null $details; public function __construct(array $json) { @@ -38,9 +38,9 @@ public function getBuyOrder(): string|null } /** - * @return ?array + * @return array|null */ - public function getCardDetail(): ?array + public function getCardDetail(): array|null { return $this->cardDetail; } @@ -62,9 +62,9 @@ public function getTransactionDate(): string|null } /** - * @return ?array + * @return array|null */ - public function getDetails(): ?array + public function getDetails(): array|null { return $this->details; } diff --git a/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php b/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php index a3649be2..79586438 100644 --- a/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php @@ -8,7 +8,7 @@ class TransactionInstallmentsResponse { public ?float $installmentsAmount; public string|null $idQueryInstallments; - public ?array $deferredPeriods; + public array|null $deferredPeriods; public function __construct(array $json) { @@ -34,9 +34,9 @@ public function getIdQueryInstallments(): string|null } /** - * @return ?array + * @return array|null */ - public function getDeferredPeriods(): ?array + public function getDeferredPeriods(): array|null { return $this->deferredPeriods; } diff --git a/src/Webpay/WebpayPlus/Responses/MallTransactionStatusResponse.php b/src/Webpay/WebpayPlus/Responses/MallTransactionStatusResponse.php index 3c06c691..4f3f6c1f 100644 --- a/src/Webpay/WebpayPlus/Responses/MallTransactionStatusResponse.php +++ b/src/Webpay/WebpayPlus/Responses/MallTransactionStatusResponse.php @@ -13,11 +13,11 @@ class MallTransactionStatusResponse public string|null $buyOrder; public string|null $sessionId; public string|null $cardNumber; - public ?array $cardDetail; + public array|null $cardDetail; public string|null $expirationDate; public string|null $accountingDate; public string|null $transactionDate; - public ?array $details; + public array|null $details; /** * @var TransactionDetail[] @@ -112,7 +112,7 @@ public function getTransactionDate(): string|null /** * @return ?TransactionDetail[] */ - public function getDetails(): ?array + public function getDetails(): array|null { return $this->details; } @@ -126,9 +126,9 @@ public function getVci(): string|null } /** - * @return ?array + * @return array|null */ - public function getCardDetail(): ?array + public function getCardDetail(): array|null { return $this->cardDetail; } From 00f7f544bba6d8273d2a654ca0f78126fbba2b40 Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 3 Jul 2024 13:14:40 -0400 Subject: [PATCH 36/51] refactor: change nullable int type by union types --- src/Utils/HasTransactionStatus.php | 12 ++++++------ src/Webpay/Exceptions/WebpayRequestException.php | 10 +++++----- .../Responses/InscriptionDeleteResponse.php | 8 ++++---- .../Responses/InscriptionFinishResponse.php | 6 +++--- .../Responses/MallTransactionCaptureResponse.php | 6 +++--- .../Responses/MallTransactionRefundResponse.php | 6 +++--- .../Responses/MallTransactionRefundResponse.php | 6 +++--- .../Responses/TransactionDetail.php | 6 +++--- .../Responses/TransactionRefundResponse.php | 6 +++--- src/Webpay/TransaccionCompleta/Transaction.php | 8 ++++---- .../Responses/TransactionCaptureResponse.php | 6 +++--- .../WebpayPlus/Responses/TransactionDetail.php | 14 +++++++------- .../Responses/TransactionRefundResponse.php | 8 ++++---- 13 files changed, 51 insertions(+), 51 deletions(-) diff --git a/src/Utils/HasTransactionStatus.php b/src/Utils/HasTransactionStatus.php index dc2d3fb3..c36dde47 100644 --- a/src/Utils/HasTransactionStatus.php +++ b/src/Utils/HasTransactionStatus.php @@ -5,12 +5,12 @@ trait HasTransactionStatus { public string|null $status; - public ?int $responseCode; + public int|null $responseCode; public ?float $amount; public string|null $authorizationCode; public string|null $paymentTypeCode; public string|null $accountingDate; - public ?int $installmentsNumber; + public int|null $installmentsNumber; public ?float $installmentsAmount; public string|null $sessionId; public string|null $buyOrder; @@ -44,17 +44,17 @@ public function getAuthorizationCode(): string|null } /** - * @return ?int + * @return int|null */ - public function getInstallmentsNumber(): ?int + public function getInstallmentsNumber(): int|null { return $this->installmentsNumber; } /** - * @return ?int + * @return int|null */ - public function getResponseCode(): ?int + public function getResponseCode(): int|null { return $this->responseCode; } diff --git a/src/Webpay/Exceptions/WebpayRequestException.php b/src/Webpay/Exceptions/WebpayRequestException.php index a493a638..5755eda2 100644 --- a/src/Webpay/Exceptions/WebpayRequestException.php +++ b/src/Webpay/Exceptions/WebpayRequestException.php @@ -17,7 +17,7 @@ class WebpayRequestException extends WebpayException */ protected string|null $transbankErrorMessage; /** - * @var ?int + * @var int|null */ protected $httpCode; @@ -36,14 +36,14 @@ class WebpayRequestException extends WebpayException * * @param string $message * @param string|null $tbkErrorMessage - * @param ?int $httpCode + * @param int|null $httpCode * @param ?TransbankApiRequest $failedRequest * @param ?\Exception $previous */ public function __construct( string $message, string|null $tbkErrorMessage = null, - ?int $httpCode = null, + int|null $httpCode = null, ?TransbankApiRequest $failedRequest = null, ?\Exception $previous = null ) { @@ -104,14 +104,14 @@ public function getFailedRequest(): ?TransbankApiRequest /** * @param string $message * @param string|null $tbkErrorMessage - * @param ?int $httpCode + * @param int|null $httpCode * * @return string */ protected function getExceptionMessage( string $message, string|null $tbkErrorMessage, - ?int $httpCode + int|null $httpCode ): string { if (!$tbkErrorMessage) { return $message; diff --git a/src/Webpay/Oneclick/Responses/InscriptionDeleteResponse.php b/src/Webpay/Oneclick/Responses/InscriptionDeleteResponse.php index a450a83f..a8b505b8 100644 --- a/src/Webpay/Oneclick/Responses/InscriptionDeleteResponse.php +++ b/src/Webpay/Oneclick/Responses/InscriptionDeleteResponse.php @@ -5,9 +5,9 @@ class InscriptionDeleteResponse { public bool $success = false; - public ?int $code; + public int|null $code; - public function __construct(bool $success, ?int $httpCode = null) + public function __construct(bool $success, int|null $httpCode = null) { $this->success = $success; $this->code = $httpCode; @@ -19,9 +19,9 @@ public function wasSuccessfull(): bool } /** - * @return ?int + * @return int|null */ - public function getCode(): ?int + public function getCode(): int|null { return $this->code; } diff --git a/src/Webpay/Oneclick/Responses/InscriptionFinishResponse.php b/src/Webpay/Oneclick/Responses/InscriptionFinishResponse.php index af0d201e..6d213c03 100644 --- a/src/Webpay/Oneclick/Responses/InscriptionFinishResponse.php +++ b/src/Webpay/Oneclick/Responses/InscriptionFinishResponse.php @@ -7,7 +7,7 @@ class InscriptionFinishResponse { - public ?int $responseCode; + public int|null $responseCode; public string|null $tbkUser; public string|null $authorizationCode; public string|null $cardType; @@ -28,9 +28,9 @@ public function isApproved(): bool } /** - * @return ?int + * @return int|null */ - public function getResponseCode(): ?int + public function getResponseCode(): int|null { return $this->responseCode; } diff --git a/src/Webpay/Oneclick/Responses/MallTransactionCaptureResponse.php b/src/Webpay/Oneclick/Responses/MallTransactionCaptureResponse.php index e13d3e5f..a0d15b4e 100644 --- a/src/Webpay/Oneclick/Responses/MallTransactionCaptureResponse.php +++ b/src/Webpay/Oneclick/Responses/MallTransactionCaptureResponse.php @@ -9,7 +9,7 @@ class MallTransactionCaptureResponse public string|null $authorizationCode; public string|null $authorizationDate; public ?float $capturedAmount; - public ?int $responseCode; + public int|null $responseCode; public function __construct(array $json) { @@ -44,9 +44,9 @@ public function getCapturedAmount(): ?float } /** - * @return ?int + * @return int|null */ - public function getResponseCode(): ?int + public function getResponseCode(): int|null { return $this->responseCode; } diff --git a/src/Webpay/Oneclick/Responses/MallTransactionRefundResponse.php b/src/Webpay/Oneclick/Responses/MallTransactionRefundResponse.php index a39abb4b..6c128f3b 100644 --- a/src/Webpay/Oneclick/Responses/MallTransactionRefundResponse.php +++ b/src/Webpay/Oneclick/Responses/MallTransactionRefundResponse.php @@ -11,7 +11,7 @@ class MallTransactionRefundResponse public string|null $authorizationDate; public ?float $nullifiedAmount; public ?float $balance; - public ?int $responseCode; + public int|null $responseCode; public function __construct(array $json) { @@ -64,9 +64,9 @@ public function getBalance(): ?float } /** - * @return ?int + * @return int|null */ - public function getResponseCode(): ?int + public function getResponseCode(): int|null { return $this->responseCode; } diff --git a/src/Webpay/TransaccionCompleta/Responses/MallTransactionRefundResponse.php b/src/Webpay/TransaccionCompleta/Responses/MallTransactionRefundResponse.php index 92cef897..ccc1000e 100644 --- a/src/Webpay/TransaccionCompleta/Responses/MallTransactionRefundResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/MallTransactionRefundResponse.php @@ -11,7 +11,7 @@ class MallTransactionRefundResponse public string|null $authorizationDate; public ?float $nullifiedAmount; public ?float $balance; - public ?int $responseCode; + public int|null $responseCode; public function __construct(array $json) { @@ -64,9 +64,9 @@ public function getBalance(): ?float } /** - * @return ?int + * @return int|null */ - public function getResponseCode(): ?int + public function getResponseCode(): int|null { return $this->responseCode; } diff --git a/src/Webpay/TransaccionCompleta/Responses/TransactionDetail.php b/src/Webpay/TransaccionCompleta/Responses/TransactionDetail.php index 9ae3f3e6..2580e9eb 100644 --- a/src/Webpay/TransaccionCompleta/Responses/TransactionDetail.php +++ b/src/Webpay/TransaccionCompleta/Responses/TransactionDetail.php @@ -7,7 +7,7 @@ class TransactionDetail extends BaseTransactionDetail { - public ?int $prepaidBalance; + public int|null $prepaidBalance; /** * Creates an instance of TransactionDetail from an array @@ -35,9 +35,9 @@ public static function createFromArray(array $array) } /** - * @return ?int + * @return int|null */ - public function getPrepaidBalance(): ?int + public function getPrepaidBalance(): int|null { return $this->prepaidBalance; } diff --git a/src/Webpay/TransaccionCompleta/Responses/TransactionRefundResponse.php b/src/Webpay/TransaccionCompleta/Responses/TransactionRefundResponse.php index 3c429780..c4bf2e47 100644 --- a/src/Webpay/TransaccionCompleta/Responses/TransactionRefundResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/TransactionRefundResponse.php @@ -11,7 +11,7 @@ class TransactionRefundResponse public string|null $authorizationDate; public ?float $nullifiedAmount; public ?float $balance; - public ?int $responseCode; + public int|null $responseCode; public function __construct(array $json) { @@ -64,9 +64,9 @@ public function getBalance(): ?float } /** - * @return ?int + * @return int|null */ - public function getResponseCode(): ?int + public function getResponseCode(): int|null { return $this->responseCode; } diff --git a/src/Webpay/TransaccionCompleta/Transaction.php b/src/Webpay/TransaccionCompleta/Transaction.php index 70f98c9d..8de8d397 100644 --- a/src/Webpay/TransaccionCompleta/Transaction.php +++ b/src/Webpay/TransaccionCompleta/Transaction.php @@ -114,8 +114,8 @@ public function installments( /** * @param string $token - * @param ?int $idQueryInstallments - * @param ?int $deferredPeriodIndex + * @param int|null $idQueryInstallments + * @param int|null $deferredPeriodIndex * @param ?bool $gracePeriod * * @throws TransactionCommitException @@ -125,8 +125,8 @@ public function installments( */ public function commit( string $token, - ?int $idQueryInstallments = null, - ?int $deferredPeriodIndex = null, + int|null $idQueryInstallments = null, + int|null $deferredPeriodIndex = null, ?bool $gracePeriod = null ) { $payload = [ diff --git a/src/Webpay/WebpayPlus/Responses/TransactionCaptureResponse.php b/src/Webpay/WebpayPlus/Responses/TransactionCaptureResponse.php index e317af6d..b36619f1 100644 --- a/src/Webpay/WebpayPlus/Responses/TransactionCaptureResponse.php +++ b/src/Webpay/WebpayPlus/Responses/TransactionCaptureResponse.php @@ -15,7 +15,7 @@ class TransactionCaptureResponse public string|null $authorizationCode; public string|null $authorizationDate; public ?float $capturedAmount; - public ?int $responseCode; + public int|null $responseCode; public function __construct(array $json) { @@ -58,9 +58,9 @@ public function getCapturedAmount(): ?float } /** - * @return ?int + * @return int|null */ - public function getResponseCode(): ?int + public function getResponseCode(): int|null { return $this->responseCode; } diff --git a/src/Webpay/WebpayPlus/Responses/TransactionDetail.php b/src/Webpay/WebpayPlus/Responses/TransactionDetail.php index dcc5f974..e1b8ccc6 100644 --- a/src/Webpay/WebpayPlus/Responses/TransactionDetail.php +++ b/src/Webpay/WebpayPlus/Responses/TransactionDetail.php @@ -12,8 +12,8 @@ class TransactionDetail public string|null $status; public string|null $authorizationCode; public string|null $paymentTypeCode; - public ?int $responseCode; - public ?int $installmentsNumber; + public int|null $responseCode; + public int|null $installmentsNumber; public ?float $installmentsAmount; public string|null $commerceCode; public string|null $buyOrder; @@ -90,23 +90,23 @@ public function getPaymentTypeCode(): string|null } /** - * @return ?int + * @return int|null */ - public function getResponseCode(): ?int + public function getResponseCode(): int|null { return $this->responseCode; } /** - * @return ?int + * @return int|null */ - public function getInstallmentsNumber(): ?int + public function getInstallmentsNumber(): int|null { return $this->installmentsNumber; } /** - * @return ?int + * @return int|null */ public function getCommerceCode(): string|null { diff --git a/src/Webpay/WebpayPlus/Responses/TransactionRefundResponse.php b/src/Webpay/WebpayPlus/Responses/TransactionRefundResponse.php index ba50ee86..b5ff8d31 100644 --- a/src/Webpay/WebpayPlus/Responses/TransactionRefundResponse.php +++ b/src/Webpay/WebpayPlus/Responses/TransactionRefundResponse.php @@ -28,9 +28,9 @@ class TransactionRefundResponse */ public ?float $balance; /** - * @var ?int + * @var int|null */ - public ?int $responseCode; + public int|null $responseCode; /** * TransactionRefundResponse constructor. @@ -73,9 +73,9 @@ public function getBalance(): ?float } /** - * @return ?int + * @return int|null */ - public function getResponseCode(): ?int + public function getResponseCode(): int|null { return $this->responseCode; } From 0f2574aa6a045e8d97c8d8578ddde5f09f7ad7ad Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 3 Jul 2024 13:17:39 -0400 Subject: [PATCH 37/51] refactor: change nullable float type by union types --- src/Utils/HasTransactionStatus.php | 18 +++++++++--------- .../MallTransactionCaptureResponse.php | 6 +++--- .../MallTransactionRefundResponse.php | 12 ++++++------ .../MallTransactionInstallmentsResponse.php | 6 +++--- .../MallTransactionRefundResponse.php | 12 ++++++------ .../TransactionInstallmentsResponse.php | 6 +++--- .../Responses/TransactionRefundResponse.php | 12 ++++++------ .../Responses/TransactionStatusResponse.php | 6 +++--- .../Responses/TransactionCaptureResponse.php | 6 +++--- .../WebpayPlus/Responses/TransactionDetail.php | 18 +++++++++--------- .../Responses/TransactionRefundResponse.php | 16 ++++++++-------- 11 files changed, 59 insertions(+), 59 deletions(-) diff --git a/src/Utils/HasTransactionStatus.php b/src/Utils/HasTransactionStatus.php index c36dde47..c5a3a358 100644 --- a/src/Utils/HasTransactionStatus.php +++ b/src/Utils/HasTransactionStatus.php @@ -6,23 +6,23 @@ trait HasTransactionStatus { public string|null $status; public int|null $responseCode; - public ?float $amount; + public float|null $amount; public string|null $authorizationCode; public string|null $paymentTypeCode; public string|null $accountingDate; public int|null $installmentsNumber; - public ?float $installmentsAmount; + public float|null $installmentsAmount; public string|null $sessionId; public string|null $buyOrder; public string|null $cardNumber; public array|null $cardDetail; public string|null $transactionDate; - public ?float $balance; + public float|null $balance; /** - * @return ?float + * @return float|null */ - public function getBalance(): ?float + public function getBalance(): float|null { return $this->balance; } @@ -121,9 +121,9 @@ public function getPaymentTypeCode(): string|null } /** - * @return ?float + * @return float|null */ - public function getInstallmentsAmount(): ?float + public function getInstallmentsAmount(): float|null { return $this->installmentsAmount; } @@ -137,9 +137,9 @@ public function getSessionId(): string|null } /** - * @return ?float + * @return float|null */ - public function getAmount(): ?float + public function getAmount(): float|null { return $this->amount; } diff --git a/src/Webpay/Oneclick/Responses/MallTransactionCaptureResponse.php b/src/Webpay/Oneclick/Responses/MallTransactionCaptureResponse.php index a0d15b4e..09754971 100644 --- a/src/Webpay/Oneclick/Responses/MallTransactionCaptureResponse.php +++ b/src/Webpay/Oneclick/Responses/MallTransactionCaptureResponse.php @@ -8,7 +8,7 @@ class MallTransactionCaptureResponse { public string|null $authorizationCode; public string|null $authorizationDate; - public ?float $capturedAmount; + public float|null $capturedAmount; public int|null $responseCode; public function __construct(array $json) @@ -36,9 +36,9 @@ public function getAuthorizationDate(): string|null } /** - * @return ?float + * @return float|null */ - public function getCapturedAmount(): ?float + public function getCapturedAmount(): float|null { return $this->capturedAmount; } diff --git a/src/Webpay/Oneclick/Responses/MallTransactionRefundResponse.php b/src/Webpay/Oneclick/Responses/MallTransactionRefundResponse.php index 6c128f3b..ec94a03a 100644 --- a/src/Webpay/Oneclick/Responses/MallTransactionRefundResponse.php +++ b/src/Webpay/Oneclick/Responses/MallTransactionRefundResponse.php @@ -9,8 +9,8 @@ class MallTransactionRefundResponse public string|null $type; public string|null $authorizationCode; public string|null $authorizationDate; - public ?float $nullifiedAmount; - public ?float $balance; + public float|null $nullifiedAmount; + public float|null $balance; public int|null $responseCode; public function __construct(array $json) @@ -48,17 +48,17 @@ public function getAuthorizationDate(): string|null } /** - * @return ?float + * @return float|null */ - public function getNullifiedAmount(): ?float + public function getNullifiedAmount(): float|null { return $this->nullifiedAmount; } /** - * @return ?float + * @return float|null */ - public function getBalance(): ?float + public function getBalance(): float|null { return $this->balance; } diff --git a/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php b/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php index aa06f8c6..cd1b2a0f 100644 --- a/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php @@ -6,7 +6,7 @@ class MallTransactionInstallmentsResponse { - public ?float $installmentsAmount; + public float|null $installmentsAmount; public string|null $idQueryInstallments; public array|null $deferredPeriods; @@ -18,9 +18,9 @@ public function __construct(array $json) } /** - * @return ?float + * @return float|null */ - public function getInstallmentsAmount(): ?float + public function getInstallmentsAmount(): float|null { return $this->installmentsAmount; } diff --git a/src/Webpay/TransaccionCompleta/Responses/MallTransactionRefundResponse.php b/src/Webpay/TransaccionCompleta/Responses/MallTransactionRefundResponse.php index ccc1000e..d2fc2f82 100644 --- a/src/Webpay/TransaccionCompleta/Responses/MallTransactionRefundResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/MallTransactionRefundResponse.php @@ -9,8 +9,8 @@ class MallTransactionRefundResponse public string|null $type; public string|null $authorizationCode; public string|null $authorizationDate; - public ?float $nullifiedAmount; - public ?float $balance; + public float|null $nullifiedAmount; + public float|null $balance; public int|null $responseCode; public function __construct(array $json) @@ -48,17 +48,17 @@ public function getAuthorizationDate(): string|null } /** - * @return ?float + * @return float|null */ - public function getNullifiedAmount(): ?float + public function getNullifiedAmount(): float|null { return $this->nullifiedAmount; } /** - * @return ?float + * @return float|null */ - public function getBalance(): ?float + public function getBalance(): float|null { return $this->balance; } diff --git a/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php b/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php index 79586438..650bd3b2 100644 --- a/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php @@ -6,7 +6,7 @@ class TransactionInstallmentsResponse { - public ?float $installmentsAmount; + public float|null $installmentsAmount; public string|null $idQueryInstallments; public array|null $deferredPeriods; @@ -18,9 +18,9 @@ public function __construct(array $json) } /** - * @return ?float + * @return float|null */ - public function getInstallmentsAmount(): ?float + public function getInstallmentsAmount(): float|null { return $this->installmentsAmount; } diff --git a/src/Webpay/TransaccionCompleta/Responses/TransactionRefundResponse.php b/src/Webpay/TransaccionCompleta/Responses/TransactionRefundResponse.php index c4bf2e47..d6625df0 100644 --- a/src/Webpay/TransaccionCompleta/Responses/TransactionRefundResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/TransactionRefundResponse.php @@ -9,8 +9,8 @@ class TransactionRefundResponse public string|null $type; public string|null $authorizationCode; public string|null $authorizationDate; - public ?float $nullifiedAmount; - public ?float $balance; + public float|null $nullifiedAmount; + public float|null $balance; public int|null $responseCode; public function __construct(array $json) @@ -48,17 +48,17 @@ public function getAuthorizationDate(): string|null } /** - * @return ?float + * @return float|null */ - public function getNullifiedAmount(): ?float + public function getNullifiedAmount(): float|null { return $this->nullifiedAmount; } /** - * @return ?float + * @return float|null */ - public function getBalance(): ?float + public function getBalance(): float|null { return $this->balance; } diff --git a/src/Webpay/TransaccionCompleta/Responses/TransactionStatusResponse.php b/src/Webpay/TransaccionCompleta/Responses/TransactionStatusResponse.php index 982b7abb..ecab5f04 100644 --- a/src/Webpay/TransaccionCompleta/Responses/TransactionStatusResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/TransactionStatusResponse.php @@ -10,7 +10,7 @@ class TransactionStatusResponse use HasTransactionStatus; public string|null $vci; - public ?float $prepaidBalance; + public float|null $prepaidBalance; public function __construct(array $json) { @@ -28,9 +28,9 @@ public function getVci(): string|null } /** - * @return ?float + * @return float|null */ - public function getPrepaidBalance(): ?float + public function getPrepaidBalance(): float|null { return $this->prepaidBalance; } diff --git a/src/Webpay/WebpayPlus/Responses/TransactionCaptureResponse.php b/src/Webpay/WebpayPlus/Responses/TransactionCaptureResponse.php index b36619f1..2f354560 100644 --- a/src/Webpay/WebpayPlus/Responses/TransactionCaptureResponse.php +++ b/src/Webpay/WebpayPlus/Responses/TransactionCaptureResponse.php @@ -14,7 +14,7 @@ class TransactionCaptureResponse */ public string|null $authorizationCode; public string|null $authorizationDate; - public ?float $capturedAmount; + public float|null $capturedAmount; public int|null $responseCode; public function __construct(array $json) @@ -50,9 +50,9 @@ public function getAuthorizationDate(): string|null } /** - * @return ?float + * @return float|null */ - public function getCapturedAmount(): ?float + public function getCapturedAmount(): float|null { return $this->capturedAmount; } diff --git a/src/Webpay/WebpayPlus/Responses/TransactionDetail.php b/src/Webpay/WebpayPlus/Responses/TransactionDetail.php index e1b8ccc6..c2c0d0c8 100644 --- a/src/Webpay/WebpayPlus/Responses/TransactionDetail.php +++ b/src/Webpay/WebpayPlus/Responses/TransactionDetail.php @@ -8,16 +8,16 @@ class TransactionDetail { - public ?float $amount; + public float|null $amount; public string|null $status; public string|null $authorizationCode; public string|null $paymentTypeCode; public int|null $responseCode; public int|null $installmentsNumber; - public ?float $installmentsAmount; + public float|null $installmentsAmount; public string|null $commerceCode; public string|null $buyOrder; - public ?float $balance; + public float|null $balance; public static function createFromArray(array $array) { @@ -58,9 +58,9 @@ public function isApproved(): bool } /** - * @return ?float + * @return float|null */ - public function getAmount(): ?float + public function getAmount(): float|null { return $this->amount; } @@ -122,17 +122,17 @@ public function getBuyOrder(): string|null } /** - * @return ?float + * @return float|null */ - public function getInstallmentsAmount(): ?float + public function getInstallmentsAmount(): float|null { return $this->installmentsAmount; } /** - * @return ?float + * @return float|null */ - public function getBalance(): ?float + public function getBalance(): float|null { return $this->balance; } diff --git a/src/Webpay/WebpayPlus/Responses/TransactionRefundResponse.php b/src/Webpay/WebpayPlus/Responses/TransactionRefundResponse.php index b5ff8d31..ceefa039 100644 --- a/src/Webpay/WebpayPlus/Responses/TransactionRefundResponse.php +++ b/src/Webpay/WebpayPlus/Responses/TransactionRefundResponse.php @@ -20,13 +20,13 @@ class TransactionRefundResponse */ public string|null $authorizationDate; /** - * @var ?float + * @var float|null */ - public ?float $nullifiedAmount; + public float|null $nullifiedAmount; /** - * @var ?float + * @var float|null */ - public ?float $balance; + public float|null $balance; /** * @var int|null */ @@ -57,17 +57,17 @@ public function success(): bool } /** - * @return ?float + * @return float|null */ - public function getNullifiedAmount(): ?float + public function getNullifiedAmount(): float|null { return $this->nullifiedAmount; } /** - * @return ?float + * @return float|null */ - public function getBalance(): ?float + public function getBalance(): float|null { return $this->balance; } From f80f1c3315946308d77f06e6d969f8ffa9e14b9a Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 3 Jul 2024 13:18:38 -0400 Subject: [PATCH 38/51] refactor: change nullable ResponseInterface type by union types --- src/Contracts/RequestService.php | 2 +- src/Utils/HttpClientRequestService.php | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Contracts/RequestService.php b/src/Contracts/RequestService.php index 6346957f..cdd648bf 100644 --- a/src/Contracts/RequestService.php +++ b/src/Contracts/RequestService.php @@ -25,6 +25,6 @@ public function request( array $payload, Options $options ): array; - public function getLastResponse(): ?ResponseInterface; + public function getLastResponse(): ResponseInterface|null; public function getLastRequest(): ?TransbankApiRequest; } diff --git a/src/Utils/HttpClientRequestService.php b/src/Utils/HttpClientRequestService.php index ea2284ed..1ddde66d 100644 --- a/src/Utils/HttpClientRequestService.php +++ b/src/Utils/HttpClientRequestService.php @@ -13,9 +13,9 @@ class HttpClientRequestService implements RequestService { /** - * @var ?ResponseInterface + * @var ResponseInterface|null */ - protected ?ResponseInterface $lastResponse = null; + protected ResponseInterface|null $lastResponse = null; /** * @var ?TransbankApiRequest @@ -98,17 +98,17 @@ public function request( } /** - * @return ?ResponseInterface + * @return ResponseInterface|null */ - public function getLastResponse(): ?ResponseInterface + public function getLastResponse(): ResponseInterface|null { return $this->lastResponse; } /** - * @param ?ResponseInterface $lastResponse + * @param ResponseInterface|null $lastResponse */ - protected function setLastResponse(?ResponseInterface $lastResponse): void + protected function setLastResponse(ResponseInterface|null $lastResponse): void { $this->lastResponse = $lastResponse; } From 8f37497d66ce7c26767e35d7c8993bc460f3d4a6 Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 3 Jul 2024 13:19:22 -0400 Subject: [PATCH 39/51] refactor: change nullable TransbankApiRequest type by union types --- src/Contracts/RequestService.php | 2 +- src/Utils/HttpClientRequestService.php | 12 ++++++------ src/Webpay/Exceptions/WebpayRequestException.php | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Contracts/RequestService.php b/src/Contracts/RequestService.php index cdd648bf..0a06a226 100644 --- a/src/Contracts/RequestService.php +++ b/src/Contracts/RequestService.php @@ -26,5 +26,5 @@ public function request( Options $options ): array; public function getLastResponse(): ResponseInterface|null; - public function getLastRequest(): ?TransbankApiRequest; + public function getLastRequest(): TransbankApiRequest|null; } diff --git a/src/Utils/HttpClientRequestService.php b/src/Utils/HttpClientRequestService.php index 1ddde66d..aa07c7a4 100644 --- a/src/Utils/HttpClientRequestService.php +++ b/src/Utils/HttpClientRequestService.php @@ -18,9 +18,9 @@ class HttpClientRequestService implements RequestService protected ResponseInterface|null $lastResponse = null; /** - * @var ?TransbankApiRequest + * @var TransbankApiRequest|null */ - protected ?TransbankApiRequest $lastRequest = null; + protected TransbankApiRequest|null $lastRequest = null; /** * @var HttpClientInterface @@ -114,17 +114,17 @@ protected function setLastResponse(ResponseInterface|null $lastResponse): void } /** - * @return ?TransbankApiRequest + * @return TransbankApiRequest|null */ - public function getLastRequest(): ?TransbankApiRequest + public function getLastRequest(): TransbankApiRequest|null { return $this->lastRequest; } /** - * @param ?TransbankApiRequest $lastRequest + * @param TransbankApiRequest|null $lastRequest */ - protected function setLastRequest(?TransbankApiRequest $lastRequest): void + protected function setLastRequest(TransbankApiRequest|null $lastRequest): void { $this->lastRequest = $lastRequest; } diff --git a/src/Webpay/Exceptions/WebpayRequestException.php b/src/Webpay/Exceptions/WebpayRequestException.php index 5755eda2..93fb3cfc 100644 --- a/src/Webpay/Exceptions/WebpayRequestException.php +++ b/src/Webpay/Exceptions/WebpayRequestException.php @@ -27,9 +27,9 @@ class WebpayRequestException extends WebpayException protected $response; /** - * @var ?TransbankApiRequest + * @var TransbankApiRequest|null */ - protected ?TransbankApiRequest $failedRequest; + protected TransbankApiRequest|null $failedRequest; /** * WebpayRequestException constructor. @@ -37,14 +37,14 @@ class WebpayRequestException extends WebpayException * @param string $message * @param string|null $tbkErrorMessage * @param int|null $httpCode - * @param ?TransbankApiRequest $failedRequest + * @param TransbankApiRequest|null $failedRequest * @param ?\Exception $previous */ public function __construct( string $message, string|null $tbkErrorMessage = null, int|null $httpCode = null, - ?TransbankApiRequest $failedRequest = null, + TransbankApiRequest|null $failedRequest = null, ?\Exception $previous = null ) { $theMessage = $tbkErrorMessage ?? $message; @@ -94,9 +94,9 @@ public function getHttpCode(): int } /** - * @return ?TransbankApiRequest + * @return TransbankApiRequest|null */ - public function getFailedRequest(): ?TransbankApiRequest + public function getFailedRequest(): TransbankApiRequest|null { return $this->failedRequest; } From ea6048a2e35a4bcb821b1de74f7f84449ed06171 Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 3 Jul 2024 13:28:06 -0400 Subject: [PATCH 40/51] refactor: change nullable HttpClientInterface type by union types --- src/Utils/HttpClientRequestService.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Utils/HttpClientRequestService.php b/src/Utils/HttpClientRequestService.php index aa07c7a4..5565d1e8 100644 --- a/src/Utils/HttpClientRequestService.php +++ b/src/Utils/HttpClientRequestService.php @@ -23,11 +23,11 @@ class HttpClientRequestService implements RequestService protected TransbankApiRequest|null $lastRequest = null; /** - * @var HttpClientInterface + * @var HttpClientInterface|null */ - protected ?HttpClientInterface $httpClient; + protected HttpClientInterface|null $httpClient; - public function __construct(?HttpClientInterface $httpClient = null) + public function __construct(HttpClientInterface|null $httpClient = null) { $this->setHttpClient($httpClient ?? new HttpClient()); } From 56fd2ce827ee9a0a65de489f00c82db56d583283 Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 3 Jul 2024 13:29:21 -0400 Subject: [PATCH 41/51] refactor: change nullable RequestService type by union types --- src/PatpassComercio/Inscription.php | 4 ++-- src/Utils/InteractsWithWebpayApi.php | 4 ++-- src/Utils/RequestServiceTrait.php | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/PatpassComercio/Inscription.php b/src/PatpassComercio/Inscription.php index 40f5a04d..bea2c1df 100644 --- a/src/PatpassComercio/Inscription.php +++ b/src/PatpassComercio/Inscription.php @@ -34,11 +34,11 @@ class Inscription * Transaction constructor. * * @param Options $options - * @param ?RequestService $requestService + * @param RequestService|null $requestService */ public function __construct( Options $options, - ?RequestService $requestService = null + RequestService|null $requestService = null ) { $this->options = $options; $this->setRequestService($requestService !== null ? $requestService : diff --git a/src/Utils/InteractsWithWebpayApi.php b/src/Utils/InteractsWithWebpayApi.php index ad635c1c..74e8ee96 100644 --- a/src/Utils/InteractsWithWebpayApi.php +++ b/src/Utils/InteractsWithWebpayApi.php @@ -21,11 +21,11 @@ trait InteractsWithWebpayApi * Transaction constructor. * * @param Options $options - * @param ?RequestService $requestService + * @param RequestService|null $requestService */ public function __construct( Options $options, - ?RequestService $requestService = null + RequestService|null $requestService = null ) { $this->options = $options; diff --git a/src/Utils/RequestServiceTrait.php b/src/Utils/RequestServiceTrait.php index 223cd13c..a58bb488 100644 --- a/src/Utils/RequestServiceTrait.php +++ b/src/Utils/RequestServiceTrait.php @@ -12,9 +12,9 @@ trait RequestServiceTrait { /** - * @var ?RequestService + * @var RequestService|null */ - protected ?RequestService $requestService = null; + protected RequestService|null $requestService = null; /** * @param string $method @@ -36,17 +36,17 @@ public function sendRequest(string $method, string $endpoint, array $payload = [ } /** - * @return ?RequestService + * @return RequestService|null */ - public function getRequestService(): ?RequestService + public function getRequestService(): RequestService|null { return $this->requestService; } /** - * @param ?RequestService $requestService + * @param RequestService|null $requestService */ - public function setRequestService(?RequestService $requestService = null): void + public function setRequestService(RequestService|null $requestService = null): void { $this->requestService = $requestService; } From e018657573e8e642280205a1c51aedd35e807268 Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 3 Jul 2024 13:30:25 -0400 Subject: [PATCH 42/51] refactor: change nullable Throwable type by union types --- src/Webpay/Exceptions/TransbankException.php | 4 ++-- src/Webpay/Exceptions/WebpayException.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Webpay/Exceptions/TransbankException.php b/src/Webpay/Exceptions/TransbankException.php index 7abe9d86..17aeec51 100644 --- a/src/Webpay/Exceptions/TransbankException.php +++ b/src/Webpay/Exceptions/TransbankException.php @@ -11,9 +11,9 @@ class TransbankException extends \Exception * * @param string $message * @param int $code - * @param ?\Throwable $previous + * @param \Throwable|null $previous */ - public function __construct(string $message = self::DEFAULT_MESSAGE, int $code = 0, ?\Throwable $previous = null) + public function __construct(string $message = self::DEFAULT_MESSAGE, int $code = 0, \Throwable|null $previous = null) { parent::__construct($message, $code, $previous); } diff --git a/src/Webpay/Exceptions/WebpayException.php b/src/Webpay/Exceptions/WebpayException.php index 2451ef3f..f5351e3a 100644 --- a/src/Webpay/Exceptions/WebpayException.php +++ b/src/Webpay/Exceptions/WebpayException.php @@ -18,7 +18,7 @@ class WebpayException extends \Exception * @param int $code * @param \Throwable|null $previous */ - public function __construct(string $message = self::DEFAULT_MESSAGE, int $code = 0, ?\Throwable $previous = null) + public function __construct(string $message = self::DEFAULT_MESSAGE, int $code = 0, \Throwable|null $previous = null) { parent::__construct($message, $code, $previous); } From a3d1069ab51180e49f3e93cd0c642eaa7bde9051 Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 3 Jul 2024 13:31:35 -0400 Subject: [PATCH 43/51] refactor: change nullable Exception type by union types --- src/Webpay/Exceptions/WebpayRequestException.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Webpay/Exceptions/WebpayRequestException.php b/src/Webpay/Exceptions/WebpayRequestException.php index 93fb3cfc..525d69f4 100644 --- a/src/Webpay/Exceptions/WebpayRequestException.php +++ b/src/Webpay/Exceptions/WebpayRequestException.php @@ -34,18 +34,18 @@ class WebpayRequestException extends WebpayException /** * WebpayRequestException constructor. * - * @param string $message + * @param string $message * @param string|null $tbkErrorMessage * @param int|null $httpCode * @param TransbankApiRequest|null $failedRequest - * @param ?\Exception $previous + * @param \Exception|null $previous */ public function __construct( string $message, string|null $tbkErrorMessage = null, int|null $httpCode = null, TransbankApiRequest|null $failedRequest = null, - ?\Exception $previous = null + \Exception|null $previous = null ) { $theMessage = $tbkErrorMessage ?? $message; From 9d7ae6914d89877213591d22eba6477e81a2b6d6 Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 3 Jul 2024 13:32:37 -0400 Subject: [PATCH 44/51] refactor: change nullable bool type by union types --- src/Webpay/TransaccionCompleta/Transaction.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Webpay/TransaccionCompleta/Transaction.php b/src/Webpay/TransaccionCompleta/Transaction.php index 8de8d397..c8b9d08b 100644 --- a/src/Webpay/TransaccionCompleta/Transaction.php +++ b/src/Webpay/TransaccionCompleta/Transaction.php @@ -116,7 +116,7 @@ public function installments( * @param string $token * @param int|null $idQueryInstallments * @param int|null $deferredPeriodIndex - * @param ?bool $gracePeriod + * @param bool|null $gracePeriod * * @throws TransactionCommitException * @throws GuzzleException @@ -127,7 +127,7 @@ public function commit( string $token, int|null $idQueryInstallments = null, int|null $deferredPeriodIndex = null, - ?bool $gracePeriod = null + bool|null $gracePeriod = null ) { $payload = [ 'id_query_installments' => $idQueryInstallments, From 49962258571f4ea437162c4399f1150d30618ee8 Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 3 Jul 2024 13:34:56 -0400 Subject: [PATCH 45/51] refactor: change nullable TransactionDetail type by union types --- src/Webpay/Oneclick/Responses/MallTransactionStatusResponse.php | 2 +- .../WebpayPlus/Responses/MallTransactionStatusResponse.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Webpay/Oneclick/Responses/MallTransactionStatusResponse.php b/src/Webpay/Oneclick/Responses/MallTransactionStatusResponse.php index 56b390b9..113fd6ee 100644 --- a/src/Webpay/Oneclick/Responses/MallTransactionStatusResponse.php +++ b/src/Webpay/Oneclick/Responses/MallTransactionStatusResponse.php @@ -74,7 +74,7 @@ public function getAccountingDate(): string|null } /** - * @return ?TransactionDetail[] + * @return TransactionDetail[]|null */ public function getDetails(): array|null { diff --git a/src/Webpay/WebpayPlus/Responses/MallTransactionStatusResponse.php b/src/Webpay/WebpayPlus/Responses/MallTransactionStatusResponse.php index 4f3f6c1f..3fc18c44 100644 --- a/src/Webpay/WebpayPlus/Responses/MallTransactionStatusResponse.php +++ b/src/Webpay/WebpayPlus/Responses/MallTransactionStatusResponse.php @@ -110,7 +110,7 @@ public function getTransactionDate(): string|null } /** - * @return ?TransactionDetail[] + * @return TransactionDetail[]|null */ public function getDetails(): array|null { From c2e581f397cb98f099092223c65b0e480b9b4bc0 Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 3 Jul 2024 13:35:37 -0400 Subject: [PATCH 46/51] refactor: change int type to float in prepaid balance --- .../TransaccionCompleta/Responses/TransactionDetail.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Webpay/TransaccionCompleta/Responses/TransactionDetail.php b/src/Webpay/TransaccionCompleta/Responses/TransactionDetail.php index 2580e9eb..a1774ed9 100644 --- a/src/Webpay/TransaccionCompleta/Responses/TransactionDetail.php +++ b/src/Webpay/TransaccionCompleta/Responses/TransactionDetail.php @@ -7,7 +7,7 @@ class TransactionDetail extends BaseTransactionDetail { - public int|null $prepaidBalance; + public float|null $prepaidBalance; /** * Creates an instance of TransactionDetail from an array @@ -35,9 +35,9 @@ public static function createFromArray(array $array) } /** - * @return int|null + * @return float|null */ - public function getPrepaidBalance(): int|null + public function getPrepaidBalance(): float|null { return $this->prepaidBalance; } From bbaa77a17ce69036312ee2dbe202911b770f9c41 Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 3 Jul 2024 13:41:37 -0400 Subject: [PATCH 47/51] refactor: change int type by string in docphp for webpayplus transaction detail --- src/Webpay/WebpayPlus/Responses/TransactionDetail.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Webpay/WebpayPlus/Responses/TransactionDetail.php b/src/Webpay/WebpayPlus/Responses/TransactionDetail.php index c2c0d0c8..4a24896e 100644 --- a/src/Webpay/WebpayPlus/Responses/TransactionDetail.php +++ b/src/Webpay/WebpayPlus/Responses/TransactionDetail.php @@ -106,7 +106,7 @@ public function getInstallmentsNumber(): int|null } /** - * @return int|null + * @return string|null */ public function getCommerceCode(): string|null { From e785b00f063fb4f435630949e98a8781b179f931 Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 3 Jul 2024 13:52:14 -0400 Subject: [PATCH 48/51] refactor: change casting type for captureAmount --- src/Webpay/TransaccionCompleta/MallTransaction.php | 2 +- src/Webpay/TransaccionCompleta/Transaction.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Webpay/TransaccionCompleta/MallTransaction.php b/src/Webpay/TransaccionCompleta/MallTransaction.php index d150db66..368100ac 100644 --- a/src/Webpay/TransaccionCompleta/MallTransaction.php +++ b/src/Webpay/TransaccionCompleta/MallTransaction.php @@ -241,7 +241,7 @@ public function capture( 'buy_order' => $buyOrder, 'commerce_code' => $commerceCode, 'authorization_code' => $authorizationCode, - 'capture_amount' => (int) $captureAmount, + 'capture_amount' => (float) $captureAmount, ]; try { diff --git a/src/Webpay/TransaccionCompleta/Transaction.php b/src/Webpay/TransaccionCompleta/Transaction.php index c8b9d08b..d663bce0 100644 --- a/src/Webpay/TransaccionCompleta/Transaction.php +++ b/src/Webpay/TransaccionCompleta/Transaction.php @@ -229,7 +229,7 @@ public function capture(string $token, string $buyOrder, string $authorizationCo $payload = [ 'buy_order' => $buyOrder, 'authorization_code' => $authorizationCode, - 'capture_amount' => (int) $captureAmount, + 'capture_amount' => (float) $captureAmount, ]; try { From 3333db212458a2cc19b51dc09e6f0f61963ec921 Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 3 Jul 2024 17:04:56 -0400 Subject: [PATCH 49/51] refactor: change nullable float by int flot and null type --- src/Utils/HasTransactionStatus.php | 18 +++++++++--------- .../MallTransactionCaptureResponse.php | 6 +++--- .../MallTransactionRefundResponse.php | 12 ++++++------ .../MallTransactionInstallmentsResponse.php | 6 +++--- .../MallTransactionRefundResponse.php | 12 ++++++------ .../Responses/TransactionDetail.php | 6 +++--- .../TransactionInstallmentsResponse.php | 6 +++--- .../Responses/TransactionRefundResponse.php | 12 ++++++------ .../Responses/TransactionStatusResponse.php | 6 +++--- .../Responses/TransactionCaptureResponse.php | 6 +++--- .../WebpayPlus/Responses/TransactionDetail.php | 18 +++++++++--------- .../Responses/TransactionRefundResponse.php | 16 ++++++++-------- 12 files changed, 62 insertions(+), 62 deletions(-) diff --git a/src/Utils/HasTransactionStatus.php b/src/Utils/HasTransactionStatus.php index c5a3a358..626c6d43 100644 --- a/src/Utils/HasTransactionStatus.php +++ b/src/Utils/HasTransactionStatus.php @@ -6,23 +6,23 @@ trait HasTransactionStatus { public string|null $status; public int|null $responseCode; - public float|null $amount; + public int|float|null $amount; public string|null $authorizationCode; public string|null $paymentTypeCode; public string|null $accountingDate; public int|null $installmentsNumber; - public float|null $installmentsAmount; + public int|float|null $installmentsAmount; public string|null $sessionId; public string|null $buyOrder; public string|null $cardNumber; public array|null $cardDetail; public string|null $transactionDate; - public float|null $balance; + public int|float|null $balance; /** - * @return float|null + * @return int|float|null */ - public function getBalance(): float|null + public function getBalance(): int|float|null { return $this->balance; } @@ -121,9 +121,9 @@ public function getPaymentTypeCode(): string|null } /** - * @return float|null + * @return int|float|null */ - public function getInstallmentsAmount(): float|null + public function getInstallmentsAmount(): int|float|null { return $this->installmentsAmount; } @@ -137,9 +137,9 @@ public function getSessionId(): string|null } /** - * @return float|null + * @return int|float|null */ - public function getAmount(): float|null + public function getAmount(): int|float|null { return $this->amount; } diff --git a/src/Webpay/Oneclick/Responses/MallTransactionCaptureResponse.php b/src/Webpay/Oneclick/Responses/MallTransactionCaptureResponse.php index 09754971..0f42bfb0 100644 --- a/src/Webpay/Oneclick/Responses/MallTransactionCaptureResponse.php +++ b/src/Webpay/Oneclick/Responses/MallTransactionCaptureResponse.php @@ -8,7 +8,7 @@ class MallTransactionCaptureResponse { public string|null $authorizationCode; public string|null $authorizationDate; - public float|null $capturedAmount; + public int|float|null $capturedAmount; public int|null $responseCode; public function __construct(array $json) @@ -36,9 +36,9 @@ public function getAuthorizationDate(): string|null } /** - * @return float|null + * @return int|float|null */ - public function getCapturedAmount(): float|null + public function getCapturedAmount(): int|float|null { return $this->capturedAmount; } diff --git a/src/Webpay/Oneclick/Responses/MallTransactionRefundResponse.php b/src/Webpay/Oneclick/Responses/MallTransactionRefundResponse.php index ec94a03a..9026120a 100644 --- a/src/Webpay/Oneclick/Responses/MallTransactionRefundResponse.php +++ b/src/Webpay/Oneclick/Responses/MallTransactionRefundResponse.php @@ -9,8 +9,8 @@ class MallTransactionRefundResponse public string|null $type; public string|null $authorizationCode; public string|null $authorizationDate; - public float|null $nullifiedAmount; - public float|null $balance; + public int|float|null $nullifiedAmount; + public int|float|null $balance; public int|null $responseCode; public function __construct(array $json) @@ -48,17 +48,17 @@ public function getAuthorizationDate(): string|null } /** - * @return float|null + * @return int|float|null */ - public function getNullifiedAmount(): float|null + public function getNullifiedAmount(): int|float|null { return $this->nullifiedAmount; } /** - * @return float|null + * @return int|float|null */ - public function getBalance(): float|null + public function getBalance(): int|float|null { return $this->balance; } diff --git a/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php b/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php index cd1b2a0f..797bc987 100644 --- a/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/MallTransactionInstallmentsResponse.php @@ -6,7 +6,7 @@ class MallTransactionInstallmentsResponse { - public float|null $installmentsAmount; + public int|float|null $installmentsAmount; public string|null $idQueryInstallments; public array|null $deferredPeriods; @@ -18,9 +18,9 @@ public function __construct(array $json) } /** - * @return float|null + * @return int|float|null */ - public function getInstallmentsAmount(): float|null + public function getInstallmentsAmount(): int|float|null { return $this->installmentsAmount; } diff --git a/src/Webpay/TransaccionCompleta/Responses/MallTransactionRefundResponse.php b/src/Webpay/TransaccionCompleta/Responses/MallTransactionRefundResponse.php index d2fc2f82..bf010918 100644 --- a/src/Webpay/TransaccionCompleta/Responses/MallTransactionRefundResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/MallTransactionRefundResponse.php @@ -9,8 +9,8 @@ class MallTransactionRefundResponse public string|null $type; public string|null $authorizationCode; public string|null $authorizationDate; - public float|null $nullifiedAmount; - public float|null $balance; + public int|float|null $nullifiedAmount; + public int|float|null $balance; public int|null $responseCode; public function __construct(array $json) @@ -48,17 +48,17 @@ public function getAuthorizationDate(): string|null } /** - * @return float|null + * @return int|float|null */ - public function getNullifiedAmount(): float|null + public function getNullifiedAmount(): int|float|null { return $this->nullifiedAmount; } /** - * @return float|null + * @return int|float|null */ - public function getBalance(): float|null + public function getBalance(): int|float|null { return $this->balance; } diff --git a/src/Webpay/TransaccionCompleta/Responses/TransactionDetail.php b/src/Webpay/TransaccionCompleta/Responses/TransactionDetail.php index a1774ed9..8f93ddd8 100644 --- a/src/Webpay/TransaccionCompleta/Responses/TransactionDetail.php +++ b/src/Webpay/TransaccionCompleta/Responses/TransactionDetail.php @@ -7,7 +7,7 @@ class TransactionDetail extends BaseTransactionDetail { - public float|null $prepaidBalance; + public int|float|null $prepaidBalance; /** * Creates an instance of TransactionDetail from an array @@ -35,9 +35,9 @@ public static function createFromArray(array $array) } /** - * @return float|null + * @return int|float|null */ - public function getPrepaidBalance(): float|null + public function getPrepaidBalance(): int|float|null { return $this->prepaidBalance; } diff --git a/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php b/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php index 650bd3b2..6752be33 100644 --- a/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/TransactionInstallmentsResponse.php @@ -6,7 +6,7 @@ class TransactionInstallmentsResponse { - public float|null $installmentsAmount; + public int|float|null $installmentsAmount; public string|null $idQueryInstallments; public array|null $deferredPeriods; @@ -18,9 +18,9 @@ public function __construct(array $json) } /** - * @return float|null + * @return int|float|null */ - public function getInstallmentsAmount(): float|null + public function getInstallmentsAmount(): int|float|null { return $this->installmentsAmount; } diff --git a/src/Webpay/TransaccionCompleta/Responses/TransactionRefundResponse.php b/src/Webpay/TransaccionCompleta/Responses/TransactionRefundResponse.php index d6625df0..46d21dae 100644 --- a/src/Webpay/TransaccionCompleta/Responses/TransactionRefundResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/TransactionRefundResponse.php @@ -9,8 +9,8 @@ class TransactionRefundResponse public string|null $type; public string|null $authorizationCode; public string|null $authorizationDate; - public float|null $nullifiedAmount; - public float|null $balance; + public int|float|null $nullifiedAmount; + public int|float|null $balance; public int|null $responseCode; public function __construct(array $json) @@ -48,17 +48,17 @@ public function getAuthorizationDate(): string|null } /** - * @return float|null + * @return int|float|null */ - public function getNullifiedAmount(): float|null + public function getNullifiedAmount(): int|float|null { return $this->nullifiedAmount; } /** - * @return float|null + * @return int|float|null */ - public function getBalance(): float|null + public function getBalance(): int|float|null { return $this->balance; } diff --git a/src/Webpay/TransaccionCompleta/Responses/TransactionStatusResponse.php b/src/Webpay/TransaccionCompleta/Responses/TransactionStatusResponse.php index ecab5f04..02b60dd7 100644 --- a/src/Webpay/TransaccionCompleta/Responses/TransactionStatusResponse.php +++ b/src/Webpay/TransaccionCompleta/Responses/TransactionStatusResponse.php @@ -10,7 +10,7 @@ class TransactionStatusResponse use HasTransactionStatus; public string|null $vci; - public float|null $prepaidBalance; + public int|float|null $prepaidBalance; public function __construct(array $json) { @@ -28,9 +28,9 @@ public function getVci(): string|null } /** - * @return float|null + * @return int|float|null */ - public function getPrepaidBalance(): float|null + public function getPrepaidBalance(): int|float|null { return $this->prepaidBalance; } diff --git a/src/Webpay/WebpayPlus/Responses/TransactionCaptureResponse.php b/src/Webpay/WebpayPlus/Responses/TransactionCaptureResponse.php index 2f354560..de0ab968 100644 --- a/src/Webpay/WebpayPlus/Responses/TransactionCaptureResponse.php +++ b/src/Webpay/WebpayPlus/Responses/TransactionCaptureResponse.php @@ -14,7 +14,7 @@ class TransactionCaptureResponse */ public string|null $authorizationCode; public string|null $authorizationDate; - public float|null $capturedAmount; + public int|float|null $capturedAmount; public int|null $responseCode; public function __construct(array $json) @@ -50,9 +50,9 @@ public function getAuthorizationDate(): string|null } /** - * @return float|null + * @return int|float|null */ - public function getCapturedAmount(): float|null + public function getCapturedAmount(): int|float|null { return $this->capturedAmount; } diff --git a/src/Webpay/WebpayPlus/Responses/TransactionDetail.php b/src/Webpay/WebpayPlus/Responses/TransactionDetail.php index 4a24896e..94b2a8e1 100644 --- a/src/Webpay/WebpayPlus/Responses/TransactionDetail.php +++ b/src/Webpay/WebpayPlus/Responses/TransactionDetail.php @@ -8,16 +8,16 @@ class TransactionDetail { - public float|null $amount; + public int|float|null $amount; public string|null $status; public string|null $authorizationCode; public string|null $paymentTypeCode; public int|null $responseCode; public int|null $installmentsNumber; - public float|null $installmentsAmount; + public int|float|null $installmentsAmount; public string|null $commerceCode; public string|null $buyOrder; - public float|null $balance; + public int|float|null $balance; public static function createFromArray(array $array) { @@ -58,9 +58,9 @@ public function isApproved(): bool } /** - * @return float|null + * @return int|float|null */ - public function getAmount(): float|null + public function getAmount(): int|float|null { return $this->amount; } @@ -122,17 +122,17 @@ public function getBuyOrder(): string|null } /** - * @return float|null + * @return int|float|null */ - public function getInstallmentsAmount(): float|null + public function getInstallmentsAmount(): int|float|null { return $this->installmentsAmount; } /** - * @return float|null + * @return int|float|null */ - public function getBalance(): float|null + public function getBalance(): int|float|null { return $this->balance; } diff --git a/src/Webpay/WebpayPlus/Responses/TransactionRefundResponse.php b/src/Webpay/WebpayPlus/Responses/TransactionRefundResponse.php index ceefa039..5ca250a5 100644 --- a/src/Webpay/WebpayPlus/Responses/TransactionRefundResponse.php +++ b/src/Webpay/WebpayPlus/Responses/TransactionRefundResponse.php @@ -20,13 +20,13 @@ class TransactionRefundResponse */ public string|null $authorizationDate; /** - * @var float|null + * @var int|float|null */ - public float|null $nullifiedAmount; + public int|float|null $nullifiedAmount; /** - * @var float|null + * @var int|float|null */ - public float|null $balance; + public int|float|null $balance; /** * @var int|null */ @@ -57,17 +57,17 @@ public function success(): bool } /** - * @return float|null + * @return int|float|null */ - public function getNullifiedAmount(): float|null + public function getNullifiedAmount(): int|float|null { return $this->nullifiedAmount; } /** - * @return float|null + * @return int|float|null */ - public function getBalance(): float|null + public function getBalance(): int|float|null { return $this->balance; } From 448d3850a59a6682556ca0858d860213060f4cbb Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 3 Jul 2024 17:18:00 -0400 Subject: [PATCH 50/51] refactor: delete capture amount casting --- src/Webpay/TransaccionCompleta/MallTransaction.php | 2 +- src/Webpay/TransaccionCompleta/Transaction.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Webpay/TransaccionCompleta/MallTransaction.php b/src/Webpay/TransaccionCompleta/MallTransaction.php index 368100ac..781b15aa 100644 --- a/src/Webpay/TransaccionCompleta/MallTransaction.php +++ b/src/Webpay/TransaccionCompleta/MallTransaction.php @@ -241,7 +241,7 @@ public function capture( 'buy_order' => $buyOrder, 'commerce_code' => $commerceCode, 'authorization_code' => $authorizationCode, - 'capture_amount' => (float) $captureAmount, + 'capture_amount' => $captureAmount, ]; try { diff --git a/src/Webpay/TransaccionCompleta/Transaction.php b/src/Webpay/TransaccionCompleta/Transaction.php index d663bce0..c8957237 100644 --- a/src/Webpay/TransaccionCompleta/Transaction.php +++ b/src/Webpay/TransaccionCompleta/Transaction.php @@ -229,7 +229,7 @@ public function capture(string $token, string $buyOrder, string $authorizationCo $payload = [ 'buy_order' => $buyOrder, 'authorization_code' => $authorizationCode, - 'capture_amount' => (float) $captureAmount, + 'capture_amount' => $captureAmount, ]; try { From 76ea663f7da310a4f0c6771d41f92e3a0a8eee00 Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 3 Jul 2024 17:18:14 -0400 Subject: [PATCH 51/51] refactor: change float type by int and float --- src/Webpay/Oneclick/MallTransaction.php | 8 ++++---- .../TransaccionCompleta/MallTransaction.php | 8 ++++---- src/Webpay/TransaccionCompleta/Transaction.php | 18 +++++++++++------- src/Webpay/WebpayPlus/MallTransaction.php | 8 ++++---- src/Webpay/WebpayPlus/Transaction.php | 12 ++++++------ 5 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/Webpay/Oneclick/MallTransaction.php b/src/Webpay/Oneclick/MallTransaction.php index ec8c6510..a5ead788 100644 --- a/src/Webpay/Oneclick/MallTransaction.php +++ b/src/Webpay/Oneclick/MallTransaction.php @@ -69,7 +69,7 @@ public function authorize( * @param string $childCommerceCode * @param string $childBuyOrder * @param string $authorizationCode - * @param float $amount + * @param int|float $amount * * @return MallTransactionCaptureResponse * @@ -80,7 +80,7 @@ public function capture( string $childCommerceCode, string $childBuyOrder, string $authorizationCode, - float $amount + int|float $amount ): MallTransactionCaptureResponse { $payload = [ 'commerce_code' => $childCommerceCode, @@ -141,7 +141,7 @@ public function status(string $buyOrder): MallTransactionStatusResponse * @param string $buyOrder * @param string $childCommerceCode * @param string $childBuyOrder - * @param float $amount + * @param int|float $amount * * @return MallTransactionRefundResponse * @@ -152,7 +152,7 @@ public function refund( string $buyOrder, string $childCommerceCode, string $childBuyOrder, - float $amount + int|float $amount ): MallTransactionRefundResponse { $payload = [ 'detail_buy_order' => $childBuyOrder, diff --git a/src/Webpay/TransaccionCompleta/MallTransaction.php b/src/Webpay/TransaccionCompleta/MallTransaction.php index 781b15aa..43a3dc2f 100644 --- a/src/Webpay/TransaccionCompleta/MallTransaction.php +++ b/src/Webpay/TransaccionCompleta/MallTransaction.php @@ -155,7 +155,7 @@ public function commit( * @param string $token * @param string $buyOrder * @param string $commerceCodeChild - * @param float $amount + * @param int|float $amount * * @throws MallTransactionRefundException * @@ -165,7 +165,7 @@ public function refund( string $token, string $buyOrder, string $commerceCodeChild, - float $amount + int|float $amount ) { $payload = [ 'buy_order' => $buyOrder, @@ -221,7 +221,7 @@ public function status(string $token) * @param string $commerceCode * @param string $buyOrder * @param string $authorizationCode - * @param float $captureAmount + * @param int|float $captureAmount * * @throws MallTransactionCaptureException * @throws GuzzleException @@ -233,7 +233,7 @@ public function capture( string $commerceCode, string $buyOrder, string $authorizationCode, - float $captureAmount + int|float $captureAmount ) { $endpoint = str_replace(self::SEARCH_STRING, $token, static::ENDPOINT_CAPTURE); diff --git a/src/Webpay/TransaccionCompleta/Transaction.php b/src/Webpay/TransaccionCompleta/Transaction.php index c8957237..2721317b 100644 --- a/src/Webpay/TransaccionCompleta/Transaction.php +++ b/src/Webpay/TransaccionCompleta/Transaction.php @@ -36,7 +36,7 @@ class Transaction /** * @param string $buyOrder * @param string $sessionId - * @param float $amount + * @param int|float $amount * @param string $cardNumber * @param string $cardExpirationDate * @param string|null $cvv @@ -49,7 +49,7 @@ class Transaction public function create( string $buyOrder, string $sessionId, - float $amount, + int|float $amount, string $cardNumber, string $cardExpirationDate, string|null $cvv = null, @@ -154,14 +154,14 @@ public function commit( /** * @param string $token - * @param float $amount + * @param int|float $amount * * @throws TransactionRefundException * @throws GuzzleException * * @return TransactionRefundResponse */ - public function refund(string $token, float $amount) + public function refund(string $token, int|float $amount) { $payload = [ 'amount' => $amount, @@ -215,15 +215,19 @@ public function status($token) * @param string $token * @param string $buyOrder * @param string $authorizationCode - * @param float $captureAmount + * @param int|float $captureAmount * * @throws TransactionCaptureException * @throws GuzzleException * * @return TransactionCaptureResponse */ - public function capture(string $token, string $buyOrder, string $authorizationCode, float $captureAmount) - { + public function capture( + string $token, + string $buyOrder, + string $authorizationCode, + int|float $captureAmount + ) { $endpoint = str_replace(self::SEARCH_STRING, $token, static::ENDPOINT_CAPTURE); $payload = [ diff --git a/src/Webpay/WebpayPlus/MallTransaction.php b/src/Webpay/WebpayPlus/MallTransaction.php index abac3657..6efd7d7b 100644 --- a/src/Webpay/WebpayPlus/MallTransaction.php +++ b/src/Webpay/WebpayPlus/MallTransaction.php @@ -108,14 +108,14 @@ public function commit(string $token) * @param string $token * @param string $buyOrder * @param string $childCommerceCode - * @param float $amount + * @param int|float $amount * * @throws MallTransactionRefundException * @throws GuzzleException * * @return MallTransactionRefundResponse */ - public function refund(string $token, string $buyOrder, string $childCommerceCode, float $amount) + public function refund(string $token, string $buyOrder, string $childCommerceCode, int|float $amount) { $payload = [ 'buy_order' => $buyOrder, @@ -176,7 +176,7 @@ public function status(string $token) * @param string $token * @param string $buyOrder * @param string $authorizationCode - * @param float $captureAmount + * @param int|float $captureAmount * * @throws MallTransactionCaptureException * @throws GuzzleException @@ -188,7 +188,7 @@ public function capture( string $token, string $buyOrder, string $authorizationCode, - float $captureAmount + int|float $captureAmount ) { $payload = [ 'commerce_code' => $childCommerceCode, diff --git a/src/Webpay/WebpayPlus/Transaction.php b/src/Webpay/WebpayPlus/Transaction.php index 8a10d767..568c5df6 100644 --- a/src/Webpay/WebpayPlus/Transaction.php +++ b/src/Webpay/WebpayPlus/Transaction.php @@ -39,7 +39,7 @@ class Transaction /** * @param string $buyOrder * @param string $sessionId - * @param float $amount + * @param int|float $amount * @param string $returnUrl * * @throws TransactionCreateException @@ -50,7 +50,7 @@ class Transaction public function create( string $buyOrder, string $sessionId, - float $amount, + int|float $amount, string $returnUrl ): TransactionCreateResponse { $payload = [ @@ -113,14 +113,14 @@ public function commit(string $token): TransactionCommitResponse /** * @param string $token - * @param float $amount + * @param int|float $amount * * @throws TransactionRefundException * @throws GuzzleException * * @return TransactionRefundResponse */ - public function refund(string $token, float $amount): TransactionRefundResponse + public function refund(string $token, int|float $amount): TransactionRefundResponse { try { $response = $this->sendRequest( @@ -174,7 +174,7 @@ public function status(string $token): TransactionStatusResponse * @param string $token * @param string $buyOrder * @param string $authorizationCode - * @param float $captureAmount + * @param int|float $captureAmount * * @throws TransactionCaptureException * @throws GuzzleException @@ -185,7 +185,7 @@ public function capture( string $token, string $buyOrder, string $authorizationCode, - float $captureAmount + int|float $captureAmount ): TransactionCaptureResponse { $payload = [ 'buy_order' => $buyOrder,