PHP SDK
lunixi/php-sdk is the framework-agnostic PHP client for Lunixi. Ed25519 request signing, the token exchange and cache, idempotency keys and money-safe retries live in the SDK. The Laravel and WordPress/WooCommerce integrations are built on it too.
Installation
composer require lunixi/php-sdkPHP 7.4 or newer with ext-sodium, ext-curl, ext-json and ext-hash is required.
Package: Packagist (opens in a new tab) · Source code: GitHub (opens in a new tab)
If you use Laravel, start with the Laravel package, which provides .env configuration, a facade, a webhook route and a Blade component; it installs this SDK itself.
Creating the client
use Lunixi\Sdk\LunixiClient;
$lunixi = LunixiClient::create([
'baseUrl' => 'https://api-gateway.lunixi.com',
'keyId' => getenv('LUNIXI_KEY_ID'),
'privateKey' => getenv('LUNIXI_PRIVATE_KEY_PEM'),
'environment' => 'LIVE',
]);| Option | Required | Default |
|---|---|---|
baseUrl | yes | — |
keyId | yes | — |
privateKey | yes | — |
environment | no | LIVE (only LIVE or TEST) |
timeout | no | 30 (seconds) |
maxRetries | no | 2 |
privateKey is the private key in the PKCS#8 PEM format the dashboard gives you.
Key pair
use Lunixi\Sdk\Auth\Ed25519Signer;
$keys = Ed25519Signer::generateKeyPair();
// $keys['publicKey'] → register it in the dashboard
// $keys['privateKey'] → keep it on your own server onlyClients
| Product | Access |
|---|---|
| Payments | $lunixi->payments() |
| Payment links | $lunixi->paymentLinks() |
| Subscriptions | $lunixi->subscriptions() |
| Fraud | $lunixi->fraud() |
| KYC | $lunixi->kyc() |
| Sanction | $lunixi->sanction() |
| Marketplace | $lunixi->marketplace() |
| Identity | $lunixi->identity() |
| Wallet | $lunixi->wallet() |
| Bank accounts | $lunixi->bankConnect() |
| Reference data (address codes) | $lunixi->reference() |
| Insurance | $lunixi->insurance() |
| Webhook verification | $lunixi->webhooks() |
Payment operations
use Lunixi\Sdk\Payment\CreateIntentRequest;
$intent = $lunixi->payments()->createIntent(
(new CreateIntentRequest(1000, 'TRY', 'WC-1042'))->withCallbackUrl('https://shop.example/lunixi/return'),
'checkout:WC-1042'
);
$paymentId = $intent->paymentId();
$script = $intent->checkoutFormContent(); // opens the Checkout Form on your payment page
$lunixi->payments()->capture($paymentId, 500, 'capture:WC-1042'); // partial capture
$lunixi->payments()->refund($paymentId, 300, 'return', 'refund:WC-1042-1');
$payment = $lunixi->payments()->get($paymentId);
if ($payment->isCaptured()) {
// ...
}Amounts are integers in the currency's minor unit (1000 = 10.00 TRY). Without an amount, capture and refund cover the full amount. Send a stable idempotency key per operation on every money-moving call, and use the same key when you retry the same operation.
Webhook verification
use Lunixi\Sdk\Exception\WebhookVerificationException;
use Lunixi\Sdk\Webhook\WebhookVerifier;
try {
$event = (new WebhookVerifier())->verify($rawBody, $requestHeaders, $endpointSecret);
} catch (WebhookVerificationException $e) {
http_response_code(400);
return; // never act on an unverified payload
}
// delivery is at least once: dedupe on $event->id()
if ($event->matches('payment.*')) {
// update the order from $event->data()
}$rawBody is the raw body. Verification is fail-closed and checks a 300-second timestamp window by default. → Webhooks
Errors
SDK exceptions live under Lunixi\Sdk\Exception: ApiException for API answers, AuthenticationException when no token can be obtained, ConfigurationException for local configuration and request rules, WebhookVerificationException for webhooks. ConfigurationException is thrown before anything goes on the network; the request was not sent.
Payment methods, split payments, promissory notes, payment links, wallet, bank accounts, insurance and sanction calls are described on their product pages; the PHP examples there use this SDK.
Related
- Laravel — the Laravel package on top of this SDK
- Authentication — key, signature and token lifetime
- Error Handling — response envelope and error codes