Laravel, Transbank, Webpay and SextaNet products and logos are property of their respective companies.
The easiest way to use Webpay in your projects
You can install the package via composer:
composer require sextanet/laravel-webpayPublish and run migrations
php artisan vendor:publish --tag="webpay-migrations"
php artisan migrateCopy these keys in your .env file
WEBPAY_IN_PRODUCTION=false
WEBPAY_COMMERCE_CODE=
WEBPAY_SECRET_KEY=
WEBPAY_DEBUG=true// app/Models/YourModel.php
use SextaNet\LaravelWebpay\Traits\PayWithWebpay; // π Import it
class YourModel
{
// ...
use HasFactory;
use PayWithWebpay; // π Use it!
}By default, it uses these 3 fields which are required by Transbank:
| Name | Description | Example |
|---|---|---|
| amount | Total price (integer format) | 10000 |
| order_id | Unique identifier for your transaction | 1 |
| session_id | Unique session for your transaction | 23d6436f95b1987cd616b85bae806649 |
If you use other names for your fields, no problem: you can make each model recognize them very easily using the following magic methods:
// app/Models/YourModel.php
public function getBuyOrderAttribute(): string
{
return $this->id; // Give it your custom logic
}
public function getAmountAttribute(): string
{
return $this->price; // Give it your custom logic: Don't need to use decimals
}
public function getSessionIdAttribute(): string
{
return md5($this->id); // Give it your custom logic
}// In your controller or equivalent
$order = YourOrder::where('id', 1)->first();
return $order->payWithWebpay(); // π Done!Easy peasy!
For convenience, you can set custom pages for each status before calling payWithOrder() method
LaravelWebpay::setCancelledUrl('/cancelled-page');LaravelWebpay::setRejectedUrl('/rejected-page');| Type | Numbers | Result |
|---|---|---|
| VISA | 4051 8856 0044 6623 | Approved |
| Mastercard | 5186 0595 5959 0568 | Rejected |
| Redcompra | 4051 8842 3993 7763 | Approved |
| VISA Prepaid | 4051 8860 0005 6590 | Approved |
- Expire date: (Any valid date)
- RUT: 11111111-1
- Password: 123
Source: Official Transbank Developers website
When you are ready to be in production, you need to set WEBPAY_IN_PRODUCTION to true, and specify WEBPAY_COMMERCE_CODE and WEBPAY_SECRET_KEY.
If you don't want to import Trait, you can create or instanciate a order, and then, calling LaravelWebpay::create($order) method, for example:
// In your controller or equivalent
$order = YourOrder::where('id', 1)->first();
// βοΈ Your order model needs to have: buy_order, session_id and amount fields
return LaravelWebpay::create($order);The MIT License (MIT). Please see License File for more information.