Held purchase: nudge the sponsor automatically (email + on-site) to link a wallet and switch on payouts, once an hour at most

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-09-15 23:43:11 -05:00
parent b7cc06b28c
commit 84d9f49d4b
2 changed files with 25 additions and 0 deletions
+24
View File
@@ -547,6 +547,30 @@ function sponsorBlockedAlert(who, r) {
const sc = siteConfig();
if (sc.telegramBotToken && sc.telegramAdminChatId) telegramSend(sc.telegramAdminChatId, text).catch(() => {});
else if (ADMIN_EMAIL && mailer.hasKey()) mailer.send(ADMIN_EMAIL, 'InstantAdPay: purchase held, sponsor unresolved', text).catch(() => {});
// and the sponsor themselves (Marty, 2026-09-15): a buy is waiting on them, once an hour at most
if (r.reason === 'notActivated') sponsorHoldNudge(String(r.tok || ''), k).catch(() => {});
}
const sponsorNudgeLast = new Map(); // sponsor email -> ts
async function sponsorHoldNudge(tok, buyerEmail) {
const t = String(tok || '').trim().toLowerCase(); if (!t) return;
let sp = await accounts.byCode(t); if (!sp) sp = await accounts.byUsername(t);
if (!sp || !sp.email) return;
if (Date.now() - (sponsorNudgeLast.get(sp.email) || 0) < 3600000) return; sponsorNudgeLast.set(sp.email, Date.now());
const buyer = await accounts.byEmail(buyerEmail); const bn = buyer && buyer.username ? '@' + buyer.username : 'One of your referrals';
const step = !sp.address ? 'link a wallet and switch on payouts' : 'switch on payouts';
const subject = bn + ' is trying to buy. ' + (sp.address ? 'Switch on payouts' : 'Link your wallet') + ' so it pays you';
const lines = [
bn + ' just tried to buy an ad package on InstantAdPay, and the purchase is on hold because payouts are not switched on for your account yet. The contract pays your share in the same transaction, but only to a wallet that is switched on, so the site paused the buy instead of sending your 50 percent to someone else.',
'To fix it: open the Wallet tab and ' + step + '. One free signature to link, one small transaction to switch on. Takes two minutes, and every purchase in your line from then on pays you the moment it happens.',
'Until then their purchase waits, and they have been told why.',
'Wallet tab: https://instantadpay.com/my#wallet'
];
const text = lines.join('\n\n');
if (mailer.hasKey()) mailer.send(sp.email, subject, text + '\n\nInstantAdPay').catch(() => {});
try {
const html = lines.map(l => '<p>' + l.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/(https:\/\/[^\s]+)/g, '<a href="$1" target="_blank" rel="noopener">$1</a>') + '</p>').join('');
await messages.deliver(1, ADMIN_EMAIL || 'house@instantadpay.com', [sp.email], subject, html);
} catch (e) {}
}
// The moment someone joins through a code, nudge its owner to activate.
// Email a member's sponsor the moment they get a new referral (free OR paid).