1. Go to this page and download the library: Download pspline/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/ */
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
$logger = new Logger('pspline');
$logger->pushHandler(new StreamHandler('logs/pspline.log'));
$psp = new PspLine($merchantId, $publicKey, $privateKey, [
'logger' => $logger,
]);
use PspLine\PspLine;
use PspLine\Http\GuzzleHttpClient;
use PspLine\Configuration;
$config = new Configuration($merchantId, $publicKey, $privateKey);
$guzzleClient = new GuzzleHttpClient($config);
$psp = new PspLine($merchantId, $publicKey, $privateKey, [
'http_client' => $guzzleClient,
]);
$invoice = $psp->invoices->create([
// Required
'service_id' => 885, // Service ID
'wallet_id' => 52205, // Wallet to credit
'currency' => 'USDT_TRON', // Currency code
'estimated_amount' => 15000000, // Amount in min units
// Optional
'external_id' => 'order-789', // Your system ID
'callback_url' => 'https://...',
'confirm_url' => 'https://...',
'fields' => ['user_id' => 'u001'],
]);
// Response
$invoice->id; // string — Invoice UUID
$invoice->walletAddress; // string|null — Crypto address
$invoice->walletMemo; // string|null — Memo (XRP, TON, etc.)
$invoice->verifyUrl; // string|null — Web payment form URL
$invoice->status; // int — Status code
$invoice->currency; // string — Currency code
$invoice->estimatedAmount; // int — Expected amount
$invoice->receivedAmount; // int — Actually received
// By PSP Line invoice ID
$invoice = $psp->invoices->find(['id' => 'invoice-uuid']);
// By your external ID
$invoice = $psp->invoices->find(['external_id' => 'order-789']);
// Check status
if ($invoice->isSuccessful()) {
// Payment completed — deliver goods
} elseif ($invoice->isPending()) {
// Still waiting — check again later
} elseif ($invoice->isFailed()) {
// Payment failed or timed out
}
use PspLine\Webhook\SignatureValidator;
$body = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_SIGNATURE'] ?? '';
$timestamp = $_SERVER['HTTP_TIMESTAMP'] ?? '';
$isValid = SignatureValidator::isValid(
$body,
$signature,
$timestamp,
'your-private-key',
120 // max age in seconds (default)
);
if (!$isValid) {
http_response_code(401);
exit('Invalid signature');
}
// Process the webhook safely
$data = json_decode($body, true);
use PspLine\Exception\PspLineException;
use PspLine\Exception\AuthenticationException;
use PspLine\Exception\ApiException;
use PspLine\Exception\ValidationException;
use PspLine\Exception\NetworkException;
try {
$invoice = $psp->invoices->create([...]);
} catch (AuthenticationException $e) {
// Invalid keys, timestamp, or signature
// API codes: 2001, 2002, 2003
echo "Auth error: " . $e->getMessage();
} catch (ValidationException $e) {
// Missing or invalid parameters
echo "Validation: " . $e->getMessage();
} catch (ApiException $e) {
// PSP Line API returned an error
echo "API error [{$e->getApiCode()}]: {$e->getMessage()}";
echo "HTTP: {$e->getHttpCode()}";
echo "Raw: {$e->getRawBody()}";
} catch (NetworkException $e) {
// Connection timeout, DNS failure, etc.
echo "Network error: " . $e->getMessage();
} catch (PspLineException $e) {
// Base catch-all for any SDK error
echo "SDK error: " . $e->getMessage();
}
// config/services.php
'pspline' => [
'merchant_id' => env('PSPLINE_MERCHANT_ID'),
'public_key' => env('PSPLINE_PUBLIC_KEY'),
'private_key' => env('PSPLINE_PRIVATE_KEY'),
'base_url' => env('PSPLINE_BASE_URL'),
],
// AppServiceProvider.php
$this->app->singleton(PspLine::class, function ($app) {
$cfg = config('services.pspline');
return new PspLine(
$cfg['merchant_id'],
$cfg['public_key'],
$cfg['private_key'],
array_filter(['base_url' => $cfg['base_url']])
);
});
// In your controller
public function createPayment(PspLine $psp)
{
$invoice = $psp->invoices->create([...]);
return redirect($invoice->verifyUrl);
}
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.