jonhwu/laravel-unitpay is a Laravel package for unitpay payments for laravel.
It currently has 0 GitHub stars and 11 downloads on Packagist (latest version v4.0.0).
Install it with composer require jonhwu/laravel-unitpay.
Discover more Laravel packages by jonhwu
or browse all Laravel packages to compare alternatives.
Last updated
Accept payments via UnitPay (unitpay.ru) using this Laravel framework package (Laravel).
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
Require this package with composer.
composer require "jonhwu/laravel-unitpay"
If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php
JonhWu\UnitPay\UnitPayServiceProvider::class,
Add the UnitPay facade to your facades array:
'UnitPay' => JonhWu\UnitPay\Facades\UnitPay::class,
Copy the package config to your local config with the publish command:
php artisan vendor:publish --provider="JonhWu\UnitPay\UnitPayServiceProvider"
Once you have published the configuration files, please edit the config file in config/unitpay.php.
public_key, secret_key params and paste into config/unitpay.phpconfig/unitpay.phpsearchOrder and paidOrderUnitPay::handle method$amount = 100; // Payment`s amount
$email = "[email protected]"; // Your customer`s email
$description = "Test payment";
//
$url = UnitPay::getPayUrl($amount, $order_id, $email, $description, $currency);
$redirect = UnitPay::redirectToPayUrl($amount, $order_id, $email, $description, $currency);
UnitPay::handle(Request $request)
You must define callbacks in config/unitpay.php to search the order and save the paid order.
'searchOrder' => null // UnitPayController@searchOrder(Request $request)
'paidOrder' => null // UnitPayController@paidOrder(Request $request, $order)
The process scheme:
unitpay.ru GET http://yourproject.com/unitpay/result (with params).UnitPayController@handlePayment runs the validation process (auto-validation request params).searchOrder will be called (see config/unitpay.php searchOrder) to search the order by the unique id.paid in your database, the method paidOrder will be called (see config/unitpay.php paidOrder).Add the route to routes/web.php:
Route::get('/unitpay/result', 'UnitPayController@handlePayment');
Note: don't forget to save your full route url (e.g. http://example.com/unitpay/result ) for your project on unitpay.ru.
Create the following controller: /app/Http/Controllers/UnitPayController.php:
class UnitPayController 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 UnitPay::handle($request);
}
}
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please send me an email at [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.