Website integration, set that address as your webhook URL * and create the webhook secret. * 3. Fill in the two settings below. * 4. Fill in the two parts marked "REPLACE THIS" with your own database code. * * It already checks the signature, refuses old or replayed messages, ignores repeats, * and asks PayNode to confirm a payment before you credit anyone. * Keep this file's settings private: never put the secret or key in a browser or app. */ const PAYNODE_WEBHOOK_SECRET = 'PASTE_YOUR_WEBHOOK_SECRET_HERE'; const PAYNODE_API_KEY = 'PASTE_YOUR_API_KEY_HERE'; // a normal API key is enough // Remembers which messages were already handled, so a retry never credits twice. // Must be a folder PHP can write to, ideally outside your public web folder. const PAYNODE_SEEN_FILE = __DIR__ . '/paynode-seen.txt'; // ---------------------------------------------------------------- 1. Check it really came from PayNode $raw = file_get_contents('php://input'); $timestamp = $_SERVER['HTTP_X_PAYNODE_TIMESTAMP'] ?? ''; $signature = $_SERVER['HTTP_X_PAYNODE_SIGNATURE'] ?? ''; $delivery = $_SERVER['HTTP_X_PAYNODE_DELIVERY'] ?? ''; $expected = hash_hmac('sha256', $timestamp . '.' . $raw, PAYNODE_WEBHOOK_SECRET); if (!hash_equals($expected, $signature) || abs(time() - (int)$timestamp) > 300) { http_response_code(400); exit('bad signature or too old'); } $event = json_decode($raw, true); if (!is_array($event) || empty($event['event'])) { http_response_code(400); exit('bad body'); } // ---------------------------------------------------------------- 2. Ignore repeats $seen = is_file(PAYNODE_SEEN_FILE) ? file(PAYNODE_SEEN_FILE, FILE_IGNORE_NEW_LINES) : []; $id = $delivery !== '' ? $delivery : hash('sha256', $raw); if (in_array($id, $seen, true)) { http_response_code(200); exit('already handled'); } // ---------------------------------------------------------------- 3. Ask PayNode directly function paynode_get($path) { $ch = curl_init('https://paynode.space' . $path); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 20, CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . PAYNODE_API_KEY], ]); $body = curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return $code === 200 ? json_decode($body, true) : null; } try { switch ($event['event']) { case 'invoice.settled': // Never trust the message alone: fetch the payment from PayNode and check it. $inv = paynode_get('/api/invoices/' . rawurlencode($event['invoice_id'])); if (!$inv) { http_response_code(503); exit('could not reach PayNode - will retry'); } if ($inv['status'] !== 'settled' || $inv['live'] !== true || !empty($inv['sandbox'])) { break; // not a real, finished payment - credit nothing } // ======================= REPLACE THIS (1 of 2) ======================= // Credit your user ONCE. Look up your own deposit by $inv['order_id'] (the order_id you // sent when creating the payment) and check the coin and amount match what you expected: // $inv['asset_key'] e.g. "eip155:56:0x55d398...7955" (USDT on BNB Chain) // $inv['expected_display'] e.g. "25" // Save $inv['id'] in a column with a UNIQUE rule, so a repeat can never credit twice. // // Example: // $pdo->prepare("UPDATE deposits SET status='paid', paynode_id=? WHERE order_id=? AND status='pending'") // ->execute([$inv['id'], $inv['order_id']]); // ...then add the amount to the user's balance. // ===================================================================== break; case 'payout.failed': // ======================= REPLACE THIS (2 of 2) ======================= // A payout you asked for did not go out. Nothing left your PayNode wallet. // Put the amount back in your user's balance. Find your withdrawal by // $event['reference'] (the reference you sent with the payout). // ===================================================================== break; case 'payout.confirmed': // The payout arrived. Mark your withdrawal $event['reference'] as done if you like. break; default: // invoice.confirming, invoice.underpaid, invoice.confirmed, invoice.settling, // invoice.expired, invoice.failed and "test" need nothing. Credit only on invoice.settled. break; } } catch (Throwable $e) { error_log('PayNode webhook: ' . $e->getMessage()); http_response_code(500); // PayNode will try again later exit('error'); } // ---------------------------------------------------------------- 4. Remember it, answer OK file_put_contents(PAYNODE_SEEN_FILE, $id . "\n", FILE_APPEND | LOCK_EX); http_response_code(200); echo 'ok';