Skip to content

Commit 0db630b

Browse files
4.x
1 parent c7d15bd commit 0db630b

18 files changed

Lines changed: 110 additions & 79 deletions

.github/workflows/php.yml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- name: Checkout code
16-
uses: actions/checkout@v4
16+
uses: actions/checkout@v6
1717

1818
- name: Check file permissions
1919
run: |
@@ -33,7 +33,7 @@ jobs:
3333
tools: parallel-lint
3434

3535
- name: Checkout code
36-
uses: actions/checkout@v4
36+
uses: actions/checkout@v6
3737

3838
- name: Validate Composer configuration
3939
run: composer validate --strict
@@ -50,18 +50,20 @@ jobs:
5050
strategy:
5151
matrix:
5252
php-version:
53-
- 8.2
5453
- 8.3
5554
- 8.4
55+
- 8.5
5656
laravel-constraint:
57-
- 11.*
5857
- 12.*
58+
- 13.*
5959
dependencies:
6060
- lowest
6161
- highest
62+
include-filament: [ true ]
6263
exclude:
63-
- laravel-constraint: 12.*
64-
php-version: 8.2
64+
- laravel-constraint: "13.*"
65+
php-version: 8.3
66+
include-filament: true
6567
steps:
6668
- name: Set up PHP
6769
uses: shivammathur/setup-php@v2
@@ -71,7 +73,12 @@ jobs:
7173
coverage: xdebug
7274

7375
- name: Checkout code
74-
uses: actions/checkout@v4
76+
uses: actions/checkout@v6
77+
78+
# Remove this once Filament PHP v5 gets Laravel 13 compatibility.
79+
- name: Remove Filament for Laravel 13 compatibility
80+
if: matrix.laravel-constraint == '13.*'
81+
run: composer remove "filament/actions" --dev --no-update
7582

7683
- name: Install dependencies
7784
uses: ramsey/composer-install@v3
@@ -103,7 +110,7 @@ jobs:
103110
coverage: none
104111

105112
- name: Checkout code
106-
uses: actions/checkout@v4
113+
uses: actions/checkout@v6
107114

108115
- name: Install dependencies
109116
uses: ramsey/composer-install@v3
@@ -119,7 +126,7 @@ jobs:
119126
runs-on: ubuntu-latest
120127
steps:
121128
- name: Checkout code
122-
uses: actions/checkout@v4
129+
uses: actions/checkout@v6
123130

124131
- name: Check exported files
125132
run: |

README.md

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
[![Codecov Coverage](https://codecov.io/gh/Laragear/Transbank/graph/badge.svg?token=LKnve3PkRl)](https://codecov.io/gh/Laragear/Transbank)
55
[![Maintainability](https://qlty.sh/badges/c6975072-d953-4d0a-ab6a-1c4e475db2f5/maintainability.svg)](https://qlty.sh/gh/Laragear/projects/Transbank)
66
[![Sonarcloud Status](https://sonarcloud.io/api/project_badges/measure?project=Laragear_Transbank&metric=alert_status)](https://sonarcloud.io/dashboard?id=Laragear_Transbank)
7-
[![Laravel Octane Compatibility](https://img.shields.io/badge/Laravel%20Octane-Compatible-success?style=flat&logo=laravel)](https://laravel.com/docs/9.x/octane#introduction)
7+
[![Laravel Octane Compatibility](https://img.shields.io/badge/Laravel%20Octane-Compatible-success?style=flat&logo=laravel)](https://laravel.com/docs/13.x/octane#introduction)
88

9-
Easy-to-use Transbank SDK for PHP for Webpay, Webpay Mall and Oneclick Mall.
9+
Easy-to-use Transbank SDK for PHP for Webpay, Webpay Mall, and Oneclick Mall.
1010

1111
```php
1212
use Laragear\Transbank\Facades\Webpay;
@@ -33,11 +33,12 @@ public function confirm(WebpayRequest $payment)
3333

3434
[![](.github/assets/support.png)](https://github.com/sponsors/DarkGhostHunter)
3535

36-
Your support allows me to keep this package free, up-to-date and maintainable. Alternatively, you can **[spread the word!](http://twitter.com/share?text=I%20am%20using%20this%20cool%20PHP%20package&url=https://github.com%2FLaragear%2FReCaptcha&hashtags=PHP,Laravel,Transbank,WebPay)**
36+
Your support allows me to keep this package free, up-to-date, and maintainable. Alternatively, you can **[spread the word!](http://twitter.com/share?text=I%20am%20using%20this%20cool%20PHP%20package&url=https://github.com%2FLaragear%2FReCaptcha&hashtags=PHP,Laravel,Transbank,WebPay)**
3737

3838
## Requisites
3939

40-
* Laravel 11, or later
40+
* PHP 8.3 or later
41+
* Laravel 12 or later
4142

4243
# Installation
4344

@@ -231,7 +232,7 @@ You will be able to hear all transactions started and completed. This package se
231232

232233
## Livewire Component
233234

234-
This packages includes the [`Laragear/Transbank/Livewire/CheckoutWebpay`](src/Livewire/CheckoutWebpay.php) Liveware trait that automatically handles receiving a Webpay Transaction from Transbank [thanks to lifecycle hooks](https://livewire.laravel.com/docs/4.x/lifecycle-hooks#using-hooks-inside-a-trait).
235+
This packages includes the [`Laragear/Transbank/Livewire/InteractsWithWebpay`](src/Livewire/InteractsWithWebpay.php) Liveware trait that automatically handles receiving a Webpay Transaction from Transbank [thanks to lifecycle hooks](https://livewire.laravel.com/docs/4.x/lifecycle-hooks#using-hooks-inside-a-trait).
235236

236237
The only requirement is to implement the `handleSuccessfulTransaction()` method, which receives the successful transaction. For example, you may use this to mark a hypothetical "Cart" model as paid.
237238

@@ -262,7 +263,7 @@ class Payment extends Component
262263

263264
Apart from the `$isSuccessful` property to check the transaction success, this trait also offers other methods you can override for your convenience:
264265

265-
- `handleWebpayException()`: Receives any exception thrown by Webpay (like connection errors).
266+
- `handleWebpayException()`: Controls exceptions thrown by Webpay (like connection errors).
266267
- `afterTransactionReceived()`: Handles the freshly retrieved transaction.
267268
- `handleTransactionStatus()`: Handles how the transaction should be considered successful or failed.
268269
- `handleFailedTransaction()`: Handles the Transaction when it has failed.
@@ -271,6 +272,28 @@ Apart from the `$isSuccessful` property to check the transaction success, this t
271272

272273
You can use these methods to show different messages to the user. For example, you can use `handleNonWebpayResponse()` to redirect the user back to the cart checkout route, or `handleFailedTransaction()` to store the failure for analytics.
273274

275+
The `handleWebpayException()` receives any exception, like connection errors or form aborts, and lets you handle it as you wish. For example, you may suppress the exception and render your component as not-successful. Otherwise, any Exception returned will be thrown as usual, so it's great to _replace_ exceptions with your own.
276+
277+
```php
278+
use Laragear\Transbank\Exceptions\ClientException;
279+
use Throwable;
280+
281+
public $title = '';
282+
public $message = '';
283+
284+
protected function handleWebpayException(Throwable $exception)
285+
{
286+
if ($exception instanceof ClientException) {
287+
$this->isSuccessful = false;
288+
} else {
289+
report($exception);
290+
291+
$this->title = 'Transbank is unresponsive';
292+
$this->message = 'We will look into it as soon as possible.';
293+
}
294+
}
295+
```
296+
274297
The `afterTransactionReceived()` method is great to override when you require to do logic _after_ the transaction has been received, but _before_ any other logic. For example, to retrieve a Checkout process.
275298

276299
```php
@@ -322,7 +345,8 @@ You should use this [adding custom actions](https://filamentphp.com/docs/5.x/res
322345
```php
323346
use App\Models\Checkout;
324347
use Filament\Schemas\Schema;
325-
use Illuminate\Support\Number;use Laragear\Transbank\Filament\WebpayAction;
348+
use Illuminate\Support\Number;
349+
use Laragear\Transbank\Filament\WebpayAction;
326350

327351
public ?Checkout $checkout = null;
328352

@@ -358,7 +382,7 @@ All exceptions implement `TransbankException`, so you can easily catch and check
358382
359383
There are 4 types of exceptions:
360384

361-
* `ClientException`: Any error byproduct of bad transactions, misconfiguration, aborts, abandonment, timeout or invalid values.
385+
* `ClientException`: Any error byproduct of bad transactions, misconfiguration, aborts, abandonment, timeout, or invalid values.
362386
* `ServerException`: Any internal Transbank servers errors.
363387
* `NetworkException`: Any communication error from Transbank Server, like network timeouts or wrong endpoints.
364388
* `UnknownException`: Any other error.
@@ -454,12 +478,12 @@ return [
454478

455479
Disabled by default, you can further protect your endpoints using the [`transbank.protect` middleware](#middleware-endpoint-protection). Once enabled, it will save the token of every transaction created by 5 minutes, and once Transbank returns the user with the token, abort the request if it was not generated or was expired.
456480

457-
This also handles which cache store to use, and which prefix to use when storing the tokens into the cache.
481+
This also handles which cache store to use and which prefix to use when storing the tokens into the cache.
458482

459483
# Licence
460484

461-
This specific package version is licensed under the terms of the [MIT License](LICENSE.md), at time of publishing.
485+
This specific package version is licensed under the terms of the [MIT License](LICENSE.md), at the time of publishing.
462486

463-
[Laravel](https://laravel.com) is a Trademark of [Taylor Otwell](https://github.com/TaylorOtwell/). Copyright © 2011-2025 Laravel LLC.
487+
[Laravel](https://laravel.com) is a Trademark of [Taylor Otwell](https://github.com/TaylorOtwell/). Copyright © 2011–2026 Laravel LLC.
464488

465489
`Redcompra`, `Webpay`, `Oneclick`, `Onepay`, `Patpass` and `Transbank` are trademarks of [Transbank S.A.](https://www.transbank.cl/). This package and its author are not associated with Transbank S.A.

composer.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@
2626
"issues": "https://github.com/Laragear/Transbank/issues"
2727
},
2828
"require": {
29-
"php": "^8.2",
29+
"php": "^8.3",
3030
"ext-json": "*",
31-
"illuminate/config": "11.*|12.*",
32-
"illuminate/http": "11.*|12.*",
33-
"illuminate/log": "11.*|12.*",
34-
"illuminate/events": "11.*|12.*",
35-
"illuminate/support": "11.*|12.*",
36-
"guzzlehttp/guzzle": "^7.9|8.*"
31+
"illuminate/config": "12.*|13.*",
32+
"illuminate/http": "12.*|13.*",
33+
"illuminate/log": "12.*|13.*",
34+
"illuminate/events": "12.*|13.*",
35+
"illuminate/support": "12.*|13.*",
36+
"guzzlehttp/guzzle": "^7.10|8.*"
3737
},
3838
"require-dev": {
39-
"orchestra/testbench": "^9.16|10.*",
40-
"livewire/livewire": "3.*|4.*",
39+
"orchestra/testbench": "10.*|11.*",
40+
"livewire/livewire": "3.*|4.*|5.*",
4141
"filament/actions": "4.*|5.*"
4242
},
4343
"autoload": {

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd" cacheDirectory=".phpunit.cache">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/13.0/phpunit.xsd" cacheDirectory=".phpunit.cache">
33
<testsuites>
44
<testsuite name="Test Suite">
55
<directory>tests</directory>

src/Events/TransactionCompleted.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Laragear\Transbank\ApiRequest;
66
use Laragear\Transbank\Services\Transactions\Transaction;
77

8-
class TransactionCompleted
8+
readonly class TransactionCompleted
99
{
1010
/**
1111
* Create a new Transaction Completed event.

src/Events/TransactionCreated.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Laragear\Transbank\ApiRequest;
66
use Laragear\Transbank\Services\Transactions\Response;
77

8-
class TransactionCreated
8+
readonly class TransactionCreated
99
{
1010
/**
1111
* Create a new Transaction Created event.

src/Events/TransactionCreating.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Laragear\Transbank\ApiRequest;
66

7-
class TransactionCreating
7+
readonly class TransactionCreating
88
{
99
/**
1010
* Create a new Transaction Creating event.

src/Http/Client.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,27 @@ class Client
2121
/**
2222
* Current API Version to use on Transbank Servers.
2323
*/
24-
public const API_VERSION = 'v1.3';
24+
public const string API_VERSION = 'v1.3';
2525

2626
/**
2727
* Transbank API Key header name.
2828
*/
29-
public const HEADER_KEY = 'Tbk-Api-Key-Id';
29+
public const string HEADER_KEY = 'Tbk-Api-Key-Id';
3030

3131
/**
3232
* Transbank API Shared Secret header name.
3333
*/
34-
public const HEADER_SECRET = 'Tbk-Api-Key-Secret';
34+
public const string HEADER_SECRET = 'Tbk-Api-Key-Secret';
3535

3636
/**
3737
* Production endpoint server.
3838
*/
39-
public const PRODUCTION_ENDPOINT = 'https://webpay3g.transbank.cl/';
39+
public const string PRODUCTION_ENDPOINT = 'https://webpay3g.transbank.cl/';
4040

4141
/**
4242
* Integration endpoint server.
4343
*/
44-
public const INTEGRATION_ENDPOINT = 'https://webpay3gint.transbank.cl/';
44+
public const string INTEGRATION_ENDPOINT = 'https://webpay3gint.transbank.cl/';
4545

4646
/**
4747
* Create a new HTTP Client instance.
@@ -56,6 +56,7 @@ public function __construct(protected ConfigContract $config, protected HttpFact
5656
*/
5757
public function send(string $method, string $endpoint, ApiRequest $request): Response
5858
{
59+
/** @var \Illuminate\Http\Client\PendingRequest $pendingRequest */
5960
$pendingRequest = $this->http
6061
->withoutRedirecting()
6162
->retry($this->config->get('transbank.http.retries'))

src/Http/Requests/WebpayRequest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@
44

55
use Closure;
66
use Illuminate\Foundation\Http\FormRequest;
7-
use Illuminate\Support\Str;
8-
use Illuminate\Validation\ValidationException;
97
use Laragear\Transbank\Services\Transactions\Transaction;
108
use Laragear\Transbank\Services\Webpay;
11-
use function is_bool;
129
use function is_callable;
13-
use function value;
1410

1511
class WebpayRequest extends FormRequest
1612
{

src/Livewire/InteractsWithWebpay.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ trait InteractsWithWebpay
1515
* @var string
1616
*/
1717
#[Url]
18-
public $token_ws = '';
18+
public ?string $token_ws = null;
1919

2020
/**
2121
* The Webpay Token for failed transactions.
2222
*
2323
* @var string
2424
*/
2525
#[Url]
26-
public $TBK_TOKEN = '';
26+
public ?string $TBK_TOKEN = null;
2727

2828
/**
2929
* Determines if the transaction was successful or not.

0 commit comments

Comments
 (0)