LiqPay PHP SDK for seamless integration with LiqPay payment gateway.
For full API reference and details, see the LiqPay API documentation:
LiqPay API Docs
Install via Composer:
composer require liqpay/liqpayOr include manually:
require_once'path/to/LiqPay.php';useLiqPay;
$liqpay = newLiqPay('your_public_key', 'your_private_key');
// Check payment status$response = $liqpay->api('payment/status', [
'version' => 3,
'action' => 'status',
'order_id' => 'order123',
]);
// Generate checkout formecho$liqpay->cnb_form([
'version' => 3,
'action' => 'pay',
'amount' => 100.50,
'currency' => 'USD',
'description' => 'Order #123 Payment',
'language' => 'en',
]);| 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. |
Initialize the LiqPay client with your credentials.
publicfunction __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.
Send a request to a LiqPay API endpoint and get a parsed response.
publicfunction 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.
Retrieve HTTP status code from the last api() call.
publicfunction get_response_code(): int\|null- Returns:
- HTTP status code (e.g.,
200) ornull.
- HTTP status code (e.g.,
Render a fully functional HTML checkout form with LiqPay JavaScript SDK.
publicfunction 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',
]);Get raw payload data for custom form implementations.
publicfunction cnb_form_raw(array$params): array- Returns:
[ 'url' => 'https://www.liqpay.ua/api/3/checkout', 'data' => '<Base64 JSON>', 'signature' => '<Signature>', ]
Compute the signature for given parameters (used in custom integrations).
publicfunction cnb_signature(array$params): stringDecode Base64‑encoded payment data back to an array.
publicfunction decode_params(string$data): arrayGenerate a Base64‑SHA1 signature for any string.
publicfunction str_to_sign(string$str): string