PayPal Payouts & Offerwall.
| Timestamp | Type | Source | Amount |
|---|---|---|---|
| 2026-11-16 14:22 | Reward | ironsource_s2s | +500 pts |
| 2026-11-14 09:15 | Payout | paypal_request | -2,000 pts |
| 2026-11-10 18:40 | Reward | adgate_callback | +1,200 pts |
Minimum threshold is 2,000 points ($20.00). Payouts are queued for manual administrative review to prevent fraud.
- Server-to-server (S2S) signature verification.
- Idempotent callbacks prevent duplicate rewards.
- Zero client-side trust or point manipulation.
- Complete audit trail via immutable ledger.
⬇ Backend — Offerwall Backend — Template
Right now Offerwall is local-only — balances are hardcoded let confirmed = 2450 in JS, simulateOffer() fakes the S2S callback with a 3-second setTimeout, the ledger is 3 hardcoded rows, and payout just subtracts 2,000 in the browser. The page already says the right rule: “Zero client-side trust.” This backend is the map to make that true: server owns balances, callbacks are signature-verified, ledger is append-only. Proposed, not connected.
01 / Files to create
api/offerwall/offers.php GET /api/offerwall/offers api/offerwall/balance.php GET /api/offerwall/balance api/offerwall/ledger.php GET /api/offerwall/ledger?limit=20 api/offerwall/callback.php POST /api/offerwall/callback?provider=... api/offerwall/payout.php POST /api/offerwall/payout sql/offerwall_tables.sql
Keep the tinyfiles PHP pattern: each endpoint loads /api/bootstrap.php, uses json_in() / json_out(), prepared PDO statements.
02 / Database tables
-- sql/offerwall_tables.sql
offerwall_offers
id INT AUTO_INCREMENT PRIMARY KEY
provider VARCHAR(40) NOT NULL -- "ironsource", "adgate", "adgem", "cpalead"
title VARCHAR(150) NOT NULL
description TEXT NOT NULL
reward_pts INT NOT NULL -- 350, 800, 200, 500
active TINYINT(1) NOT NULL DEFAULT 1
sort_order INT NOT NULL DEFAULT 0
offerwall_ledger
id BIGINT AUTO_INCREMENT PRIMARY KEY
user_id INT NOT NULL -- FK -> users.id
type ENUM('reward','payout') NOT NULL
source VARCHAR(60) NOT NULL -- "ironsource_s2s", "paypal_request"
amount_pts INT NOT NULL -- +500, -2000 (signed)
callback_id VARCHAR(120) NULL -- provider transaction id, UNIQUE
created_at DATETIME NOT NULL
-- append-only: never UPDATE or DELETE ledger rows
offerwall_payouts
id BIGINT AUTO_INCREMENT PRIMARY KEY
user_id INT NOT NULL
method ENUM('paypal','cashapp') NOT NULL
destination VARCHAR(200) NOT NULL -- PayPal email / $Cashtag
amount_pts INT NOT NULL DEFAULT 2000
status ENUM('queued','approved','paid','rejected') NOT NULL DEFAULT 'queued'
created_at DATETIME NOT NULL
reviewed_at DATETIME NULL
Balances are never stored as a single number. Balance = SUM(amount_pts) WHERE type='reward' minus payouts. The ledger is the balance.
03 / API endpoints & request flow
GET /api/offerwall/offers
- returns { "ok": true, "offers": [ { id, provider, title,
description, reward_pts }, ... ] } — active=1 only
GET /api/offerwall/balance
- session user only, returns { "ok": true, "confirmed": N,
"pending": N, "lifetime": N } — computed from ledger, never trusted from client
GET /api/offerwall/ledger?limit=20
- returns { "ok": true, "entries": [ { created_at, type,
source, amount_pts }, ... ] } — newest first
POST /api/offerwall/callback?provider=ironsource
- provider server-to-server POST, NOT browser
- body: { user_id, transaction_id, reward_pts, signature }
- server verifies HMAC signature with provider secret
- INSERT ledger row with callback_id UNIQUE — duplicate callback = no double credit
- returns { "ok": true } or 401 on bad signature
POST /api/offerwall/payout
{ "method": "paypal", "destination": "name@domain.com" }
- session user only, validates method + destination
- checks confirmed >= 2000, else { "ok": false, "error": "insufficient" }
- INSERT payout row status='queued' + INSERT ledger row -2000
- returns { "ok": true, "payout_id": N }
Browser never credits points. Browser only asks “what is my balance?” and “please queue a payout.” The callback endpoint is the only writer of rewards.
04 / Signatures, idempotency & validation (server owns this)
// Callback signature — server verifies, never trusts: // expected = HMAC_SHA256(secret_for_provider, // user_id + "|" + transaction_id + "|" + reward_pts) // compare with hash_equals(expected, signature) // if mismatch: 401, log attempt, do NOT credit // Idempotency — same callback twice = one credit: // callback_id has UNIQUE index in offerwall_ledger // INSERT ... ON DUPLICATE KEY UPDATE id=id — second insert is a no-op // Payout validation: // method in [paypal, cashapp], destination 3-200 chars // amount_pts must be exactly 2000 (fixed threshold, no client amount) // confirmed balance re-checked inside a transaction before INSERT
Keep the page’s existing promise: “S2S signature verification. Idempotent callbacks. Zero client-side trust. Immutable ledger.” The backend makes each line true.
05 / Frontend wiring
// Replace the hardcoded let confirmed = 2450 etc. in this page:
async function loadOfferwall(){
const [offers, bal, ledger] = await Promise.all([
fetch('/api/offerwall/offers').then(r=>r.json()),
fetch('/api/offerwall/balance').then(r=>r.json()),
fetch('/api/offerwall/ledger?limit=20').then(r=>r.json()),
]);
// offers.offers -> .offers-grid, same .offer-card HTML as now
// bal -> #confirmedPoints / #pendingPoints / #lifetimePoints
// ledger.entries -> #ledgerBody, same HTML as now
}
// Replace simulateOffer(title, pts):
// window.location = offer.tracking_url from /offers (provider link)
// DO NOT credit in JS. Wait for S2S callback, then reload balance.
// Replace payoutForm submit:
// POST /api/offerwall/payout { method, destination }
// on ok: reload balance + ledger, show toast
// on insufficient: show "Minimum 2,000 pts required"
// On load: loadOfferwall()
// If API fails, keep current demo numbers + hardcoded ledger as fallback.
Keep the current demo playable with no backend — if /api/offerwall/balance fails, use the in-page numbers as the fallback.
Copy the snippets above into api/offerwall/ + sql/offerwall_tables.sql — no GitHub needed. The <pre> blocks are the backend spec: server-owned balances, signature-verified S2S callbacks, idempotent ledger, fixed 2,000-pt payout, same layout.