sextanet / laravel-webpay
Laravel Webpay
Fund package maintenance!
SextaNet
Requires
- php: ^8.1
- illuminate/contracts: ^10.0||^11.0
- spatie/laravel-package-tools: ^1.16
- transbank/transbank-sdk: ^4.0
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
README
Laravel, Transbank, Webpay and SextaNet products and logos are property of their respective companies.
The easiest way to use Webpay in your projects
Installation
You can install the package via composer:
composer require sextanet/laravel-webpay
Publish and run migrations
php artisan vendor:publish --tag="webpay-migrations"
php artisan migrate
Copy these keys in your .env
file
WEBPAY_IN_PRODUCTION=false WEBPAY_COMMERCE_CODE= WEBPAY_SECRET_KEY= WEBPAY_DEBUG=true
Usage
With attached model (recommended)
// 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:
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!
Setting custom URLs
For convenience, you can set custom pages for each status before calling payWithOrder() method
Cancelled
LaravelWebpay::setCancelledUrl('/cancelled-page');
Rejected
LaravelWebpay::setRejectedUrl('/rejected-page');
Testing cards
- Expire date: (Any valid date)
- RUT: 11111111-1
- Password: 123
Source: Official Transbank Developers website
Production mode
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
.
Alternative usage
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);
License
The MIT License (MIT). Please see License File for more information.