Game Pass: no pass is ever bought with credits again (Marty, 2026-10-22). Buy only opens a waiting order and sends the member to buy a package of at least the tier price; the order is fulfilled only by a fresh on-chain package Purchase by one of the member's own positions (main or linked), mined after the order was opened (block time, 30 s clock grace), each purchase tx used once across every account. The member keeps the package credits for ads; sponsors and team are paid by the package as usual. Existing passes untouched. Card and confirm copy say so; my.js tag bumped. qa/gamepass.mjs updated for the new flow (older-than-order, too small, another member, replayed tx): ALL PASS.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+56
-30
@@ -4,7 +4,7 @@
|
||||
//
|
||||
// What lives here:
|
||||
// - the pass store email -> { until, bought: [{ ts, via, tx | credits, usd }], lastCapHit } (durable persisted map 'gamepass')
|
||||
// - waiting orders order -> { status, email, ts, tx } (a $5+ package bought while an order waits fulfils it: the pwpasses pattern)
|
||||
// - pass orders order -> { status, email, ts, tx } (every pass is paid by a FRESH package purchase: see buy() / onEvent())
|
||||
// - the cap ledger per member per Central day: used daily/total, deferred queue per game, every answered (game, ref) kept 90 days
|
||||
// - the weekly Pass Tournament: ranks pass holders by grants reported through polgrant, records POL prizes for the games to pay
|
||||
// - admin stats
|
||||
@@ -20,6 +20,11 @@
|
||||
// `until` as the weekly tier). flag().tier = the highest active tier. Explorer/Champion sales sit behind the site switch
|
||||
// `sovTiers` (default off; only ADMIN_EMAIL can see and buy them while it is off). No proration, no auto-renew: buying again
|
||||
// extends that tier from max(now, until).
|
||||
// 2026-10-22 (Marty): every pass rides the package rail so sponsors get paid. Buying a pass never spends a credit balance any more
|
||||
// (today's buyer paid from an old balance, so no new money came in and nobody upline was paid). A pass click opens an order; the
|
||||
// order is fulfilled ONLY by an on-chain package Purchase of at least the tier price, mined after the order was opened, bought by
|
||||
// one of that member's own positions (main or linked), each purchase tx used once. The member keeps that package's credits for ads.
|
||||
// Bought rows: via 'package' (with tx and cents). The two rows from before this change are via 'credits' and 'package' and stay.
|
||||
// 2026-10-22 (Dallas's structure, Marty approved): Explorer $19.99 and Champion $39.99 (30 days), plus Sovereign $99.99 (30 days)
|
||||
// and Legend $249.99 (365 days, the yearly pass), all in TIER_DEFS below and all behind the same sovTiers switch. The weekly
|
||||
// pass is unchanged ($5 / 7 days / the same caps). Rank weekly < explorer < champion < sovereign < legend.
|
||||
@@ -35,7 +40,8 @@ const KEEP_DAYS = 90; // answered refs and day rows are kept this long
|
||||
// THE pass table (2026-10-22, Dallas's structure, Marty approved): lowest to highest, a higher tier includes everything below.
|
||||
// Rename a tier here (name) and nowhere else: the member card, the admin pane, the charge label and the chatbot read it from here.
|
||||
// key = the wire value the games read (flag().tier / tiers); set = the Admin > Settings stem (gamePass<set>Enabled /
|
||||
// PriceCredits / Days; weekly keeps its original gamePassPriceCredits / gamePassDays); price = purchased-grade credits (100 = $1);
|
||||
// PriceCredits / Days; weekly keeps its original gamePassPriceCredits / gamePassDays); price = the pass price in cents (100 = $1;
|
||||
// the setting keeps its old 'PriceCredits' name): the package that pays for a pass must cost at least this much;
|
||||
// perks = what the member card lists. Every tier is a Game Pass holder everywhere with the SAME caps (no extra POL).
|
||||
const TIER_DEFS = [
|
||||
{ key: 'weekly', name: 'Game Pass', set: '', price: 500, days: 7,
|
||||
@@ -193,46 +199,66 @@ function view(email, now, opts) {
|
||||
show: c.enabled || tiered, passes: passRows, tierPreview: tiered && admin && !c.tierSales };
|
||||
}
|
||||
|
||||
// POST /api/my/gamepass/buy { tier }. `charge(price, label)` runs ads.gamePurchase(purchasedOnly) and resolves { ok } | { error: 'short', ... } | { error }.
|
||||
// tier missing = weekly (exactly the pass as it was before tiers). opts.admin = the ADMIN_EMAIL account.
|
||||
async function buy(email, charge, now, tier, opts) {
|
||||
// POST /api/my/gamepass/buy { tier }. tier missing = weekly (exactly the pass as it was before tiers). opts.admin = the ADMIN_EMAIL account.
|
||||
// A pass is ALWAYS paid by a fresh package purchase (2026-10-22, Marty: the pass rides the package rail so sponsors get paid). This never
|
||||
// spends credits: it opens (or reuses) a waiting order for that tier and sends the member to buy a package of at least the tier price.
|
||||
// The order is fulfilled by onEvent() below; the member keeps every credit of that package for ads.
|
||||
function buy(email, now, tier, opts) {
|
||||
const e = String(email || '').toLowerCase(); const c = cfg(); const t = now || Date.now();
|
||||
tier = (tier === undefined || tier === null || tier === '') ? 'weekly' : String(tier).toLowerCase();
|
||||
if (!tierOk(tier)) return { error: 'There is no such pass.' };
|
||||
const tc = c.tiers[tier]; const name = TIER_NAMES[tier];
|
||||
if (tier === 'weekly') { if (!c.enabled) return { error: 'The Game Pass is not open yet.' }; }
|
||||
else if (!tierOpen(c, tier, !!(opts && opts.admin))) return { error: 'The ' + name + ' pass is not open yet.' };
|
||||
const r = await charge(tc.price, (tier === 'weekly' ? 'Game Pass' : name + ' pass') + ' (' + tc.days + ' days)');
|
||||
if (r && r.ok) {
|
||||
const x = extend(e, 'credits', { credits: tc.price, campaignId: r.campaignId || null }, t, tier);
|
||||
console.log('gamepass bought with credits', tier, e, tc.price, 'until', new Date(x.until).toISOString());
|
||||
return { ok: true, active: true, tier, until: x.until, days: tc.days, paid: 'credits' };
|
||||
}
|
||||
if (r && r.error === 'short') {
|
||||
// no purchased-grade credits on a position: the pass waits for a package of at least its price (bought while the order waits, it fulfils it)
|
||||
let w = waitingOrder(e, tier);
|
||||
if (!w) { const k = 'gp-' + t.toString(36) + '-' + Math.random().toString(36).slice(2, 8); orders.set(k, { status: 'waiting', email: e, ts: t, tier }); w = Object.assign({ order: k }, orders.get(k)); }
|
||||
const pkg = packageFor(tc.price / 100);
|
||||
return { ok: false, needPay: true, tier, payUrl: tier === 'weekly' ? '/my?from=gamepass#buy' : '/my?from=gamepass&tier=' + tier + '#buy', order: w.order, price: tc.price, usd: tc.price / 100, package: pkg, available: r.available || 0, need: r.need || tc.price,
|
||||
message: (tier === 'weekly' ? 'The pass' : 'The ' + name + ' pass') + ' is paid with purchased credits. Buy a $' + pkg + ' package and the pass starts the moment it settles; you keep every credit of the package for your ads.' };
|
||||
}
|
||||
return { error: (r && r.error) || 'The purchase did not go through. Nothing was taken.' };
|
||||
let w = waitingOrder(e, tier); const reused = !!w;
|
||||
if (!w) { const k = 'gp-' + t.toString(36) + '-' + Math.random().toString(36).slice(2, 8); orders.set(k, { status: 'waiting', email: e, ts: t, tier }); w = Object.assign({ order: k }, orders.get(k)); }
|
||||
const pkg = packageFor(tc.price / 100);
|
||||
if (!reused) console.log('gamepass order opened', tier, e, w.order, 'needs a package of', tc.price, 'cents');
|
||||
return { ok: false, needPay: true, tier, payUrl: tier === 'weekly' ? '/my?from=gamepass#buy' : '/my?from=gamepass&tier=' + tier + '#buy', order: w.order, orderTs: w.ts, reused,
|
||||
price: tc.price, usd: tc.price / 100, package: pkg,
|
||||
message: (tier === 'weekly' ? 'Your Game Pass' : 'Your ' + name + ' pass') + ' starts the moment your next package of $' + pkg + ' or more settles on chain. Your sponsor and team are paid from it as usual, and you keep every credit of the package for your ads.' };
|
||||
}
|
||||
|
||||
// a package purchase landing on chain fulfils one of this account's waiting orders: the highest-priced one the package covers
|
||||
// (one pass per purchase of $5 or more, each tx counted once)
|
||||
// A package purchase landing on chain fulfils one of this account's waiting orders: the highest-priced one the package covers.
|
||||
// Rules (2026-10-22): the buyer must be one of this account's own positions (main member id or a linked position); the purchase must
|
||||
// be mined AFTER the order was opened (block time, ORDER_SKEW_MS for clock drift); one pass per purchase of $5 or more; each tx used
|
||||
// once across every account and order. Credit balances never fulfil an order.
|
||||
const ORDER_SKEW_MS = 30000;
|
||||
function txUsed(tx) {
|
||||
if (!tx) return false;
|
||||
for (const [, o] of orders) if (o && o.tx === tx) return true;
|
||||
for (const [, p] of passes) if (p && (p.bought || []).some(b => b.tx && b.tx === tx)) return true;
|
||||
return false;
|
||||
}
|
||||
async function ownerOf(ev) { // the account behind the buying position
|
||||
if (ev.devEmail && !R.isProd) return String(ev.devEmail).toLowerCase();
|
||||
const id = Number(ev.buyerId) || 0; if (!id) return null;
|
||||
let a = await R.accounts.byMemberId(id);
|
||||
if (!a && R.accounts.positionByMember) { const pos = await R.accounts.positionByMember(id); if (pos && pos.email) a = { email: pos.email }; }
|
||||
return a && a.email ? String(a.email).toLowerCase() : null;
|
||||
}
|
||||
async function minedAt(ev) { // block time in ms; the indexed-at time only when the block cannot be read (it is never earlier than the block)
|
||||
if (ev.devMinedAt && !R.isProd) return Number(ev.devMinedAt);
|
||||
if (ev.block && R.blockTime) {
|
||||
for (let i = 0; i < 3; i++) { try { const s = await R.blockTime(ev.block); if (s > 0) return s * 1000; } catch (e) {} await new Promise(r => setTimeout(r, 1500)); }
|
||||
console.warn('gamepass: block time unavailable for', ev.block, '- using the indexed-at time');
|
||||
}
|
||||
return Number(ev.ts) || Date.now();
|
||||
}
|
||||
async function onEvent(ev) {
|
||||
if (!ev || ev.type !== 'Purchase' || (ev.priceCents || 0) < 500) return null;
|
||||
const c = cfg(); const cents = ev.priceCents || 0;
|
||||
if (!TIERS.some(k => cents >= c.tiers[k].price)) return null;
|
||||
const a = (ev.devEmail && !R.isProd) ? { email: ev.devEmail } : await R.accounts.byMemberId(ev.buyerId); if (!a || !a.email) return null;
|
||||
const e = String(a.email).toLowerCase();
|
||||
const p = passes.get(e); if (p && (p.bought || []).some(b => b.tx && b.tx === ev.tx)) return null; // each purchase counts once
|
||||
const w = waitingOrders(e).filter(o => cents >= c.tiers[o.tier].price).sort((x, y) => c.tiers[y.tier].price - c.tiers[x.tier].price || x.ts - y.ts)[0];
|
||||
if (!w) return null;
|
||||
orders.set(w.order, Object.assign({}, orders.get(w.order), { status: 'paid', tx: ev.tx, cents, paidAt: Date.now() }));
|
||||
const x = extend(e, 'package', { tx: ev.tx, cents, order: w.order }, ev.ts || Date.now(), w.tier);
|
||||
console.log('gamepass fulfilled by package', w.tier, e, 'tx', String(ev.tx).slice(0, 12), 'until', new Date(x.until).toISOString());
|
||||
const e = await ownerOf(ev); if (!e) return null;
|
||||
if (!waitingOrders(e).length) return null;
|
||||
if (txUsed(ev.tx)) return null; // each purchase counts once, everywhere
|
||||
const at = await minedAt(ev);
|
||||
const w = waitingOrders(e).filter(o => cents >= c.tiers[o.tier].price && at + ORDER_SKEW_MS >= o.ts)
|
||||
.sort((x, y) => c.tiers[y.tier].price - c.tiers[x.tier].price || x.ts - y.ts)[0];
|
||||
if (!w) { console.log('gamepass: package', String(ev.tx).slice(0, 12), 'by', e, 'fulfils no order (bought before the order or too small)'); return null; }
|
||||
orders.set(w.order, Object.assign({}, orders.get(w.order), { status: 'paid', tx: ev.tx, cents, paidAt: Date.now(), minedAt: at, buyerId: Number(ev.buyerId) || 0 }));
|
||||
const x = extend(e, 'package', { tx: ev.tx, cents, order: w.order, buyerId: Number(ev.buyerId) || 0, usd: c.tiers[w.tier].price / 100, packageUsd: cents / 100 }, (ev.devNow && !R.isProd) ? Number(ev.devNow) : Date.now(), w.tier);
|
||||
console.log('gamepass fulfilled by package', w.tier, e, 'tx', String(ev.tx).slice(0, 12), cents, 'cents, until', new Date(x.until).toISOString());
|
||||
return { order: w.order, until: x.until, tier: w.tier };
|
||||
}
|
||||
|
||||
|
||||
+9
-9
@@ -1744,7 +1744,7 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str
|
||||
const capsLine = caps.enforced ? 'Today: <b>' + gpPol(caps.used && caps.used.total) + '</b> of ' + gpPol(caps.total) + ' POL used across the games (' + gpPol(caps.used && caps.used.daily) + ' of ' + gpPol(caps.daily) + ' on daily play).' : '';
|
||||
const box = r => {
|
||||
const btn = r.waiting ? '<button class="btn small" type="button" data-gp-go="1">Buy a $' + r.package + ' package</button>'
|
||||
: r.open ? '<button class="btn small" type="button" data-gp-tier="' + esc(r.tier) + '">' + (r.active ? 'Extend ' + gpLen(r.days) + ' more' : 'Get ' + esc(r.name)) + ' · ' + r.price + ' credits</button>'
|
||||
: r.open ? '<button class="btn small" type="button" data-gp-tier="' + esc(r.tier) + '">' + (r.active ? 'Extend ' + gpLen(r.days) + ' more' : 'Get ' + esc(r.name)) + ' · ' + '$' + r.package + ' package</button>'
|
||||
: '<span class="small muted">Not on sale right now. Your pass keeps running.</span>';
|
||||
return '<div class="gp-tier' + (r.tier === gp.tier ? ' on' : '') + '"><h4>' + esc(r.name) + '</h4>'
|
||||
+ '<p class="gp-price">$' + r.usd + ' <span class="small muted">for ' + gpLen(r.days) + '</span></p>'
|
||||
@@ -1759,15 +1759,15 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str
|
||||
+ '<p>Free play pays real POL every day, and the main story of Shards of Valor is free for everyone. Every pass gives the same higher POL caps in every game. Each higher pass includes everything below it and adds more of Shards of Valor: weapons, gear, bonus islands, heroes and a higher level cap. <b>Paid passes never make you stronger than players who earn their gear</b>, and they never pay more POL.</p>'
|
||||
+ '<div class="gp-tiers">' + rows.map(box).join('') + '</div>'
|
||||
+ (capsLine ? '<p class="small muted" style="margin-top:10px">' + capsLine + '</p>' : '')
|
||||
+ '<p class="small muted" style="margin:10px 0 0">Paid with purchased credits from your packages (earned credits never buy a pass). Passes run side by side: a higher pass shows first, and the one underneath keeps its own end date. No auto-renew: buy again any time and that pass extends from its end date. When a pass ends, nothing you earned in a game is taken away.</p>';
|
||||
+ '<p class="small muted" style="margin:10px 0 0">Every pass is paid by a new package purchase of at least its price, so your sponsor and team are paid; you keep the package credits for your ads. Credits you already hold never buy a pass. Passes run side by side: a higher pass shows first, and the one underneath keeps its own end date. No auto-renew: buy again any time and that pass extends from its end date. When a pass ends, nothing you earned in a game is taken away.</p>';
|
||||
card.querySelectorAll('[data-gp-tier]').forEach(b => b.addEventListener('click', async () => {
|
||||
const r = rows.find(x => x.tier === b.dataset.gpTier); if (!r) return;
|
||||
const yes = await IAP.confirmBox((r.active ? 'Extend your ' + r.name + ' by ' + gpLen(r.days) : 'Get ' + r.name + ' for ' + gpLen(r.days)) + ' for ' + r.price + ' purchased credits ($' + r.usd + ')? It starts at once. The same POL caps as every pass: no extra POL.', { title: r.name, ok: r.active ? 'Extend' : 'Get ' + r.name, cancel: 'Not now' });
|
||||
const yes = await IAP.confirmBox((r.active ? 'Extend your ' + r.name + ' by ' + gpLen(r.days) : 'Get ' + r.name + ' for ' + gpLen(r.days)) + ' ($' + r.usd + ')? Every pass is paid by a new package purchase of $' + r.package + ' or more: your sponsor and team are paid from it as usual, you keep all its credits for your ads, and the pass starts the moment it settles. Credits you already hold never buy a pass. The same POL caps as every pass: no extra POL.', { title: r.name, ok: r.active ? 'Extend' : 'Get ' + r.name, cancel: 'Not now' });
|
||||
if (!yes) return;
|
||||
b.disabled = true;
|
||||
try {
|
||||
const x = await api('/api/my/gamepass/buy', { tier: r.tier });
|
||||
if (x.needPay) { IAP.status(x.message || 'Buy a package and the pass starts when it settles.', 'bad'); await loadGamePassCard(true); return; }
|
||||
if (x.needPay) { IAP.status(x.message || 'Buy a package and the pass starts when it settles.', 'ok'); setPane('buy'); return; }
|
||||
IAP.status(r.name + ' active until ' + gpCT(x.until) + '. Have fun out there.', 'ok');
|
||||
await loadGamePassCard(true);
|
||||
} catch (e) { IAP.status(e.message, 'bad'); b.disabled = false; }
|
||||
@@ -1816,15 +1816,15 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str
|
||||
+ '<p class="small muted">' + capsLine + '</p>'
|
||||
+ (gp.waiting ? '<p class="small">Your pass is waiting: buy a $' + (gp.usd || 5) + ' package and it starts the moment the purchase settles. You keep every credit of the package for your ads.</p>' : '')
|
||||
+ '<p style="display:flex;gap:10px;flex-wrap:wrap;align-items:center;margin:10px 0 0">'
|
||||
+ (gp.waiting ? '<button class="btn" type="button" id="gpGoBuy">Buy a $' + (gp.usd || 5) + ' package</button>' : '<button class="btn" type="button" id="gpBuy">' + (gp.active ? 'Extend ' + (gp.days || 7) + ' more days' : 'Get the Pass') + ' \u00b7 ' + price + ' credits</button>')
|
||||
+ '<span class="small muted">Paid with purchased credits from your packages (earned credits never buy a pass). Short? A $' + (gp.usd || 5) + ' package starts it the moment it settles.</span></p>';
|
||||
+ (gp.waiting ? '<button class="btn" type="button" id="gpGoBuy">Buy a $' + (gp.usd || 5) + ' package</button>' : '<button class="btn" type="button" id="gpBuy">' + (gp.active ? 'Extend ' + (gp.days || 7) + ' more days' : 'Get the Pass') + ' \u00b7 buy a $' + (gp.usd || 5) + ' package</button>')
|
||||
+ '<span class="small muted">Paid by a new $' + (gp.usd || 5) + ' or bigger package, so your sponsor and team are paid. You keep the package credits for your ads; credits you already hold never buy a pass.</span></p>';
|
||||
const b = $('gpBuy'); if (b) b.addEventListener('click', async () => {
|
||||
const yes = await IAP.confirmBox((gp.active ? 'Extend your Game Pass by ' + (gp.days || 7) + ' days' : 'Get the Game Pass for ' + (gp.days || 7) + ' days') + ' for ' + price + ' purchased credits? Higher daily caps across all nine games, the weekly Pass Tournament and the Pass perks start at once.', { title: 'Game Pass', ok: gp.active ? 'Extend the Pass' : 'Get the Pass', cancel: 'Not now' });
|
||||
const yes = await IAP.confirmBox((gp.active ? 'Extend your Game Pass by ' + (gp.days || 7) + ' days' : 'Get the Game Pass for ' + (gp.days || 7) + ' days') + '? The Pass is paid by a new package purchase of $' + (gp.usd || 5) + ' or more: your sponsor and team are paid from it as usual, you keep all its credits for your ads, and the Pass starts the moment it settles. Credits you already hold never buy a pass.', { title: 'Game Pass', ok: gp.active ? 'Extend the Pass' : 'Get the Pass', cancel: 'Not now' });
|
||||
if (!yes) return;
|
||||
b.disabled = true;
|
||||
try {
|
||||
const r = await api('/api/my/gamepass/buy');
|
||||
if (r.needPay) { IAP.status(r.message || 'Buy a $5 package and the pass starts when it settles.', 'bad'); await loadGamePassCard(true); return; }
|
||||
if (r.needPay) { IAP.status(r.message || 'Buy a $5 package and the pass starts when it settles.', 'ok'); setPane('buy'); return; }
|
||||
IAP.status('Game Pass active until ' + gpDate(r.until) + '. Have fun out there.', 'ok');
|
||||
await loadGamePassCard(true);
|
||||
try { await loadDashboard(); } catch (e) {} // unlocks the Game Pass badge at once (toast + team post)
|
||||
@@ -1842,7 +1842,7 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str
|
||||
const NAMES = { polhunter: 'PolHunter', gemkingdom: 'Gem Kingdom', spellwheel: 'SpellWheel', spookydoors: 'Spooky Doors', polywarriors: 'PolyWarriors', clutterhunt: 'ClutterHunt', polybreak: 'PolyBreak', driprunner: 'Drip Runner', roadagent: 'Road Agent' };
|
||||
card.hidden = false;
|
||||
card.innerHTML = '<div class="card-head"><h3>\u{1F39F}\uFE0F You reached today\u2019s free cap in ' + esc(NAMES[gp.lastCapHit.game] || 'the games') + '</h3><span class="sub">free play keeps paying; the Pass plays more</span></div>'
|
||||
+ '<p>Every member earns real POL in the games up to the daily cap. The <b>Game Pass</b> raises the caps across all nine games for ' + (gp.days || 7) + ' days ($' + (gp.usd || 5) + ', paid with purchased credits), adds the weekly Pass Tournament and a perk in every game.</p>'
|
||||
+ '<p>Every member earns real POL in the games up to the daily cap. The <b>Game Pass</b> raises the caps across all nine games for ' + (gp.days || 7) + ' days ($' + (gp.usd || 5) + ', paid with a new package), adds the weekly Pass Tournament and a perk in every game.</p>'
|
||||
+ '<button class="btn" type="button" id="gpNudgeGo">See the Game Pass</button>';
|
||||
$('gpNudgeGo').addEventListener('click', () => setPane('games?pass=1'));
|
||||
try { localStorage.setItem('iap-hide-gpnudge', String(Date.now())); } catch (e) {} // once a day
|
||||
|
||||
+1
-1
@@ -1188,7 +1188,7 @@
|
||||
<script src="/assets/wallet.js?v=20260911a"></script>
|
||||
<script src="/assets/promo.js?v=20261016p"></script>
|
||||
<script src="/assets/support.js?v=20261016a"></script>
|
||||
<script src="/assets/my.js?v=20261022gpt"></script>
|
||||
<script src="/assets/my.js?v=20261022gpk"></script>
|
||||
<script src="/assets/chat.js?v=20261016n"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+28
-13
@@ -71,24 +71,39 @@ try {
|
||||
g = (await api('/api/my/gamepass', null, hA)).j;
|
||||
ok(g && g.enabled === true && g.caps && g.caps.enforced === false && g.caps.daily === 0.3 && g.caps.total === 2, 'pass ON: GET shows free caps 0.30 / 2 and enforced false (no capsStartDate)', JSON.stringify(g.caps));
|
||||
|
||||
// 2. buy without purchased credits -> waiting order; a $5 package fulfils it
|
||||
// 2. buy (2026-10-22: no pass is ever bought with credits) -> waiting order; only a FRESH package by the member's own position fulfils it.
|
||||
// A's purchases are stamped Sun Oct 18 (week of Oct 12) and B's Tue Oct 20 (week of Oct 19), so the tournament below sees one sale.
|
||||
const SUN = Date.parse('2026-10-18T17:00:00Z'), TUE = Date.parse('2026-10-20T17:00:00Z');
|
||||
r = await api('/api/my/gamepass/buy', { data: {} }, hA);
|
||||
ok(r.status === 200 && r.j && r.j.needPay === true && r.j.payUrl === '/my?from=gamepass#buy' && r.j.order, 'buy with no purchased credits -> needPay + payUrl + waiting order', JSON.stringify(r.j && { needPay: r.j.needPay, payUrl: r.j.payUrl, need: r.j.need }));
|
||||
const order1 = r.j && r.j.order;
|
||||
r = await api('/api/my/gamepass/buy', { data: {} }, hA);
|
||||
ok(r.j && r.j.order === order1, 'a second buy attempt reuses the same waiting order', r.j && r.j.order);
|
||||
ok(r.status === 200 && r.j && r.j.needPay === true && r.j.payUrl === '/my?from=gamepass#buy' && r.j.order && r.j.package === 5 && /package/.test(r.j.message || ''), 'buy -> needPay + payUrl + waiting order (never a credit charge)', JSON.stringify(r.j && { needPay: r.j.needPay, payUrl: r.j.payUrl, pkg: r.j.package }));
|
||||
const order1 = r.j && r.j.order, order1Ts = r.j && r.j.orderTs;
|
||||
r = await api('/api/my/gamepass/buy', { data: { devPaid: true } }, hA);
|
||||
ok(r.j && r.j.order === order1 && r.j.needPay === true && !r.j.ok, 'a second buy (even with the retired devPaid flag) reuses the same waiting order, no pass', r.j && r.j.order);
|
||||
g = (await api('/api/my/gamepass', null, hA)).j; ok(g.waiting === true && g.active === false, 'GET shows waiting: true', '');
|
||||
r = await api('/api/dev/gamepass-purchase', { data: { email: A, cents: 500 } });
|
||||
ok(r.j && r.j.order && r.j.order.order === order1, 'a $5 package purchase event fulfils the waiting order', JSON.stringify(r.j));
|
||||
r = await api('/api/dev/gamepass-purchase', { data: { email: A, cents: 500, minedAt: order1Ts - 10 * 60000 } });
|
||||
ok(r.j && r.j.order === null, 'a package mined BEFORE the order was opened does not fulfil it', JSON.stringify(r.j));
|
||||
r = await api('/api/dev/gamepass-purchase', { data: { email: A, cents: 200 } });
|
||||
ok(r.j && r.j.order === null, 'a $2 package does not fulfil a $5 pass order', JSON.stringify(r.j));
|
||||
r = await api('/api/dev/gamepass-purchase', { data: { email: Bm, cents: 500 } });
|
||||
ok(r.j && r.j.order === null, 'another member’s package does not fulfil A’s order', JSON.stringify(r.j));
|
||||
const tx1 = '0x' + crypto.randomBytes(32).toString('hex');
|
||||
r = await api('/api/dev/gamepass-purchase', { data: { email: A, cents: 500, tx: tx1, now: SUN } });
|
||||
ok(r.j && r.j.order && r.j.order.order === order1, 'a fresh $5 package by A fulfils the waiting order', JSON.stringify(r.j));
|
||||
g = (await api('/api/my/gamepass', null, hA)).j; const until1 = g.until;
|
||||
ok(g.active === true && g.waiting === false && near(g.until, Date.now() + 7 * 86400000, 60000) && g.bought === 1, 'pass active for 7 days, waiting cleared', new Date(g.until).toISOString());
|
||||
ok(g.active === true && g.waiting === false && g.until === SUN + 7 * 86400000 && g.bought === 1, 'pass active for 7 days from the purchase, waiting cleared', new Date(g.until).toISOString());
|
||||
r = await api('/api/dev/gamepass-purchase', { data: { email: A, cents: 500 } });
|
||||
ok(r.j && r.j.order === null, 'another package with no waiting order does nothing', JSON.stringify(r.j));
|
||||
// 3. buy while active -> extends from the current until (charge stubbed: devPaid, local only)
|
||||
r = await api('/api/my/gamepass/buy', { data: { devPaid: true } }, hA);
|
||||
ok(r.status === 200 && r.j.ok && near(r.j.until, until1 + 7 * 86400000, 1000) && r.j.paid === 'credits', 'buy while active extends by 7 days from the current until', new Date(r.j.until).toISOString());
|
||||
r = await api('/api/my/gamepass/buy', { data: { devPaid: true, devDay: '2026-10-20' } }, hB);
|
||||
ok(r.status === 200 && r.j.ok && r.j.active === true, 'member B: buy -> active (sale stamped in the week of Oct 19 for the tournament)', '');
|
||||
// 3. buy while active -> a new order; the same tx again is refused, a new package extends from the current until
|
||||
r = await api('/api/my/gamepass/buy', { data: {} }, hA);
|
||||
ok(r.j && r.j.needPay && r.j.order && r.j.order !== order1, 'buy while active opens a new waiting order', r.j && r.j.order);
|
||||
r = await api('/api/dev/gamepass-purchase', { data: { email: A, cents: 500, tx: tx1, now: SUN } });
|
||||
ok(r.j && r.j.order === null, 'replaying a purchase tx that already paid a pass does nothing (each tx once)', JSON.stringify(r.j));
|
||||
r = await api('/api/dev/gamepass-purchase', { data: { email: A, cents: 500, now: SUN } });
|
||||
ok(r.j && r.j.order && near(r.j.order.until, until1 + 7 * 86400000, 1000), 'a fresh package while active extends by 7 days from the current until', r.j && r.j.order && new Date(r.j.order.until).toISOString());
|
||||
r = await api('/api/my/gamepass/buy', { data: {} }, hB);
|
||||
r = await api('/api/dev/gamepass-purchase', { data: { email: Bm, cents: 1000, now: TUE } });
|
||||
g = (await api('/api/my/gamepass', null, hB)).j;
|
||||
ok(r.j && r.j.order && g.active === true, 'member B: order + a $10 package -> active (sale stamped in the week of Oct 19 for the tournament)', JSON.stringify(r.j));
|
||||
|
||||
// 4. partner auth + /api/partner/player
|
||||
let pl = await gameGet('/api/partner/player', { game: 'gemkingdom', m: 0, e: A }, A, GK);
|
||||
|
||||
@@ -624,6 +624,7 @@ async function boot() {
|
||||
blog.init({ dataDir: DATA_DIR });
|
||||
adminMember.init({ accounts, ads, chain, tank, legacy, promos, messages, dataDir: DATA_DIR });
|
||||
gamepass.init({ dataDir: DATA_DIR, siteConfig, accounts, marks, isProd: IS_PROD, persistedMap, polUsd: polUsdLive,
|
||||
blockTime: async n => { const blk = await chain.rpc('eth_getBlockByNumber', ['0x' + Number(n).toString(16), false]); return blk && blk.timestamp ? parseInt(blk.timestamp, 16) : 0; }, // a pass order is fulfilled only by a purchase mined after it
|
||||
telegram: async html => { const sc = siteConfig(); const chat = String(sc.telegramGamesChatId || sc.telegramEchoChatId || '').trim(); if (!sc.telegramBotToken || !chat) return false; await telegramSend(chat, html, sc.telegramGamesTopicId || null); return true; },
|
||||
notify: (to, subject, html) => messages.deliver(1, ADMIN_EMAIL || 'house@instantadpay.com', [to], subject, html, 'notice') }); // before loadOpenTokens: its maps must exist to be restored
|
||||
loadOpenTokens();
|
||||
@@ -3965,14 +3966,14 @@ const server = http.createServer(async (req, res) => {
|
||||
if (p === '/api/my/gamepass/buy' && req.method === 'POST') {
|
||||
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
|
||||
if (fraud.isSuspended(s.email)) return json(res, 403, { error: 'This account is suspended.' });
|
||||
const b = await readBody(req); const { ids } = await myMemberIds(s);
|
||||
// purchased-grade credits only, from a position's package balance (the PolyWarriors mint rule); devPaid = local tests only
|
||||
const charge = (!IS_PROD && b.devPaid) ? async () => ({ ok: true, campaignId: 0, dev: true }) : (price, label) => ads.gamePurchase(s.email, ids, price, label, 'https://instantadpay.com/my#games', { purchasedOnly: true });
|
||||
const b = await readBody(req);
|
||||
// 2026-10-22 (Marty): no pass is ever bought with credits. Buy only opens a waiting order; a FRESH package purchase of at least the
|
||||
// tier price, by one of this member's own positions, fulfils it (gamepass.onEvent), so the sponsor and team are paid as usual.
|
||||
// tier: weekly (missing) | explorer | champion | sovereign | legend; every tier above weekly is refused unless sovTiers is on, except for the ADMIN_EMAIL account (testing)
|
||||
const r = await gamepass.buy(s.email, charge, gpDevNow(b.devDay), b.tier, { admin: !!ADMIN_EMAIL && String(s.email).toLowerCase() === ADMIN_EMAIL });
|
||||
const r = gamepass.buy(s.email, gpDevNow(b.devDay), b.tier, { admin: !!ADMIN_EMAIL && String(s.email).toLowerCase() === ADMIN_EMAIL });
|
||||
return json(res, r.error ? 400 : 200, r);
|
||||
}
|
||||
if (!IS_PROD && p === '/api/dev/gamepass-purchase' && req.method === 'POST') { const b = await readBody(req); return json(res, 200, { order: await gamepass.onEvent({ type: 'Purchase', priceCents: Number(b.cents) || 500, buyerId: 0, tx: '0x' + crypto.randomBytes(32).toString('hex'), ts: Date.now(), devEmail: b.email }) }); } // local tests only
|
||||
if (!IS_PROD && p === '/api/dev/gamepass-purchase' && req.method === 'POST') { const b = await readBody(req); return json(res, 200, { order: await gamepass.onEvent({ type: 'Purchase', priceCents: Number(b.cents) || 500, buyerId: 0, tx: /^0x[0-9a-f]{64}$/.test(String(b.tx || '')) ? b.tx : '0x' + crypto.randomBytes(32).toString('hex'), ts: Date.now(), devEmail: b.email, devMinedAt: Number(b.minedAt) || 0, devNow: Number(b.now) || 0 }) }); } // local tests only (minedAt fakes the block time, now the fulfilment time, tx replays a hash)
|
||||
if (p === '/api/admin/gamepass/stats' && req.method === 'GET') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); return json(res, 200, gamepass.adminStats()); }
|
||||
if (p === '/api/admin/gamepass/comp' && req.method === 'POST') { // support: give an account a pass week without a purchase
|
||||
if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); const b = await readBody(req); const e = String(b.email || '').trim().toLowerCase(); if (!e) return json(res, 400, { error: 'email required' });
|
||||
|
||||
Reference in New Issue
Block a user