PHP code example of nokimaro / liontech-php-sdk

1. Go to this page and download the library: Download nokimaro/liontech-php-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nokimaro / liontech-php-sdk example snippets




okimaro\LionTech\Client;

$liontech = new Client(
    accessToken: 'your_access_token_here',
    // refreshToken: 'your_refresh_token',
    // baseUrl: 'https://api.sandbox.fusionpayments.io',
);



use Nokimaro\LionTech\Client;
use Nokimaro\LionTech\Requests\CreateOrderRequest;
use Nokimaro\LionTech\Requests\CustomerData;
use Nokimaro\LionTech\ValueObjects\Currency;
use Nokimaro\LionTech\ValueObjects\Money;

$orderRequest = new CreateOrderRequest(
    amount: new Money('100.00', Currency::USD),
    customer: new CustomerData(
        email: '[email protected]',
        fullName: 'John Doe',
        ip: '192.168.1.1',
    ),
    autoApprove: true,
    successUrl: 'https://your-site.com/success',
    declineUrl: 'https://your-site.com/decline',
    webhookUrl: 'https://your-site.com/webhook',
    description: 'Order #12345',
);

$order = $liontech->orders()->create($orderRequest);

echo "Order ID: {$order->orderId}\n";
echo "Pay URL: {$order->payUrl}\n";



use Nokimaro\LionTech\Requests\CreatePaymentRequest;
use Nokimaro\LionTech\Requests\CustomerData;
use Nokimaro\LionTech\ValueObjects\Currency;
use Nokimaro\LionTech\ValueObjects\EncryptedCardData;
use Nokimaro\LionTech\ValueObjects\Money;
use Nokimaro\LionTech\ValueObjects\PaymentData;

// Encrypt the card data before sending
$encryptor = $liontech->cardEncryptor();
$encryptedCard = $encryptor->encryptForPayment([
    'pan' => '4405639704015096',
    'cvv' => '123',
    'exp_month' => 12,
    'exp_year' => 2030,
    'cardHolder' => 'John Doe',
]);

$paymentRequest = new CreatePaymentRequest(
    amount: new Money('50.00', Currency::USD),
    paymentData: PaymentData::card(new EncryptedCardData(
        encryptedCardData: $encryptedCard['encryptedCardData'],
        cardHolder: $encryptedCard['cardHolder'],
    )),
    customer: new CustomerData(
        email: '[email protected]',
        ip: '192.168.1.1',
        fingerprint: 'browser_fingerprint_here',
    ),
    orderId: 'ord_123',
    autoApprove: true,
    backLink: 'https://your-site.com/payment-result',
);

$payment = $liontech->payments()->create($paymentRequest);

if ($payment->



use Nokimaro\LionTech\Requests\CreateRefundRequest;
use Nokimaro\LionTech\ValueObjects\Currency;
use Nokimaro\LionTech\ValueObjects\Money;

$refundRequest = new CreateRefundRequest(
    amount: new Money('25.00', Currency::USD),
    paymentId: 'pay_123',
    webhookUrl: 'https://your-site.com/webhook',
);

$refund = $liontech->refunds()->create($refundRequest);

echo "Refund ID: {$refund->refundId}\n";
echo "Status: {$refund->status->value}\n";



use Nokimaro\LionTech\Webhooks\WebhookPayload;

$payload = file_get_contents('php://input');
$headers = getallheaders();

if (! $liontech->webhookVerifier()->verify($headers, $payload)) {
    http_response_code(401);
    exit;
}

$webhook = WebhookPayload::fromJson($payload);
$payment = $webhook->payment;

if ($payment->isSuccessful()) {
    // Payment confirmed — fulfil the order
    echo "Order {$payment->orderId} paid (txn: {$payment->txnId})";
} elseif ($payment->isDeclined()) {
    // Payment declined — notify the customer
    $reason = $webhook->error?->description ?? 'Unknown reason';
    echo "Payment {$payment->paymentId} declined: {$reason}";
}

http_response_code(200);



use Nokimaro\LionTech\Requests\RefreshTokenRequest;

$refreshRequest = new RefreshTokenRequest(
    refreshToken: 'your_current_refresh_token',
);

$response = $liontech->auth()->refreshAndApply($refreshRequest);

echo "New access token: {$response->accessToken}\n";
echo "Expires at: {$response->accessTokenExpireAt->format('Y-m-d H:i:s')}\n";

// Authentication & Token Management
$liontech->auth()->refreshTokens($request);
$liontech->auth()->refreshAndApply($request);

// Orders
$liontech->orders()->create($request);
$liontech->orders()->createWithId('custom_id', $request);
$liontech->orders()->get('order_id');
$liontech->orders()->cancel('order_id');
$liontech->orders()->close('order_id');

// Payments
$liontech->payments()->create($request);
$liontech->payments()->createWithId('custom_id', $request);
$liontech->payments()->get('payment_id');
$liontech->payments()->confirm('payment_id');
$liontech->payments()->getRefunds('payment_id');

// Refunds
$liontech->refunds()->create($request);
$liontech->refunds()->createWithId('custom_id', $request);
$liontech->refunds()->get('refund_id');

// Payouts
$liontech->payouts()->createWithId('custom_id', $request);
$liontech->payouts()->get('payout_id');

// Tokens (Saved Payment Methods)
$liontech->tokens()->list(accountId: 'acc_123');
$liontech->tokens()->delete('token_id');

// Balances
$liontech->balances()->list();

// Transfers
$liontech->transfers()->create($data);
$liontech->transfers()->get('transfer_id');

// Signature
$liontech->signature()->getPublicKey();

// Webhook Signature Verification
$verifier = $liontech->webhookVerifier();          // auto-fetches public key
$verifier = $liontech->webhookVerifier($pemKey);   // or provide your own
$isValid = $verifier->verify($headers, $payload);

// Card Encryption
$encryptor = $liontech->cardEncryptor();           // auto-fetches encryption key
$encryptor = $liontech->cardEncryptor($pemKey);    // or provide your own
$encrypted = $encryptor->encryptForPayment([
    'pan' => '4405639704015096',
    'cvv' => '123',
    'exp_month' => 12,
    'exp_year' => 2030,
    'cardHolder' => 'John Doe',
]);

use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Psr7\HttpFactory;
use Nokimaro\LionTech\Client;
use Nokimaro\LionTech\Http\Transport;

$transport = new Transport(
    baseUrl: 'https://api.fusionpayments.io',
    client: new GuzzleClient(),
    requestFactory: new HttpFactory(),
    streamFactory: new HttpFactory(),
);

$liontech = new Client(
    accessToken: 'your_token',
    httpClient: $transport,
);

use Nokimaro\LionTech\Client;

// Via constructor
$liontech = new Client(
    accessToken: 'your_sandbox_token',
    baseUrl: 'https://api.sandbox.fusionpayments.io',
    secureUrl: 'https://secure.sandbox.fusionpayments.io',
);

// Via builder
$liontech = Client::builder()
    ->accessToken('your_sandbox_token')
    ->sandbox()
    ->build();

use Nokimaro\LionTech\Exceptions\Auth\AuthenticationException;
use Nokimaro\LionTech\Exceptions\Auth\TokenExpiredException;
use Nokimaro\LionTech\Exceptions\Business\ConflictException;
use Nokimaro\LionTech\Exceptions\RateLimitException;
use Nokimaro\LionTech\Exceptions\ResourceNotFoundException;
use Nokimaro\LionTech\Exceptions\Transport\TransportException;
use Nokimaro\LionTech\Exceptions\Validation\ValidationException;

try {
    $payment = $liontech->payments()->create($request);
} catch (TokenExpiredException $e) {
    // Token expired — refresh and retry
    $liontech->auth()->refreshAndApply($refreshRequest);
    $payment = $liontech->payments()->create($request);
} catch (ValidationException $e) {
    // Invalid request data
    $errors = $e->getErrors();
} catch (ResourceNotFoundException $e) {
    // Resource doesn't exist
} catch (AuthenticationException $e) {
    // Authentication failed
} catch (RateLimitException $e) {
    // Too many requests
} catch (TransportException $e) {
    // Network or server error
}
bash
composer