alyakin/liqpay-laravel

Laravel package for LiqPay integration

0.1.3 2025-05-12 08:09 UTC

This package is auto-updated.

Last update: 2025-05-16 19:26:53 UTC


README

Latest Version on Packagist Downloads Laravel PHP License

PHPUnit Laravel Pint Larastan

Package for integrating LiqPay into Laravel application. It allows generating payment links, signing requests, and handling incoming webhook events from LiqPay.

Table of Contents

Requirements

  • PHP 8.1+
  • Laravel 9+

Installation

Add the package via Composer:

composer require alyakin/liqpay-laravel

Publishing Configuration:

php artisan vendor:publish --tag=liqpay-config

Configuration

After publishing, the configuration file config/liqpay.php contains:

  • public_key — public key from LiqPay
  • private_key — private key from LiqPay
  • result_url — URL to redirect the user after payment
  • server_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"

Usage

Generating Payment Link

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);

Handling LiqPay Webhook

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 failure
  • LiqpayPaymentSucceeded - occurs on successful payment
  • LiqpayPaymentWaiting - occurs when payment is pending
  • LiqpayReversed - occurs when a payment is reversed
  • LiqpaySubscribed - occurs when subscribed to payments
  • LiqpayUnsubscribed - 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,
);

Testing

All tests can be found in the folder with tests

To run the tests, use the command

composer test

License

This package is distributed under the MIT License.