maksa988 / laravel-freekassa
FreeKassa payments for Laravel
Installs: 2 703
Dependents: 0
Suggesters: 0
Security: 0
Stars: 14
Watchers: 3
Forks: 9
Open Issues: 3
pkg:composer/maksa988/laravel-freekassa
Requires
- php: >=7.3
- guzzlehttp/guzzle: 7.*
- laravel/framework: 8.*
Requires (Dev)
- orchestra/testbench: 6.*
- phpunit/phpunit: ^9.3
This package is auto-updated.
Last update: 2025-10-23 06:03:22 UTC
README
Accept payments via FreeKassa (free-kassa.ru) using this Laravel framework package (Laravel).
- receive payments, adding just the two callbacks
Laravel >= 8.*, PHP >= 7.3
To use the package for Laravel 7.* use the 3.x branch
To use the package for Laravel 6.* use the 2.x branch
To use the package for Laravel 5.* use the 1.x branch
Installation
Require this package with composer.
composer require maksa988/laravel-freekassa
If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php
Maksa988\FreeKassa\FreeKassaServiceProvider::class,
Add the FreeKassa facade to your facades array:
'FreeKassa' => Maksa988\FreeKassa\Facades\FreeKassa::class,
Copy the package config to your local config with the publish command:
php artisan vendor:publish --provider="Maksa988\FreeKassa\FreeKassaServiceProvider"
Configuration
Once you have published the configuration files, please edit the config file in config/freekassa.php.
- Create an account on free-kassa.ru
- Add your project, copy the
project_id,secret_keyandsecret_key_secondparams and paste intoconfig/freekassa.php - After the configuration has been published, edit
config/freekassa.php - Set the callback static function for
searchOrderandpaidOrder - Create route to your controller, and call
FreeKassa::handlemethod
Usage
- Generate a payment url or get redirect:
$amount = 100; // Payment`s amount $url = FreeKassa::getPayUrl($amount, $order_id); $redirect = FreeKassa::redirectToPayUrl($amount, $order_id);
You can add custom fields to your payment:
$rows = [ 'time' => Carbon::now(), 'info' => 'Local payment' ]; $url = FreeKassa::getPayUrl($amount, $order_id, $email, $phone, $rows); $redirect = FreeKassa::redirectToPayUrl($amount, $order_id, $email, $phone, $rows);
$email and $phone can be null.
- Process the request from FreeKassa:
FreeKassa::handle(Request $request)
Important
You must define callbacks in config/freekassa.php to search the order and save the paid order.
'searchOrder' => null // FreeKassaController@searchOrder(Request $request)
'paidOrder' => null // FreeKassaController@paidOrder(Request $request, $order)
Example
The process scheme:
- The request comes from
free-kassa.ruGET/POSThttp://yourproject.com/freekassa/result(with params). - The function
FreeKassaController@handlePaymentruns the validation process (auto-validation request params). - The method
searchOrderwill be called (seeconfig/freekassa.phpsearchOrder) to search the order by the unique id. - If the current order status is NOT
paidin your database, the methodpaidOrderwill be called (seeconfig/freekassa.phppaidOrder).
Add the route to routes/web.php:
Route::get('/freekassa/result', 'FreeKassaController@handlePayment');
Note: don't forget to save your full route url (e.g. http://example.com/freekassa/result ) for your project on free-kassa.ru.
Create the following controller: /app/Http/Controllers/FreeKassaController.php:
class FreeKassaController extends Controller { /** * Search the order in your database and return that order * to paidOrder, if status of your order is 'paid' * * @param Request $request * @param $order_id * @return bool|mixed */ public function searchOrder(Request $request, $order_id) { $order = Order::where('id', $order_id)->first(); if($order) { $order['_orderSum'] = $order->sum; // If your field can be `paid` you can set them like string $order['_orderStatus'] = $order['status']; // Else your field doesn` has value like 'paid', you can change this value $order['_orderStatus'] = ('1' == $order['status']) ? 'paid' : false; return $order; } return false; } /** * When paymnet is check, you can paid your order * * @param Request $request * @param $order * @return bool */ public function paidOrder(Request $request, $order) { $order->status = 'paid'; $order->save(); // return true; } /** * Start handle process from route * * @param Request $request * @return mixed */ public function handlePayment(Request $request) { return FreeKassa::handle($request); } }
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please send me an email at maksa988ua@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.