liqpay / liqpay
SDK for Liqpay
Requires
- php: >=7.0
Requires (Dev)
- phpunit/phpunit: >=10.4.1
This package is not auto-updated.
Last update: 2026-03-24 18:32:28 UTC
README
LiqPay PHP SDK for seamless integration with LiqPay payment gateway.
Documentation
For full API reference and details, see the LiqPay API documentation:
LiqPay API Docs
Table of Contents
Installation
Install via Composer:
composer require liqpay/liqpay
Or include manually:
require_once 'path/to/LiqPay.php';
Quick Start
use LiqPay; $liqpay = new LiqPay('your_public_key', 'your_private_key'); // Check payment status $response = $liqpay->api('payment/status', [ 'version' => 3, 'action' => 'status', 'order_id' => 'order123', ]); // Generate checkout form echo $liqpay->cnb_form([ 'version' => 3, 'action' => 'pay', 'amount' => 100.50, 'currency' => 'USD', 'description' => 'Order #123 Payment', 'language' => 'en', ]);
Usage
Public Methods
Methods Summary
| Method | Signature | Description |
|---|---|---|
api |
api(string $path, array $params = [], int $timeout = 5): object|array |
Call LiqPay API and return parsed response. |
get_response_code |
get_response_code(): int|null |
Last HTTP status code from API. |
cnb_form |
cnb_form(array $params): string |
Render HTML checkout form. |
cnb_form_raw |
cnb_form_raw(array $params): array |
Raw URL, data, and signature. |
cnb_signature |
cnb_signature(array $params): string |
Compute data signature for checkout. |
decode_params |
decode_params(string $data): array |
Decode Base64‑encoded payload. |
str_to_sign |
str_to_sign(string $str): string |
Generate Base64‑SHA1 signature. |
__construct
Initialize the LiqPay client with your credentials.
public function __construct( string $public_key, string $private_key, string|null $api_url = null )
- Parameters:
$public_key(string) — Your LiqPay public key.$private_key(string) — Your LiqPay private key.$api_url(string|null) — Override default API endpoint.
- Exceptions:
InvalidArgumentExceptionif keys are empty.
api
Send a request to a LiqPay API endpoint and get a parsed response.
public function api( string $path, array $params = [], int $timeout = 5 ): object\|array
- Parameters:
$path(string) — Endpoint path (e.g.,'payment/status').$params(array) — Must includeversionandaction(e.g.,'pay').$timeout(int) — Timeout in seconds (connect + exec).
- Returns:
- JSON-decoded object on success.
['error' => '...']on failure.
- Exceptions:
InvalidArgumentExceptionif required params missing.
get_response_code
Retrieve HTTP status code from the last api() call.
public function get_response_code(): int\|null
- Returns:
- HTTP status code (e.g.,
200) ornull.
- HTTP status code (e.g.,
cnb_form
Render a fully functional HTML checkout form with LiqPay JavaScript SDK.
public function cnb_form(array $params): string
- Parameters:
version,action,amount,currency,description(required)language(optional) —'uk','ru', or'en'.
- Returns:
- HTML
<form>string with embedded button.
- HTML
- Example:
echo $liqpay->cnb_form([ 'version' => 3, 'action' => 'paydonate', 'amount' => 5, 'currency' => 'UAH', 'description' => 'Support project', 'language' => 'uk', ]);
cnb_form_raw
Get raw payload data for custom form implementations.
public function cnb_form_raw(array $params): array
- Returns:
[ 'url' => 'https://www.liqpay.ua/api/3/checkout', 'data' => '<Base64 JSON>', 'signature' => '<Signature>', ]
cnb_signature
Compute the signature for given parameters (used in custom integrations).
public function cnb_signature(array $params): string
decode_params
Decode Base64‑encoded payment data back to an array.
public function decode_params(string $data): array
str_to_sign
Generate a Base64‑SHA1 signature for any string.
public function str_to_sign(string $str): string