Package for integrating LiqPay into Laravel application. It allows generating payment links, signing requests, and handling incoming webhook events from LiqPay.
- PHP 8.1+
- Laravel 9+
Add the package via Composer:
composer require alyakin/liqpay-laravel
Publishing Configuration:
php artisan vendor:publish --tag=liqpay-config
After publishing, the configuration file config/liqpay.php
contains:
public_key
— public key from LiqPayprivate_key
— private key from LiqPayresult_url
— URL to redirect the user after paymentserver_url
— URL for programmatic notifications (webhook)
All parameters can be overridden via the .env
file:
LIQPAY_PUBLIC_KEY=your_public_key
LIQPAY_PRIVATE_KEY=your_private_key
LIQPAY_RESULT_URL="${APP_URL}/billing"
LIQPAY_SERVER_URL="/api/liqpay/webhook"
use Alyakin\LiqPayLaravel\Contracts\LiqPayServiceInterface as LiqPay;
use Alyakin\LiqPayLaravel\DTO\LiqPayRequestDto;
$liqpay = app(LiqPay::class);
$url = $liqpay->getPaymentUrl(LiqPayRequestDto::fromArray([
'version' => 3,
'public_key' => config('liqpay.public_key'),
'action' => 'pay',
'amount' => 100,
'currency' => 'UAH',
'description' => 'Payment #'.($a = rand(1000,9999)),
'language' => 'ua',
'order_id' => 'ORDER-'.$a,
'result_url' => config('liqpay.result_url'),
'server_url' => config('app.url').config('liqpay.server_url'),
]));
return redirect($url);
The package automatically registers the route /api/liqpay/webhook
(route from the config) and includes a handler for incoming requests.
When the webhook is triggered, the following events are fired:
LiqpayWebhookReceived
- occurs when ANY webhook from LiqPay is received
After the general event is called, events corresponding to statuses will be triggered:
LiqpayPaymentFailed
- occurs on payment failureLiqpayPaymentSucceeded
- occurs on successful paymentLiqpayPaymentWaiting
- occurs when payment is pendingLiqpayReversed
- occurs when a payment is reversedLiqpaySubscribed
- occurs when subscribed to paymentsLiqpayUnsubscribed
- occurs when unsubscribed from payments
To handle these events in your Laravel application, you can register corresponding event listeners.
Example of registering a listener for the LiqpayPaymentSucceeded
event:
namespace App\Listeners;
use Alyakin\LiqpayLaravel\Events\LiqpayPaymentSucceeded;
class HandleLiqpayPaymentSucceeded
{
public function handle(LiqpayPaymentSucceeded $event)
{
\Log::debug(__method__, $event->dto->toArray());
// Your code for handling successful payment
}
}
The event has a property dto
, which is an object.
You can also enable the built-in event handler LiqpayWebhookReceived
to log all incoming webhooks by registering in app/Providers/EventServiceProvider.php
in the boot
method as follows:
Event::listen(
\Alyakin\LiqPayLaravel\Events\LiqpayWebhookReceived::class,
\Alyakin\LiqPayLaravel\Listeners\LogLiqPayWebhook::class,
);
All tests can be found in the folder with tests
To run the tests, use the command
composer test
This package is distributed under the MIT License.