PHPackages                             darkghosthunter/larabanker - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. darkghosthunter/larabanker

ActiveLibrary

darkghosthunter/larabanker
==========================

Transbank SDK for Laravel

v2.0.1(4y ago)228MITPHPPHP &gt;=8.0

Since Apr 5Pushed 4y agoCompare

[ Source](https://github.com/DarkGhostHunter/Larabanker)[ Packagist](https://packagist.org/packages/darkghosthunter/larabanker)[ RSS](/packages/darkghosthunter-larabanker/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (5)Dependencies (10)Versions (8)Used By (0)

[![Paul Felberbauer - Unsplash (UL) #-idNOBU5k_80](https://camo.githubusercontent.com/f49edf5e45b201c28f6edda38849387e2cdff56ad2f773415a80cd4bb138dae0/68747470733a2f2f696d616765732e756e73706c6173682e636f6d2f70686f746f2d313539313033303433343436392d3364373863376231373832303f69786c69623d72622d312e322e3126697869643d65794a6863484266615751694f6a45794d446439266175746f3d666f726d6174266669743d63726f7026773d3132383026683d34303026713d3830)](https://camo.githubusercontent.com/f49edf5e45b201c28f6edda38849387e2cdff56ad2f773415a80cd4bb138dae0/68747470733a2f2f696d616765732e756e73706c6173682e636f6d2f70686f746f2d313539313033303433343436392d3364373863376231373832303f69786c69623d72622d312e322e3126697869643d65794a6863484266615751694f6a45794d446439266175746f3d666f726d6174266669743d63726f7026773d3132383026683d34303026713d3830)

[![Latest Stable Version](https://camo.githubusercontent.com/5ff442d6cb4d80d3576316c5228100ba4eb252fb509291f5821c2d79fb81077c/68747470733a2f2f706f7365722e707567782e6f72672f6461726b67686f737468756e7465722f6c61726162616e6b65722f762f737461626c65)](https://packagist.org/packages/darkghosthunter/larabanker) [![License](https://camo.githubusercontent.com/d876bbabc9219a001cbfbdb7feda1fc92b947e00108a9f7248798ddb49164108/68747470733a2f2f706f7365722e707567782e6f72672f6461726b67686f737468756e7465722f6c61726162616e6b65722f6c6963656e7365)](https://packagist.org/packages/darkghosthunter/larabanker) [![](https://camo.githubusercontent.com/27be105e8eb1e02212e6b9aebb4b9f4898875ba612b83bab93eb2725aa420ef0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6461726b67686f737468756e7465722f6c61726162616e6b65722e737667)](https://camo.githubusercontent.com/27be105e8eb1e02212e6b9aebb4b9f4898875ba612b83bab93eb2725aa420ef0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6461726b67686f737468756e7465722f6c61726162616e6b65722e737667) [![Coverage Status](https://camo.githubusercontent.com/fa49ea854af1953a14f34d59a0242d416742fb3c3a397775f22cecb8ef94721a/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f4461726b47686f737448756e7465722f4c61726162616e6b65722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/DarkGhostHunter/Larabanker?branch=master) [![Laravel Octane Compatible](https://camo.githubusercontent.com/70359a356da237cd29561bc5d0bb80baae775b5ff62f288ed324755382858342/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2532304f6374616e652d436f6d70617469626c652d737563636573733f7374796c653d666c6174266c6f676f3d6c61726176656c)](https://github.com/laravel/octane)

Larabanker - Transbank for Laravel
==================================

[](#larabanker---transbank-for-laravel)

This package connects the non-official [Transbank SDK](https://github.com/DarkGhostHunter/Transbank/) into your Laravel Application.

Requirements
------------

[](#requirements)

- PHP &gt;= 8.0
- Laravel 8.x

> Check older releases for older Laravel versions.

Installation
------------

[](#installation)

Call composer and require it into your application.

```
composer require darkghosthunter/larabanker
```

Documentation
-------------

[](#documentation)

This package mimics the Transbank SDK, so you should check the documentation of these services in Transbank Developer's site (in spanish).

- [Webpay](https://www.transbankdevelopers.cl/documentacion/webpay-plus#webpay-plus)
- [Webpay Mall](https://www.transbankdevelopers.cl/documentacion/webpay-plus#webpay-plus-mall)
- [Oneclick Mall](https://www.transbankdevelopers.cl/documentacion/oneclick)

Quickstart
----------

[](#quickstart)

To start using Transbank services, you can use the included `Webpay`, `WebpayMall` and `Oneclick` facades and the `redirect()` method, which use minimum parameters and returns a ready-made `GET` redirect to Transbank.

```
use DarkGhostHunter\Larabanker\Facades\Webpay;

return Webpay::redirect('buy-order#1230', 1000);
```

Alternatively, you can still have total control to create transactions using the facades.

```
use DarkGhostHunter\Larabanker\Facades\Webpay;

$response = Webpay::create('buyOrder#1230', 1000, route('payment'));

return redirect()->away($response, 303);
```

> Since API 1.2, Transbank services support `GET` redirects. There is no longer need to use views with Javascript redirection.

Redirects are made using [default route names](#dealing-with-post-and-session-destruction) that centralizes the payment endpoint.

Dealing with POST and Session destruction
-----------------------------------------

[](#dealing-with-post-and-session-destruction)

Laravel sets cookies as `SameSite: lax` by default. This means that the session is destroyed when a payment fails or is aborted. This happens because Transbank redirects using a `POST` method to your application without cookies, forcing Laravel to [recreate a new empty session](https://github.com/laravel/framework/issues/31442).

To avoid this, you should use the same path to receive the response from Transbank, but using a different controller for `GET` or `POST`. Larabanker conveniently uses one route name for each of Transbank services redirection points, which will be hit once the payment process ends.

ServiceURLNameYour hypothetical routeWebpayReturn URL`transbank.webpay``http://yourappurl.com/transbank/webpay`Webpay MallReturn URL`transbank.webpayMall``http://yourappurl.com/transbank/webpayMall`Oneclick MallResponse URL`transbank.oneclickMall``http://yourappurl.com/transbank/oneclickMall`You're free to [change these Route names in the config file](#redirection). Be sure to add your controllers for these routes to process the incoming response from Transbank.

In this example, we will disable the `web` middleware to avoid creating a new session, and return a view with a generic failure message.

```
use \DarkGhostHunter\Larabanker\Facades\Webpay;
use \Illuminate\Support\Facades\Route;

Route::get('transbank/webpay', function (Request $request) {
    $transaction = Webpay::commit($request->input('token_ws'));

    return view('payment.processed')->with('transaction', $transaction);
})->name('transbank.webpay');

Route::post('transaction/webpay, function (Request $request) {
    return view('payment.failed');
})->withoutMiddleware('web');
```

Configuration
-------------

[](#configuration)

While Larabanker is made to use conveniently without setting too much, you can go deeper by publishing the configuration file:

```
php artisan vendor:publish --provider="DarkGhostHunter\Larabanker\ServiceProvider"

```

You will receive the `larabanker.php` config file with the following contents:

```
