PBBG Vault Vote Callback Webhook Integration Guide

This guide explains how game developers can receive real-time vote callbacks from PBBG Vault (pbbgvault.com) to reward players in-game with virtual currency, energy, points, or items when they cast their daily vote.


1. How It Works

  1. A player clicks "Vote" on your game's listing page or through your embedded vote widget on pbbgvault.com.
  2. PBBG Vault validates vote integrity (one vote per user/IP per 24 hours, anti-bot checks).
  3. PBBG Vault's background worker (vault:deliver-vote-webhooks) sends an HTTPS POST request to your configured webhook URL:
    POST https://yourgame.com/api/pbbgvault/webhook
    
  4. Your server verifies the cryptographic signature (X-Vault-Signature) using your game's webhook secret.
  5. If the signature matches and the event has not been processed yet, your game awards the player their rewards and responds with HTTP 200 OK.

2. Webhook Headers & Payload Structure

HTTP Request Headers

POST /api/pbbgvault/webhook HTTP/1.1
Host: yourgame.com
Content-Type: application/json
X-Vault-Event: vote.counted
X-Vault-Signature: 7f8a9b2c3d4e5f6... (hex-encoded HMAC-SHA256 signature)
X-Vault-Timestamp: 1732700000
User-Agent: PBBGVault-Webhook/1.0

JSON Payload

{
  "event_id": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d",
  "type": "vote.counted",
  "game_id": 42,
  "game_slug": "your-game-slug",
  "reference": "player_12345",
  "voted_at": "2026-11-27T13:45:00Z"
}
  • event_id: A unique UUID for this vote delivery. Store this to ensure idempotency (never grant rewards twice for the same event).
  • type: Currently vote.counted (or vote.revoked if vote fraud was detected by staff).
  • reference: The player identifier passed in your vote button URL (e.g. https://pbbgvault.com/games/your-slug/vote?ref=player_12345).
  • voted_at: UTC ISO-8601 timestamp of when the vote occurred.

3. Implementation Code Examples

A. Procedural PHP (OpenPBBG / MCCodes / Legacy Stacks)

Save as pbbgvault_webhook.php:

<?php
// Configuration: Your Webhook Secret from PBBG Vault Developer Studio
define('PBBG_VAULT_SECRET', 'whsec_your_secret_key_here');

// 1. Read Raw Payload and Headers
$rawPayload = file_get_contents('php://input');
$signatureHeader = $_SERVER['HTTP_X_VAULT_SIGNATURE'] ?? '';
$timestampHeader = $_SERVER['HTTP_X_VAULT_TIMESTAMP'] ?? '';

if (empty($rawPayload) || empty($signatureHeader)) {
    http_response_code(400);
    exit(json_encode(['error' => 'Missing payload or signature']));
}

// 2. Prevent Replay Attacks (Reject timestamps older than 5 minutes)
if (abs(time() - (int)$timestampHeader) > 300) {
    http_response_code(400);
    exit(json_encode(['error' => 'Timestamp expired']));
}

// 3. Compute and Verify HMAC-SHA256
$expectedSignature = hash_hmac('sha256', $rawPayload, PBBG_VAULT_SECRET);

if (!hash_equals($expectedSignature, $signatureHeader)) {
    http_response_code(401);
    exit(json_encode(['error' => 'Invalid cryptographic signature']));
}

// 4. Parse JSON
$data = json_decode($rawPayload, true);
$eventId = $data['event_id'] ?? '';
$playerId = $data['reference'] ?? null;
$type = $data['type'] ?? '';

if ($type !== 'vote.counted' || empty($playerId)) {
    http_response_code(200);
    exit(json_encode(['status' => 'ignored']));
}

// 5. Connect to Database (PDO example)
$pdo = new PDO('mysql:host=localhost;dbname=your_game;charset=utf8mb4', 'db_user', 'db_pass', [
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
]);

// 6. Idempotency Check & Atomic Reward
$pdo->beginTransaction();
try {
    // Check if event was already processed
    $stmt = $pdo->prepare('SELECT id FROM processed_webhook_events WHERE event_id = ? FOR UPDATE');
    $stmt->execute([$eventId]);
    if ($stmt->fetch()) {
        $pdo->rollBack();
        http_response_code(200);
        exit(json_encode(['status' => 'already_processed']));
    }

    // Record the event
    $insertStmt = $pdo->prepare('INSERT INTO processed_webhook_events (event_id, processed_at) VALUES (?, NOW())');
    $insertStmt->execute([$eventId]);

    // Reward the player (e.g., +100 Energy, +5,000 Cash)
    $rewardStmt = $pdo->prepare('UPDATE users SET energy = LEAST(max_energy, energy + 100), money = money + 5000 WHERE id = ?');
    $rewardStmt->execute([(int)$playerId]);

    $pdo->commit();

    http_response_code(200);
    echo json_encode(['status' => 'success', 'player_id' => $playerId]);
} catch (Exception $e) {
    $pdo->rollBack();
    http_response_code(500);
    echo json_encode(['error' => 'Database error']);
}

B. Laravel 11 / 12 / 13 (Pulse Engine Compatible)

Create app/Http/Controllers/PbbgVaultWebhookController.php:

<?php

namespace App\Http\Controllers;

use App\Models\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class PbbgVaultWebhookController extends Controller
{
    public function handle(Request $request): JsonResponse
    {
        $secret = config('services.pbbgvault.webhook_secret');
        $signature = $request->header('X-Vault-Signature');
        $rawContent = $request->getContent();

        if (!$signature || !hash_equals(hash_hmac('sha256', $rawContent, $secret), $signature)) {
            return response()->json(['error' => 'Unauthorized signature'], 401);
        }

        $eventId = $request->input('event_id');
        $playerId = $request->input('reference');
        $type = $request->input('type');

        if ($type !== 'vote.counted' || !$playerId) {
            return response()->json(['status' => 'ignored'], 200);
        }

        return DB::transaction(function () use ($eventId, $playerId) {
            // Prevent duplicate rewards with atomic insert
            $alreadyProcessed = DB::table('vote_webhook_events')->where('event_id', $eventId)->exists();
            if ($alreadyProcessed) {
                return response()->json(['status' => 'already_rewarded'], 200);
            }

            DB::table('vote_webhook_events')->insert([
                'event_id' => $eventId,
                'created_at' => now(),
            ]);

            $user = User::query()->whereKey($playerId)->lockForUpdate()->first();
            if ($user) {
                $user->increment('energy', 100);
                $user->increment('cash', 5000);
            }

            return response()->json(['status' => 'rewarded'], 200);
        });
    }
}

C. Node.js (Express)

import express from 'express';
import crypto from 'crypto';

const app = express();
const WEBHOOK_SECRET = process.env.PBBGVAULT_SECRET;

app.post('/api/pbbgvault/webhook', express.raw({ type: 'application/json' }), async (req, res) => {
    const signature = req.headers['x-vault-signature'];
    const rawBody = req.body.toString('utf8');

    const expected = crypto.createHmac('sha256', WEBHOOK_SECRET).update(rawBody).digest('hex');
    if (!crypto.timingSafeEqual(Buffer.from(signature || '', 'hex'), Buffer.from(expected, 'hex'))) {
        return res.status(401).json({ error: 'Invalid signature' });
    }

    const payload = JSON.parse(rawBody);
    if (payload.type === 'vote.counted' && payload.reference) {
        await grantVoteReward(payload.reference, payload.event_id);
    }

    res.status(200).json({ status: 'ok' });
});

4. Testing Your Webhook

In your PBBG Vault Developer Area (pbbgvault.com/games/mine -> Vote Rewards):

  1. Enter your callback URL (must be HTTPS on port 443).
  2. Copy your unique whsec_... signing secret.
  3. Click "Send Test Ping". PBBG Vault will send a mock payload with event_id: "test-event-0000" to verify connectivity and display the response status code received from your server.