1. Go to this page and download the library: Download satlane/satlane-php 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 Satlane\WebhookSignature;
use Satlane\Exceptions\SignatureException;
$rawBody = file_get_contents('php://input');
$header = $_SERVER['HTTP_X_SATLANE_SIGNATURE'] ?? '';
try {
WebhookSignature::verify(
rawBody: $rawBody,
signatureHeader: $header,
secrets: getenv('SATLANE_WEBHOOK_SECRET'),
);
} catch (SignatureException $e) {
http_response_code(400);
exit;
}
$event = json_decode($rawBody, true);
// IMPORTANT: dedupe by event_id. Retries deliver the same event_id, and
// top-up payments produce repeated invoice.underpaid events.
if (alreadyProcessed($event['event_id'])) {
http_response_code(200);
exit;
}
match ($event['event_type']) {
'invoice.paid', 'invoice.late_paid' => fulfillOrder($event['data']['invoice']),
'invoice.underpaid' => onShortPayment($event['data']['invoice']),
'invoice.overpaid' => onOverpayment($event['data']['invoice']),
'invoice.payment_reverted' => reverseOrder($event['data']['invoice']),
'invoice.expired',
'invoice.cancelled' => null,
default => null,
};
http_response_code(200);
use Satlane\Exceptions\ApiException;
try {
$invoice = $client->invoices->create([...]);
} catch (ApiException $e) {
if ($e->code() === 'gap_limit_exceeded') {
// Wallet has too many unused addresses pre-derived.
// Bump your Electrum gap limit or rotate xpubs.
}
if ($e->code() === 'no_active_xpub') {
// Vendor needs to add an xpub on this store.
}
if ($e->isRetryable()) {
// 429 / 503 / network error. SDK already retried 3 times by
// default — surface a "try again later" to the user.
}
// Always log $e->requestId() — it correlates to our server logs.
logger()->error('satlane create failed', [
'code' => $e->code(),
'status' => $e->status,
'request_id' => $e->requestId(),
]);
throw $e;
}