forksoft / laravel-primepayments
PrimePayments payments for Laravel
Requires
- php: >=7.4
- guzzlehttp/guzzle: 7.*
- laravel/framework: 8.* || 9.* || 10.* || 11.*
Requires (Dev)
- orchestra/testbench: 6.*
- phpunit/phpunit: ^9.3
This package is not auto-updated.
Last update: 2025-10-03 22:47:36 UTC
README
Accept payments via PrimePayments (primepayments.ru) using this Laravel framework package (Laravel).
- receive payments, adding just the two callbacks
Laravel >= 8.*, PHP >= 7.3
Installation
Require this package with composer.
composer require forksoft/laravel-primepayments
If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php
Forksoft\PrimePayments\PrimePaymentsServiceProvider::class,
Add the PrimePayments
facade to your facades array:
'PrimePayments' => Forksoft\PrimePayments\Facades\PrimePayments::class,
Copy the package config to your local config with the publish command:
php artisan vendor:publish --provider="Forksoft\PrimePayments\PrimePaymentsServiceProvider"
Configuration
Once you have published the configuration files, please edit the config file in config/primepayments.php
.
- Create an account on primepayments.ru
- Add your project, copy the
project_id
,secret_key
andsecret_key_second
params and paste intoconfig/primepayments.php
- After the configuration has been published, edit
config/primepayments.php
- Set the callback static function for
searchOrder
andpaidOrder
- Create route to your controller, and call
PrimePayments::handle
method
Usage
- Generate a payment url or get redirect:
$sum = 100; // Payment`s sum $url = PrimePayments::getPayUrl($sum, $order_id, $email, $comment); $redirect = PrimePayments::redirectToPayUrl($sum, $order_id, $email, $comment);
You can add custom fields to your payment:
$url = PrimePayments::getPayUrl($sum, $order_id, $email, $comment); $redirect = PrimePayments::redirectToPayUrl($sum, $order_id, $email, $comment);
$email
and $phone
can be null.
- Process the request from PrimePayments:
PrimePayments::handle(Request $request)
Important
You must define callbacks in config/primepayments.php
to search the order and save the paid order.
'searchOrder' => null // PrimePaymentsController@searchOrder(Request $request)
'paidOrder' => null // PrimePaymentsController@paidOrder(Request $request, $order)
Example
The process scheme:
- The request comes from
primepayments.ru
GET
/POST
http://yourproject.com/primepayments/result
(with params). - The function
PrimePaymentsController@handlePayment
runs the validation process (auto-validation request params). - The method
searchOrder
will be called (seeconfig/primepayments.php
searchOrder
) to search the order by the unique id. - If the current order status is NOT
order_payed
in your database, the methodpaidOrder
will be called (seeconfig/primepayments.php
paidOrder
).
Add the route to routes/web.php
:
Route::get('/primepayments/result', 'PrimePaymentsController@handlePayment');
Note: don't forget to save your full route url (e.g. http://example.com/primepayments/result ) for your project on primepayments.ru.
Create the following controller: /app/Http/Controllers/PrimePaymentsController.php
:
class PrimePaymentsController extends Controller { /** * Search the order in your database and return that order * to paidOrder, if status of your order is 'order_payed' * * @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 `order_payed` you can set them like string $order['_orderStatus'] = $order['status']; // Else your field doesn` has value like 'order_payed', you can change this value $order['_orderStatus'] = ('1' == $order['status']) ? 'order_payed' : 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 = 'order_payed'; $order->save(); // return true; } /** * Start handle process from route * * @param Request $request * @return mixed */ public function handlePayment(Request $request) { return PrimePayments::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 mail@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.