diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 629d9d4..413e796 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -9,119 +9,119 @@ on: jobs: byte_level: - name: "0️⃣ Byte-level" - runs-on: "ubuntu-latest" + name: 0️⃣ Byte-level + runs-on: ubuntu-latest steps: - - name: "Checkout code" - uses: "actions/checkout@v3" + - name: Checkout code + uses: actions/checkout@v4 - - name: "Check file permissions" + - name: Check file permissions run: | - test "$(find . -type f -not -path './.git/*' -executable)" == "" - - name: "Find non-printable ASCII characters" + test $(find . -type f -not -path './.git/*' -executable) == + - name: Find non-printable ASCII characters run: | - ! LC_ALL=C.UTF-8 find ./src -type f -name "*.php" -print0 | xargs -0 -- grep -PHn "[^ -~]" + ! LC_ALL=C.UTF-8 find ./src -type f -name *.php -print0 | xargs -0 -- grep -PHn [^ -~] syntax_errors: - name: "1️⃣ Syntax errors" - runs-on: "ubuntu-latest" + name: 1️⃣ Syntax errors + runs-on: ubuntu-latest steps: - - name: "Set up PHP" - uses: "shivammathur/setup-php@v2" + - name: Set up PHP + uses: shivammathur/setup-php@v2 with: - php-version: "latest" - tools: "parallel-lint" + php-version: latest + tools: parallel-lint - - name: "Checkout code" - uses: "actions/checkout@v3" + - name: Checkout code + uses: actions/checkout@v4 - - name: "Validate Composer configuration" - run: "composer validate --strict" + - name: Validate Composer configuration + run: composer validate --strict - - name: "Check source code for syntax errors" - run: "composer exec -- parallel-lint src/" + - name: Check source code for syntax errors + run: composer exec -- parallel-lint src/ unit_tests: - name: "2️⃣ Unit and Feature tests" + name: 2️⃣ Unit and Feature tests needs: - - "byte_level" - - "syntax_errors" - runs-on: "ubuntu-latest" + - byte_level + - syntax_errors + runs-on: ubuntu-latest strategy: matrix: php-version: - - "8.0" - - "8.1" - - "8.2" + - 8.1 + - 8.2 + - 8.3 laravel-constraint: - - "9.*" - - "10.*" + - 10.* + - 11.* dependencies: - - "lowest" - - "highest" + - lowest + - highest exclude: - - laravel-constraint: "10.*" - php-version: "8.0" + - laravel-constraint: 11.* + php-version: 8.1 steps: - - name: "Set up PHP" - uses: "shivammathur/setup-php@v2" + - name: Set up PHP + uses: shivammathur/setup-php@v2 with: - php-version: "${{ matrix.php-version }}" - extensions: "mbstring, intl" - coverage: "xdebug" + php-version: ${{ matrix.php-version }} + extensions: mbstring, intl + coverage: xdebug - - name: "Checkout code" - uses: "actions/checkout@v3" + - name: Checkout code + uses: actions/checkout@v4 - - name: "Install dependencies" - uses: "ramsey/composer-install@v2" + - name: Install dependencies + uses: ramsey/composer-install@v3 with: - dependency-versions: "${{ matrix.dependencies }}" - composer-options: "--with=laravel/framework:${{ matrix.laravel-constraint }}" + dependency-versions: ${{ matrix.dependencies }} + composer-options: --with=laravel/framework:${{ matrix.laravel-constraint }} - - name: "Execute unit tests" - run: "composer run-script test" + - name: Execute unit tests + run: composer run-script test - - name: "Upload coverage to Codecov" - uses: "codecov/codecov-action@v3" + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 static_analysis: - name: "3️⃣ Static Analysis" + name: 3️⃣ Static Analysis needs: - - "byte_level" - - "syntax_errors" - runs-on: "ubuntu-latest" + - byte_level + - syntax_errors + runs-on: ubuntu-latest steps: - - name: "Set up PHP" - uses: "shivammathur/setup-php@v2" + - name: Set up PHP + uses: shivammathur/setup-php@v2 with: - tools: "phpstan" - php-version: "latest" - coverage: "none" + tools: phpstan + php-version: latest + coverage: none - - name: "Checkout code" - uses: "actions/checkout@v3" + - name: Checkout code + uses: actions/checkout@v4 - - name: "Install dependencies" - uses: "ramsey/composer-install@v2" + - name: Install dependencies + uses: ramsey/composer-install@v3 - - name: "Execute static analysis" - run: "composer exec -- phpstan analyze -l 5 src/" + - name: Execute static analysis + run: composer exec -- phpstan analyze -l 5 src/ exported_files: - name: "4️⃣ Exported files" + name: 4️⃣ Exported files needs: - - "byte_level" - - "syntax_errors" - runs-on: "ubuntu-latest" + - byte_level + - syntax_errors + runs-on: ubuntu-latest steps: - - name: "Checkout code" - uses: "actions/checkout@v3" + - name: Checkout code + uses: actions/checkout@v4 - - name: "Check exported files" + - name: Check exported files run: | - EXPECTED="LICENSE.md,README.md,composer.json" - CURRENT="$(git archive HEAD | tar --list --exclude="src" --exclude="src/*" --exclude=".stubs" --exclude=".stubs/*" --exclude="routes" --exclude="routes/*" --exclude="stubs" --exclude="stubs/*" --exclude="lang" --exclude="lang/*" --exclude="config" --exclude="config/*" --exclude="database" --exclude="database/*" --exclude="resources" --exclude="resources/*" | paste -s -d ",")" - echo "CURRENT =${CURRENT}" - echo "EXPECTED=${EXPECTED}" - test "${CURRENT}" == "${EXPECTED}" + EXPECTED=LICENSE.md,README.md,composer.json + CURRENT=$(git archive HEAD | tar --list --exclude=src --exclude=src/* --exclude=.stubs --exclude=.stubs/* --exclude=routes --exclude=routes/* --exclude=stubs --exclude=stubs/* --exclude=lang --exclude=lang/* --exclude=config --exclude=config/* --exclude=database --exclude=database/* --exclude=resources --exclude=resources/* | paste -s -d ,) + echo CURRENT =${CURRENT} + echo EXPECTED=${EXPECTED} + test ${CURRENT} == ${EXPECTED} diff --git a/README.md b/README.md index 7c92df0..6030340 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@ public function confirm(WebpayRequest $payment) } ``` +> [!NOTE] +> > Only supports Webpay at the moment. Webpay Mall and Oneclick Mall are planned based on support. ## Become a sponsor @@ -35,8 +37,7 @@ Your support allows me to keep this package free, up-to-date and maintainable. A ## Requisites: -* Laravel 9.x, or later -* PHP 8.0 or later +* Laravel 10, or later # Installation @@ -101,6 +102,8 @@ To operate in production mode, where all transaction will be real, you will need TRANSBANK_ENV=production ``` +> [!NOTE] +> > Production keys don't work on _integration_ and vice versa. ## Middleware endpoint protection @@ -153,7 +156,9 @@ Route::get('failed-transaction', function () { RouteRedirect::as('confirm', 'failed-transaction'); ``` -> If you're using a different middleware to verify CSRF tokens, set the class in `RouteRedirect::$csrfMiddleware`. +> [!IMPORTANT] +> +> If you're using you own middleware to verify CSRF/XSRF tokens, set the class in `RouteRedirect::$csrfMiddleware`. ## Events @@ -167,6 +172,8 @@ You will be able to hear all transactions started and completed. This package se All exceptions implement `TransbankException`, so you can easily catch and check what happened. +> [!IMPORTANT] +> > Transactions properly rejected by banks or credit card issuers **do not** throw exceptions. There are 4 types of exceptions: diff --git a/composer.json b/composer.json index d0b14bb..36ad112 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Easy-to-use Transbank SDK for PHP.", "type": "library", "license": "MIT", - "minimum-stability": "stable", + "minimum-stability": "dev", "prefer-stable": true, "keywords": [ "payments", @@ -26,16 +26,15 @@ "issues": "https://github.com/Laragear/Transbank/issues" }, "require": { - "php": "8.*", + "php": "^8.1", "ext-json": "*", - "illuminate/http": "9.*|10.*", - "illuminate/log": "9.*|10.*", - "illuminate/events": "9.*|10.*", + "illuminate/http": "10.*|11.*", + "illuminate/log": "10.*|11.*", + "illuminate/events": "10.*|11.*", "guzzlehttp/guzzle": "^7.5" }, "require-dev": { - "orchestra/testbench": "^7.22|8.*", - "jetbrains/phpstorm-attributes": "*" + "orchestra/testbench": "8.*|9.*" }, "autoload": { "psr-4": { diff --git a/phpunit.xml b/phpunit.xml index 998d9d4..88aabac 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,9 +1,6 @@ - + - - src/ - @@ -19,4 +16,9 @@ + + + src/ + + diff --git a/src/ApiRequest.php b/src/ApiRequest.php index 404149a..bbf20ff 100644 --- a/src/ApiRequest.php +++ b/src/ApiRequest.php @@ -11,10 +11,6 @@ class ApiRequest implements JsonSerializable, ArrayAccess, Jsonable { /** * Create a new API Request instance. - * - * @param string $service - * @param string $action - * @param array $attributes */ public function __construct(public string $service, public string $action, public array $attributes = []) { @@ -23,9 +19,6 @@ public function __construct(public string $service, public string $action, publi /** * Convert the object to its JSON representation. - * - * @param int $options - * @return string */ public function toJson($options = 0): string { @@ -38,8 +31,6 @@ public function toJson($options = 0): string /** * Specify data which should be serialized to JSON. - * - * @return array */ public function jsonSerialize(): array { @@ -48,9 +39,6 @@ public function jsonSerialize(): array /** * Whether an offset exists. - * - * @param mixed $offset - * @return bool */ public function offsetExists(mixed $offset): bool { @@ -59,9 +47,6 @@ public function offsetExists(mixed $offset): bool /** * Offset to retrieve. - * - * @param mixed $offset - * @return mixed */ public function offsetGet(mixed $offset): mixed { @@ -70,10 +55,6 @@ public function offsetGet(mixed $offset): mixed /** * Offset to set. - * - * @param mixed $offset - * @param mixed $value - * @return void */ public function offsetSet(mixed $offset, mixed $value): void { @@ -82,9 +63,6 @@ public function offsetSet(mixed $offset, mixed $value): void /** * Offset to unset. - * - * @param mixed $offset - * @return void */ public function offsetUnset(mixed $offset): void { diff --git a/src/Events/TransactionCompleted.php b/src/Events/TransactionCompleted.php index ae62f7c..06d1e7b 100644 --- a/src/Events/TransactionCompleted.php +++ b/src/Events/TransactionCompleted.php @@ -9,9 +9,6 @@ class TransactionCompleted { /** * Create a new Transaction Completed event. - * - * @param \Laragear\Transbank\ApiRequest $apiRequest Data sent to Transbank. - * @param \Laragear\Transbank\Services\Transactions\Transaction $transaction */ public function __construct(public ApiRequest $apiRequest, public Transaction $transaction) { diff --git a/src/Events/TransactionCreated.php b/src/Events/TransactionCreated.php index e42e492..ae4286a 100644 --- a/src/Events/TransactionCreated.php +++ b/src/Events/TransactionCreated.php @@ -9,9 +9,6 @@ class TransactionCreated { /** * Create a new Transaction Created event. - * - * @param \Laragear\Transbank\ApiRequest $apiRequest Data sent to Transbank. - * @param \Laragear\Transbank\Services\Transactions\Response $response Raw response from Transbank. */ public function __construct(public ApiRequest $apiRequest, public Response $response) { diff --git a/src/Events/TransactionCreating.php b/src/Events/TransactionCreating.php index 08e0086..76278dc 100644 --- a/src/Events/TransactionCreating.php +++ b/src/Events/TransactionCreating.php @@ -8,8 +8,6 @@ class TransactionCreating { /** * Create a new Transaction Creating event. - * - * @param \Laragear\Transbank\ApiRequest $apiRequest */ public function __construct(public ApiRequest $apiRequest) { diff --git a/src/Exceptions/ClientException.php b/src/Exceptions/ClientException.php index 8168831..2caebd0 100644 --- a/src/Exceptions/ClientException.php +++ b/src/Exceptions/ClientException.php @@ -10,8 +10,6 @@ class ClientException extends RuntimeException implements TransbankException /** * The log level to report to the app. - * - * @var int */ public const LOG_LEVEL = LOG_ERR; } diff --git a/src/Exceptions/HandlesException.php b/src/Exceptions/HandlesException.php index 34007ff..a100fbf 100644 --- a/src/Exceptions/HandlesException.php +++ b/src/Exceptions/HandlesException.php @@ -10,13 +10,7 @@ trait HandlesException { /** * Transbank Exception constructor. - * - * @param string $message - * @param \Laragear\Transbank\ApiRequest|null $apiRequest - * @param \Illuminate\Http\Client\Response|null $response - * @param Throwable|null $previous */ - #[\JetBrains\PhpStorm\Pure] public function __construct( string $message = '', protected ?ApiRequest $apiRequest = null, @@ -28,8 +22,6 @@ public function __construct( /** * Returns the ApiRequest of this exception, if any. - * - * @return \Laragear\Transbank\ApiRequest|null */ public function getApiRequest(): ?ApiRequest { @@ -38,8 +30,6 @@ public function getApiRequest(): ?ApiRequest /** * Returns the Response from Transbank, if any. - * - * @return \Illuminate\Http\Client\Response|null */ public function getResponse(): ?Response { diff --git a/src/Exceptions/NetworkException.php b/src/Exceptions/NetworkException.php index 4122bef..c03b45e 100644 --- a/src/Exceptions/NetworkException.php +++ b/src/Exceptions/NetworkException.php @@ -10,8 +10,6 @@ class NetworkException extends RuntimeException implements TransbankException /** * The log level to report to the app. - * - * @var int */ public const LOG_LEVEL = LOG_CRIT; } diff --git a/src/Exceptions/ServerException.php b/src/Exceptions/ServerException.php index e9d4ca5..e84e785 100644 --- a/src/Exceptions/ServerException.php +++ b/src/Exceptions/ServerException.php @@ -10,8 +10,6 @@ class ServerException extends RuntimeException implements TransbankException /** * The log level to report to the app. - * - * @var int */ public const LOG_LEVEL = LOG_CRIT; } diff --git a/src/Exceptions/UnknownException.php b/src/Exceptions/UnknownException.php index e3b686d..c1c003b 100644 --- a/src/Exceptions/UnknownException.php +++ b/src/Exceptions/UnknownException.php @@ -10,8 +10,6 @@ class UnknownException extends RuntimeException implements TransbankException /** * The log level to report to the app. - * - * @var int */ public const LOG_LEVEL = LOG_CRIT; } diff --git a/src/Http/Client.php b/src/Http/Client.php index 8637375..47b53b7 100644 --- a/src/Http/Client.php +++ b/src/Http/Client.php @@ -20,44 +20,31 @@ class Client { /** * Current API Version to use on Transbank Servers. - * - * @var string */ public const API_VERSION = 'v1.3'; /** * Transbank API Key header name. - * - * @var string */ public const HEADER_KEY = 'Tbk-Api-Key-Id'; /** * Transbank API Shared Secret header name. - * - * @var string */ public const HEADER_SECRET = 'Tbk-Api-Key-Secret'; /** * Production endpoint server. - * - * @var string */ public const PRODUCTION_ENDPOINT = 'https://webpay3g.transbank.cl/'; /** * Integration endpoint server. - * - * @var string */ public const INTEGRATION_ENDPOINT = 'https://webpay3gint.transbank.cl/'; /** * Create a new HTTP Client instance. - * - * @param \Illuminate\Contracts\Config\Repository $config - * @param \Illuminate\Http\Client\Factory $http */ public function __construct(protected ConfigContract $config, protected HttpFactory $http) { @@ -66,11 +53,6 @@ public function __construct(protected ConfigContract $config, protected HttpFact /** * Sends a transaction to Transbank servers. - * - * @param string $method - * @param string $endpoint - * @param \Laragear\Transbank\ApiRequest $request - * @return \Illuminate\Http\Client\Response */ public function send(string $method, string $endpoint, ApiRequest $request): Response { @@ -92,11 +74,7 @@ public function send(string $method, string $endpoint, ApiRequest $request): Res /** * Returns the headers for the service with its key and secret. - * - * @param string $service - * @return array */ - #[\JetBrains\PhpStorm\ArrayShape([self::HEADER_KEY => 'string', self::HEADER_SECRET => 'string'])] protected function getHeadersKeysForService(string $service): array { return [ @@ -107,12 +85,6 @@ protected function getHeadersKeysForService(string $service): array /** * Sends the request to Transbank servers. - * - * @param \Illuminate\Http\Client\PendingRequest $request - * @param \Laragear\Transbank\ApiRequest $api - * @param string $method - * @param string $endpoint - * @return \Illuminate\Http\Client\Response */ protected function toTransbank(PendingRequest $request, ApiRequest $api, string $method, string $endpoint): Response { @@ -130,10 +102,6 @@ protected function toTransbank(PendingRequest $request, ApiRequest $api, string /** * Replace the API Version from the endpoint. - * - * @param string $endpoint - * - * @return string */ protected function setApiVersion(string $endpoint): string { @@ -142,10 +110,6 @@ protected function setApiVersion(string $endpoint): string /** * Checks if the Response is an error or not. - * - * @param \Laragear\Transbank\ApiRequest $apiRequest - * @param \Illuminate\Http\Client\Response $response - * @return void */ protected function throwExceptionOnResponseError(ApiRequest $apiRequest, Response $response): void { @@ -170,9 +134,6 @@ protected function throwExceptionOnResponseError(ApiRequest $apiRequest, Respons /** * Returns the error message from the Transbank response. - * - * @param \Illuminate\Http\Client\Response $response - * @return string */ protected function getErrorMessage(Response $response): string { @@ -181,12 +142,10 @@ protected function getErrorMessage(Response $response): string /** * Return the string used to reach Transbank servers. - * - * @return string */ protected function getTransbankBaseEndpoint(): string { - return $this->config->get('transbank.environment') === 'production' + return $this->config->get('transbank.environment') === Transbank::PRODUCTION_ENV ? static::PRODUCTION_ENDPOINT : static::INTEGRATION_ENDPOINT; } diff --git a/src/Http/Controllers/FailureRedirectController.php b/src/Http/Controllers/FailureRedirectController.php index f07ad10..eeaf6c3 100644 --- a/src/Http/Controllers/FailureRedirectController.php +++ b/src/Http/Controllers/FailureRedirectController.php @@ -14,10 +14,6 @@ class FailureRedirectController extends RedirectController { /** * Redirects the POST request of a failed transaction from Transbank. - * - * @param \Illuminate\Http\Request $request - * @param \Illuminate\Routing\UrlGenerator $url - * @return \Illuminate\Http\RedirectResponse */ public function __invoke(Request $request, UrlGenerator $url): RedirectResponse { diff --git a/src/Http/Middleware/ProtectTransaction.php b/src/Http/Middleware/ProtectTransaction.php index 47a00de..a4a5b34 100644 --- a/src/Http/Middleware/ProtectTransaction.php +++ b/src/Http/Middleware/ProtectTransaction.php @@ -13,10 +13,6 @@ class ProtectTransaction { /** * Handle the incoming Transbank POST Request. - * - * @param \Illuminate\Http\Request $request - * @param \Closure $next - * @return mixed */ public function handle(Request $request, Closure $next): mixed { @@ -27,9 +23,6 @@ public function handle(Request $request, Closure $next): mixed /** * Check if the request contains a valid token from Transbank. - * - * @param \Illuminate\Http\Request $request - * @return bool */ protected function requestComesFromTransbank(Request $request): bool { @@ -44,9 +37,6 @@ protected function requestComesFromTransbank(Request $request): bool /** * Returns the incoming transaction token from Transbank, if any. - * - * @param \Illuminate\Http\Request $request - * @return string|null */ protected function token(Request $request): ?string { diff --git a/src/Http/Requests/WebpayRequest.php b/src/Http/Requests/WebpayRequest.php index d3da95f..638cc32 100644 --- a/src/Http/Requests/WebpayRequest.php +++ b/src/Http/Requests/WebpayRequest.php @@ -11,15 +11,11 @@ class WebpayRequest extends FormRequest { /** * The received transaction. - * - * @var \Laragear\Transbank\Services\Transactions\Transaction|null */ protected ?Transaction $transaction = null; /** * Validate the given class instance. - * - * @return void */ public function validateResolved(): void { @@ -28,9 +24,6 @@ public function validateResolved(): void /** * Commits the transaction if the callback or value is truthy. - * - * @param mixed $condition - * @return \Laragear\Transbank\Services\Transactions\Transaction|null */ public function commitWhen(mixed $condition): ?Transaction { @@ -43,9 +36,6 @@ public function commitWhen(mixed $condition): ?Transaction /** * Commits the transaction if the callback or value is falsy. - * - * @param mixed $condition - * @return \Laragear\Transbank\Services\Transactions\Transaction|null */ public function commitUnless(mixed $condition): ?Transaction { @@ -58,10 +48,6 @@ public function commitUnless(mixed $condition): ?Transaction /** * Parses the condition to evaluate. - * - * @param mixed $condition - * @param bool $truthy - * @return bool */ protected function parseCondition(mixed $condition, bool $truthy): bool { @@ -74,8 +60,6 @@ protected function parseCondition(mixed $condition, bool $truthy): bool /** * Commits and returns a transaction in Webpay only once. - * - * @return \Laragear\Transbank\Services\Transactions\Transaction */ public function transaction(): Transaction { @@ -84,8 +68,6 @@ public function transaction(): Transaction /** * Commits and returns a transaction in Webpay. - * - * @return \Laragear\Transbank\Services\Transactions\Transaction */ protected function commit(): Transaction { @@ -94,8 +76,6 @@ protected function commit(): Transaction /** * Commit the transaction and return if it was successful. - * - * @return bool */ public function isSuccessful(): bool { @@ -104,8 +84,6 @@ public function isSuccessful(): bool /** * Commits the transaction and return if it was not successful. - * - * @return bool */ public function isNotSuccessful(): bool { @@ -114,8 +92,6 @@ public function isNotSuccessful(): bool /** * Returns the Transaction Token from the request. - * - * @return string */ protected function token(): string { diff --git a/src/Listeners/SaveTransactionToken.php b/src/Listeners/SaveTransactionToken.php index 7114060..13a7bf4 100644 --- a/src/Listeners/SaveTransactionToken.php +++ b/src/Listeners/SaveTransactionToken.php @@ -10,9 +10,6 @@ class SaveTransactionToken { /** * Create a new listener instance. - * - * @param \Illuminate\Contracts\Config\Repository $config - * @param \Illuminate\Contracts\Cache\Factory $cache */ public function __construct(protected ConfigContract $config, protected CacheContract $cache) { @@ -21,9 +18,6 @@ public function __construct(protected ConfigContract $config, protected CacheCon /** * Handle the fired event. - * - * @param \Laragear\Transbank\Events\TransactionCreated $event - * @return void */ public function handle(TransactionCreated $event): void { diff --git a/src/RouteRedirect.php b/src/RouteRedirect.php index 7e9e6ef..d293f5e 100644 --- a/src/RouteRedirect.php +++ b/src/RouteRedirect.php @@ -2,6 +2,7 @@ namespace Laragear\Transbank; +use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken; use Illuminate\Routing\Route as HttpRoute; use Illuminate\Session\Middleware\StartSession; use Illuminate\Support\Facades\Route; @@ -12,17 +13,11 @@ class RouteRedirect { /** * Middleware class that verifies CSRF tokens. - * - * @var string */ - public static $csrfMiddleware = 'App\Http\Middleware\VerifyCsrfToken'; + public static $csrfMiddleware = VerifyCsrfToken::class; /** * Returns a redirection route for failed transactions - * - * @param string $path - * @param string|null $route - * @return \Illuminate\Routing\Route */ public static function as(string $path, string $route = null, int $status = 303): HttpRoute { diff --git a/src/Services/Concerns/DebugsTransactions.php b/src/Services/Concerns/DebugsTransactions.php index 8b9da70..44ecf25 100644 --- a/src/Services/Concerns/DebugsTransactions.php +++ b/src/Services/Concerns/DebugsTransactions.php @@ -9,9 +9,6 @@ trait DebugsTransactions { /** * Debugs a given operation. - * - * @param string $message - * @param array $context */ protected function log(string $message, array $context = []): void { @@ -20,8 +17,6 @@ protected function log(string $message, array $context = []): void /** * Debugs a transaction before creating it. - * - * @param \Laragear\Transbank\ApiRequest $apiRequest */ protected function logCreating(ApiRequest $apiRequest): void { @@ -30,10 +25,6 @@ protected function logCreating(ApiRequest $apiRequest): void /** * Debugs a given operation. - * - * @param \Laragear\Transbank\ApiRequest $apiRequest - * @param \Illuminate\Http\Client\Response $response - * @param string|null $token */ protected function logResponse(ApiRequest $apiRequest, Response $response, string $token = null): void { diff --git a/src/Services/Concerns/FiresEvents.php b/src/Services/Concerns/FiresEvents.php index 8070863..a542721 100644 --- a/src/Services/Concerns/FiresEvents.php +++ b/src/Services/Concerns/FiresEvents.php @@ -13,8 +13,6 @@ trait FiresEvents { /** * Fires a Transaction Started event. - * - * @param \Laragear\Transbank\ApiRequest $apiRequest */ protected function fireCreating(ApiRequest $apiRequest): void { @@ -23,9 +21,6 @@ protected function fireCreating(ApiRequest $apiRequest): void /** * Fires a Transaction Created event. - * - * @param \Laragear\Transbank\ApiRequest $apiRequest - * @param \Laragear\Transbank\Services\Transactions\Response $response */ protected function fireCreated(ApiRequest $apiRequest, Response $response): void { @@ -34,9 +29,6 @@ protected function fireCreated(ApiRequest $apiRequest, Response $response): void /** * Fires a Transaction Completed event. - * - * @param \Laragear\Transbank\ApiRequest $apiRequest - * @param \Laragear\Transbank\Services\Transactions\Transaction $transaction */ protected function fireCompleted(ApiRequest $apiRequest, Transaction $transaction): void { diff --git a/src/Services/Concerns/SendsRequests.php b/src/Services/Concerns/SendsRequests.php index 26624db..90d5344 100644 --- a/src/Services/Concerns/SendsRequests.php +++ b/src/Services/Concerns/SendsRequests.php @@ -12,12 +12,7 @@ trait SendsRequests { /** * Creates a new API Request. - * - * @param string $action - * @param array $attributes - * @return \Laragear\Transbank\ApiRequest */ - #[\JetBrains\PhpStorm\Pure] protected function request(string $action, array $attributes = []): ApiRequest { return new ApiRequest(static::SERVICE_NAME, $action, $attributes); @@ -25,10 +20,6 @@ protected function request(string $action, array $attributes = []): ApiRequest /** * Sends a ApiRequest to Transbank, returns a response array. - * - * @param \Laragear\Transbank\ApiRequest $apiRequest - * @param array $replace - * @return \Illuminate\Http\Client\Response */ protected function send(ApiRequest $apiRequest, array $replace = []): Response { @@ -41,10 +32,6 @@ protected function send(ApiRequest $apiRequest, array $replace = []): Response /** * Returns the Transaction object from Transbank response. - * - * @param string $action - * @param \Illuminate\Http\Client\Response $response - * @return \Laragear\Transbank\Services\Transactions\Transaction */ protected function transaction(string $action, Response $response): Transaction { diff --git a/src/Services/Transactions/Response.php b/src/Services/Transactions/Response.php index c2b7b05..0240b7a 100644 --- a/src/Services/Transactions/Response.php +++ b/src/Services/Transactions/Response.php @@ -9,6 +9,9 @@ class Response implements Stringable, Responsable { + /** + * The name of the key holding the token. + */ public const WEBPAY_TOKEN = 'token_ws'; /** @@ -28,8 +31,6 @@ public function __construct( /** * Returns the transaction token that identifies it on Transbank. - * - * @return string */ public function getToken(): string { @@ -38,8 +39,6 @@ public function getToken(): string /** * Returns the transaction URL where the transaction can be retrieved. - * - * @return string */ public function getUrl(): string { @@ -48,8 +47,6 @@ public function getUrl(): string /** * Transforms the Response into a String for Webpay GET redirects. - * - * @return string */ public function __toString(): string { @@ -58,9 +55,6 @@ public function __toString(): string /** * Create an HTTP response that represents the object. - * - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\RedirectResponse */ public function toResponse($request): RedirectResponse { diff --git a/src/Services/Transactions/Transaction.php b/src/Services/Transactions/Transaction.php index 8848bfa..8dadf60 100644 --- a/src/Services/Transactions/Transaction.php +++ b/src/Services/Transactions/Transaction.php @@ -18,10 +18,6 @@ class Transaction extends Fluent /** * Creates a new Transaction instance. - * - * @param string $service - * @param string $action - * @param array $attributes */ public function __construct(public string $service, public string $action, array $attributes) { @@ -33,7 +29,6 @@ public function __construct(public string $service, public string $action, array * * @return bool */ - #[\JetBrains\PhpStorm\Pure] public function isSuccessful(): bool { // If TBK data has been received, immediately bail out. @@ -58,10 +53,7 @@ public function isSuccessful(): bool /** * Check the transaction has failed. - * - * @return bool */ - #[\JetBrains\PhpStorm\Pure] public function isNotSuccessful(): bool { return ! $this->isSuccessful(); @@ -69,10 +61,7 @@ public function isNotSuccessful(): bool /** * Check the transaction has failed. - * - * @return bool */ - #[\JetBrains\PhpStorm\Pure] public function hasFailed(): bool { return $this->isNotSuccessful(); @@ -80,8 +69,6 @@ public function hasFailed(): bool /** * Returns the Credit Card numbers as an integer, or null if it doesn't exist. - * - * @return int|null */ public function getCreditCardNumber(): ?int { diff --git a/src/Services/Webpay.php b/src/Services/Webpay.php index fcee0b0..ab30fe1 100644 --- a/src/Services/Webpay.php +++ b/src/Services/Webpay.php @@ -14,25 +14,20 @@ class Webpay /** * Integrations Keys for this service. - * - * @var int */ public const INTEGRATION_KEY = 597055555532; // Service names. public const SERVICE_NAME = 'webpay'; + // Action names public const ACTION_CREATE = 'create'; public const ACTION_COMMIT = 'commit'; public const ACTION_STATUS = 'status'; public const ACTION_REFUND = 'refund'; public const ACTION_CAPTURE = 'capture'; - /** - * The API base URI. - * - * @var string - */ + // The API base URI. public const ENDPOINT_BASE = 'rswebpaytransaction/api/webpay/{api_version}/'; // Endpoints for the transactions. @@ -46,10 +41,6 @@ class Webpay /** * Create a new Webpay instance. - * - * @param \Illuminate\Contracts\Events\Dispatcher $event - * @param \Psr\Log\LoggerInterface $logger - * @param \Laragear\Transbank\Http\Client $client */ public function __construct(public Dispatcher $event, public LoggerInterface $logger, public Client $client) { @@ -58,11 +49,6 @@ public function __construct(public Dispatcher $event, public LoggerInterface $lo /** * Creates a ApiRequest on Transbank, returns a response from it. - * - * @param string $buyOrder - * @param int|float $amount - * @param string $returnUrl - * @return \Laragear\Transbank\Services\Transactions\Response */ public function create(string $buyOrder, int|float $amount, string $returnUrl): Transactions\Response { @@ -88,9 +74,6 @@ public function create(string $buyOrder, int|float $amount, string $returnUrl): /** * Commits a transaction immediately - * - * @param string $token - * @return \Laragear\Transbank\Services\Transactions\Transaction */ public function commit(string $token): Transactions\Transaction { @@ -110,9 +93,6 @@ public function commit(string $token): Transactions\Transaction /** * Returns the status of a non-expired transaction by its token. - * - * @param string $token - * @return \Laragear\Transbank\Services\Transactions\Transaction */ public function status(string $token): Transactions\Transaction { @@ -130,10 +110,6 @@ public function status(string $token): Transactions\Transaction /** * Refunds partially or totally a given credit-card charge amount. * - * @param string $token - * @param int|float $amount - * @return \Laragear\Transbank\Services\Transactions\Transaction - * */ public function refund(string $token, int|float $amount): Transactions\Transaction { @@ -157,12 +133,6 @@ public function refund(string $token, int|float $amount): Transactions\Transacti * * This transaction type only works for credit cards, and "holds" the amount up to 7 days. * - * @param string $token - * @param string $buyOrder - * @param int $code - * @param int|float $amount - * @return \Laragear\Transbank\Services\Transactions\Transaction - * */ public function capture(string $token, string $buyOrder, int $code, int|float $amount): Transactions\Transaction { diff --git a/src/Transbank.php b/src/Transbank.php index edf9b51..3c9ad45 100644 --- a/src/Transbank.php +++ b/src/Transbank.php @@ -6,22 +6,16 @@ class Transbank { /** * Current SDK version. - * - * @var string */ - public const VERSION = '1.0'; + public const VERSION = '1.2'; /** * The name of the production environment. - * - * @var string */ public const PRODUCTION_ENV = 'production'; /** * Integration shared secret. - * - * @var string */ public const INTEGRATION_SECRET = '579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C'; } diff --git a/src/TransbankServiceProvider.php b/src/TransbankServiceProvider.php index 719f8ea..87edcd5 100644 --- a/src/TransbankServiceProvider.php +++ b/src/TransbankServiceProvider.php @@ -2,8 +2,8 @@ namespace Laragear\Transbank; -use Illuminate\Contracts\Config\Repository; -use Illuminate\Contracts\Events\Dispatcher; +use Illuminate\Contracts\Config\Repository as ConfigContract; +use Illuminate\Contracts\Events\Dispatcher as EventContract; use Illuminate\Routing\Router; use Illuminate\Support\ServiceProvider; use Laragear\Transbank\Events\TransactionCreated; @@ -14,8 +14,6 @@ class TransbankServiceProvider extends ServiceProvider /** * Register bindings in the container. - * - * @return void */ public function register(): void { @@ -27,13 +25,8 @@ public function register(): void /** * Bootstrap any application services. - * - * @param \Illuminate\Contracts\Events\Dispatcher $dispatcher - * @param \Illuminate\Contracts\Config\Repository $config - * @param \Illuminate\Routing\Router $router - * @return void */ - public function boot(Router $router, Repository $config, Dispatcher $dispatcher): void + public function boot(Router $router, ConfigContract $config, EventContract $dispatcher): void { $router->aliasMiddleware('transbank.protect', Http\Middleware\ProtectTransaction::class);