1. Go to this page and download the library: Download rootdigit/sagapay 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/ */
// By address
$status = $client->checkTransactionStatus('deposit', '0x742d35C...');
// By transaction ID
$status = $client->checkTransactionStatus('deposit', null, 'deposit-uuid');
$balance = $client->fetchWalletBalance(
'0x742d35C...', // Address
'ERC20', // Network type
'0xdAC17F...' // Contract address (use '0' for native currency)
);
// webhook.php
ent;
use SagaPay\SDK\WebhookHandler;
$client = new Client('your-api-key', 'your-api-secret');
// Optional platform-issued IPN secret (NOT your API secret). When null,
// signature verification is skipped and verifyWithServer() below is the
// primary check.
$ipnSecret = null; // e.g. 'your-platform-ipn-secret'
$webhookHandler = new WebhookHandler($client, $ipnSecret);
try {
// Process and validate the webhook
$webhookData = $webhookHandler->processWebhook(getallheaders(), file_get_contents('php://input'));
// Confirm the notification against the SagaPay API (recommended)
if (!$webhookHandler->verifyWithServer($webhookData)) {
throw new \SagaPay\SDK\Exception('IPN could not be verified with the server');
}
// Handle the validated webhook data
$transactionId = $webhookData['id'];
$type = $webhookData['type']; // 'DEPOSIT' or 'WITHDRAWAL'
$status = $webhookData['status']; // 'COMPLETED' (the only status sent today)
$address = $webhookData['address'];
$amount = $webhookData['amount'];
$udf = $webhookData['udf'] ?? null; // Your custom reference field
// IPNs are delivered at least once — the same notification may arrive
// more than once, so make your processing idempotent (e.g. skip
// transaction IDs you have already handled).
if ($status === 'COMPLETED' && $type === 'DEPOSIT') {
// Process successful payment
// e.g., updateOrderStatus($udf, 'paid');
}
// Send success response
$webhookHandler->sendSuccessResponse();
} catch (\SagaPay\SDK\Exception $e) {
// Log the error and send error response
error_log("Webhook error: " . $e->getMessage());
$webhookHandler->sendErrorResponse($e->getMessage(), $e->getCode());
}
$webhookHandler = new WebhookHandler($client, 'your-platform-ipn-secret');
$verified = $client->verifyIpn(
$webhookData['txHash'] ?? '', // Transaction hash from the IPN
$webhookData['type'], // 'DEPOSIT' or 'WITHDRAWAL'
$webhookData['amount'], // Amount from the IPN
$webhookData['address'] // Address from the IPN
);
if (!$verified) {
// Reject the notification
}