PHP code example of visualpay / sdk
1. Go to this page and download the library: Download visualpay/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/ */
visualpay / sdk example snippets
use VisualPay\Client;
use VisualPay\Webhook;
use VisualPay\Exceptions\ApiException;
$client = new Client(getenv('VISUALPAY_API_KEY'));
// 1) List currencies / networks
$currencies = $client->listCurrencies();
// 2) Create a payment
$created = $client->createTransaction([
'currency_symbol' => 'USDT',
'network_code' => 'trc20',
'amount_usd' => 25.50,
'ttl' => 15,
'order_id' => 100001,
'email' => '[email protected] ',
'comment' => 'Invoice #1001',
'callback_url' => 'https://example.com/order', // optional HTTPS redirect for the payer
]);
$trackingCode = $created['data']['tracking_code'];
$paymentUrl = $created['data']['payment_url'];
// 3) Check status
$status = $client->getTransactionStatus($trackingCode);
// 4) Cancel (pending only) / recheck (expired|cancelled)
// $client->cancelTransaction($trackingCode);
// $client->recheckTransaction($trackingCode);
// 5) History
$txs = $client->listTransactions(['limit' => 20, 'page' => 1]);
$withdrawals = $client->listWithdrawals(['limit' => 20]);
use VisualPay\Webhook;
use VisualPay\Exceptions\ValidationException;
$headerToken = $_SERVER['HTTP_TOKEN'] ?? '';
$rawBody = file_get_contents('php://input') ?: '';
try {
$event = Webhook::verifyAndParse(
$headerToken,
getenv('VISUALPAY_WEBHOOK_SECRET') ?: '',
$rawBody
);
// $event is a TransactionItem (or settlement payload)
} catch (ValidationException $e) {
http_response_code(401);
exit;
}
try {
$client->createTransaction([...]);
} catch (\VisualPay\Exceptions\AuthenticationException $e) {
// 401
} catch (\VisualPay\Exceptions\ValidationException $e) {
// 422 — $e->getErrors()
} catch (\VisualPay\Exceptions\RateLimitException $e) {
// 429
} catch (\VisualPay\Exceptions\ApiException $e) {
// other API errors — $e->getStatusCode(), $e->getMessage()
} catch (\VisualPay\Exceptions\NetworkException $e) {
// transport / TLS failure
}