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/liqpay
Or include manually:
require_once 'path/to/LiqPay.php';
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',
]);
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.
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:
InvalidArgumentException
if keys are empty.
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 includeversion
andaction
(e.g.,'pay'
).$timeout
(int) — Timeout in seconds (connect + exec).
- Returns:
- JSON-decoded object on success.
['error' => '...']
on failure.
- Exceptions:
InvalidArgumentException
if required params missing.
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.,
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',
]);
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>', ]
Compute the signature for given parameters (used in custom integrations).
public function cnb_signature(array $params): string
Decode Base64‑encoded payment data back to an array.
public function decode_params(string $data): array
Generate a Base64‑SHA1 signature for any string.
public function str_to_sign(string $str): string