nokimaro/liontech-php-sdk
Community-maintained PHP 8.3+ SDK for FusionPayments (formerly LionTech). Type-safe, domain-oriented API covering orders, payments, refunds, payouts, tokens, transfers, balances; PSR-18 compatible, supports token refresh, webhook verification, and RSA card encryption.
Install the SDK:
composer require nokimaro/liontech-php-sdk
For Laravel, use the dedicated wrapper:
composer require nokimaro/liontech-laravel
Initialize the Client (Laravel example):
use Nokimaro\LionTech\Laravel\Facades\LionTech;
$liontech = LionTech::client(); // Uses config/liontech.php
Or manually:
use Nokimaro\LionTech\Client;
$liontech = new Client(
accessToken: config('liontech.access_token'),
baseUrl: config('liontech.base_url')
);
First Use Case: Create an Order
$order = $liontech->orders()->create(new CreateOrderRequest(
amount: new Money('100.00', Currency::USD),
customer: new CustomerData(
email: 'user@example.com',
fullName: 'John Doe',
ip: request()->ip(),
),
successUrl: route('payment.success'),
declineUrl: route('payment.decline'),
description: 'Order #123'
));
Redirect users to $order->payUrl.
Payment Flow
orderId in DB).payments()->create().requiresRedirect().payments()->confirm().// Example: Process payment with saved token
$payment = $liontech->payments()->create(new CreatePaymentRequest(
amount: new Money('50.00', Currency::USD),
paymentData: PaymentData::token('tok_123'),
orderId: 'ord_456',
));
Webhook Handling
public function handle(Request $request, Closure $next) {
$liontech = LionTech::client();
$verifier = $liontech->webhookVerifier();
if (!$verifier->verify($request->header(), $request->getContent())) {
abort(401);
}
return $next($request);
}
$webhook = WebhookPayload::fromJson($request->getContent());
if ($webhook->payment->isSuccessful()) {
// Fulfill order
}
Token Management
expiresAt.try {
$liontech->payments()->create(...);
} catch (TokenExpiredException $e) {
$liontech->auth()->refreshAndApply(new RefreshTokenRequest(
refreshToken: $storedRefreshToken
));
retry();
}
liontech-laravel to bind the client to the container.\Log::info('Payment created', [
'payment_id' => $payment->paymentId,
'amount' => $payment->amount->value,
'currency' => $payment->amount->currency->value,
]);
5522 0427 0506 6736 for 3DS flows).Token Expiry
TokenExpiredException and refresh tokens. Use the refreshAndApply() method to update the client’s token automatically.refreshToken securely (e.g., encrypted in DB).Webhook Verification
webhookVerifier() in middleware or controllers.$verifier = $liontech->webhookVerifier()->withCachedKey();
Required Fields
CreateOrderRequest::$description and CreateRefundRequest::$webhookUrl are required (API returns 400 if omitted).$request = new CreateOrderRequest(
amount: new Money('100.00', Currency::USD),
customer: new CustomerData(...),
description: 'Order #123', // <-- Required!
// ...
);
3DS Redirects
requiresRedirect() before redirecting users.if ($payment->requiresRedirect()) {
return redirect()->away($payment->getRedirectUrl());
}
Card Encryption
cardEncryptor():
$encrypted = $liontech->cardEncryptor()->encryptForPayment([
'pan' => '4111111111111111',
'exp_month' => 12,
'exp_year' => 2030,
]);
Error Handling
Exception and losing context.try {
$liontech->payments()->create($request);
} catch (ValidationException $e) {
// Log $e->getErrors()
} catch (RateLimitException $e) {
retryAfter($e->getRetryAfter());
}
LIONTECH_DEBUG=true in .env to log raw API responses.dd($liontech->getLastRequest()->getHeaders()) to inspect requests.4405 6397 0401 5096 for non-3DS payments).Custom HTTP Client
HttpClient or another PSR-18 client:
$liontech = new Client(
accessToken: '...',
httpClient: new Transport(
client: new Symfony\Contracts\HttpClient\HttpClient(),
),
);
Webhook Payload Parsing
WebhookPayload to add custom logic:
$webhook = WebhookPayload::fromJson($payload);
if ($webhook->eventType === WebhookEventType::PAYMENT_CONFIRMED) {
// Custom logic
}
Retry Logic
RateLimitException:
use Symfony\Component\ErrorHandler\RetryableErrorInterface;
if ($e instanceof RateLimitException) {
throw new RetryableErrorInterface($e->getMessage(), $e->getRetryAfter());
}
Mocking for Tests
Mockery or PHPUnit to mock the client:
$mockClient = Mockery::mock(Client::class);
$mockClient->shouldReceive('payments()->create')
->andReturn(new PaymentResponse(...));
fusionpayments.io, but you can override it:
$liontech = new Client(
accessToken: '...',
baseUrl: 'https://api.liontechnology.ai', // Legacy support
);
$liontech = Client::builder()
->accessToken('sandbox_token')
->sandbox() // Auto-configures sandbox URLs
->build();
config/liontech.php by default. Override with:
config(['liontech.access_token' => env('LIONTECH_ACCESS_TOKEN')]);
How can I help you explore Laravel packages today?