BixPay card integration, phase 1 (Marty approved the copy 2026-10-29; docs/BIXPAY-INTEGRATION.md): gated by site config bixpayLive (off by default). Profile > BixPay card field (partner link validated: bix.ibportal.io/auth/register, e= token, a=1; the appId=3 card-customer link is refused with a message), bixpay.js resolver own > sponsor chain (10 levels) > company link (bixCompanyLink, seeded with Marty's partner link), every surface says whose link it is. Wallet tab card, one-week Overview announcement (24 h snooze), one sentence in TierPaid payout emails and the games' wallet nudges, Promo tools > BixPay tab (3 posts, email swipe, 4 text-only banners on the Spaces CDN, tracked link + per-member clicks), public guide /bixpay with masked app screenshots, chatbot canned answers + facts gated to 'coming soon' while off (KNOWLEDGE_DATE 2026-10-29). Clicks per surface via /go/bixpay in the admin Traffic tab; admin Overview counts members with a link; member card shows it; signed /api/partner/bixpay and the lssync profile row carry it for LinkSpin/CTB. accounts.bix_partner_link column (db.js alterSafe). Tests: qa/bixpay.test.cjs (17) + walk.mjs BixPay block; my.js/promo.js/admin.js ?v=20261029bx.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-29 07:56:49 -05:00
parent 6e1ab102f1
commit ed6febe0b8
29 changed files with 971 additions and 27 deletions
+94
View File
@@ -0,0 +1,94 @@
// BixPay (bixpay.js, 2026-10-29): the partner-link validator, the sponsor-follows resolver (own / sponsor at level 3 / none ->
// company), the gate, the email + nudge lines and the click store. Fake accounts, throwaway data dir. Run: node qa/bixpay.test.cjs
'use strict';
const fs = require('fs');
const os = require('os');
const path = require('path');
const assert = require('assert');
const ROOT = path.join(__dirname, '..');
let fails = 0, n = 0;
async function t(name, fn) { n++; try { await fn(); console.log('ok', name); } catch (e) { fails++; console.log('FAIL', name, '::', e.message); } }
const bixpay = require(path.join(ROOT, 'bixpay.js'));
const walletnudge = require(path.join(ROOT, 'walletnudge.js'));
const PARTNER = 'https://bix.ibportal.io/auth/register?e=XqwU9T1aJ5N0UJ0yr9x0TGUiSQTsVCkTM01MIovVNnc&a=1';
const CUSTOMER = 'https://bix.ibportal.io/auth/register?e=boUGQ_dC9B472D9LGfzxPKvgfBw1iyqx-xffnx1kqPM&a=1&appId=3';
const L3 = 'https://bix.ibportal.io/auth/register?e=' + 'L3token_'.repeat(5) + '&a=1';
// a five-deep line: leaf -> s1 -> s2 -> s3 (has a link) -> s4 -> s5; plus a loop pair and an orphan
const A = {};
const mk = (email, sponsor, link, username) => { A[email] = { email, sponsorRef: sponsor || '', bixPartnerLink: link || null, username: username || null, code: email.split('@')[0] }; };
mk('leaf@x.test', 's1', null, 'leaf'); mk('s1@x.test', 's2', null, 's1'); mk('s2@x.test', 's3', null, 's2'); mk('s3@x.test', 's4', L3, 's3'); mk('s4@x.test', 's5', null, 's4'); mk('s5@x.test', '', null, 's5');
mk('own@x.test', 's1', PARTNER, 'own'); mk('orphan@x.test', '', null, 'orphan');
mk('loopa@x.test', 'loopb', null, 'loopa'); mk('loopb@x.test', 'loopa', null, 'loopb');
// twelve deep with the only link at level 11: must fall to the company (10-level walk)
let prev = ''; for (let i = 12; i >= 1; i--) { mk('d' + i + '@x.test', prev, i === 12 ? L3 : null, 'd' + i); prev = 'd' + i; }
mk('deep@x.test', 'd1', null, 'deep');
const accounts = { byEmail: async e => A[e] || null, sponsorOf: async e => { const a = A[e]; if (!a || !a.sponsorRef) return null; return Object.values(A).find(x => x.username === a.sponsorRef || x.code === a.sponsorRef) || null; } };
let site = { bixpayLive: '1', bixCompanyLink: '' };
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'bixpay-test-'));
bixpay.init({ dataDir: dir, accounts, siteConfig: () => site, refAccount: async tok => Object.values(A).find(x => x.username === tok || x.code === tok) || null });
(async () => {
await t('validator: the partner link passes and normalises', () => { const v = bixpay.validate(' ' + PARTNER + ' '); assert.ok(v.ok); assert.strictEqual(v.link, PARTNER); });
await t('validator: extra params are dropped, e= and a=1 kept', () => { const v = bixpay.validate(PARTNER + '&utm=x'); assert.ok(v.ok); assert.strictEqual(v.link, PARTNER); });
await t('validator: the appId=3 customer link is refused with the message', () => { const v = bixpay.validate(CUSTOMER); assert.ok(!v.ok); assert.strictEqual(v.error, bixpay.CUSTOMER_LINK_MSG); });
await t('validator: wrong host, wrong path, no e=, no a=1, too long, empty, http', () => {
assert.ok(bixpay.validate('https://bix.fi/r?code=ABCDEFGH').error);
assert.ok(bixpay.validate('https://bix.ibportal.io/auth/login?e=' + 'x'.repeat(40) + '&a=1').error);
assert.ok(bixpay.validate('https://bix.ibportal.io/auth/register?a=1').error);
assert.ok(bixpay.validate('https://bix.ibportal.io/auth/register?e=' + 'x'.repeat(40)).error);
assert.ok(bixpay.validate('https://bix.ibportal.io/auth/register?e=' + 'x'.repeat(40) + '&a=2').error);
assert.ok(bixpay.validate('https://bix.ibportal.io/auth/register?e=' + 'x'.repeat(300) + '&a=1').error);
assert.ok(bixpay.validate('').error); assert.ok(bixpay.validate(null).error);
assert.ok(bixpay.validate('http://bix.ibportal.io/auth/register?e=' + 'x'.repeat(40) + '&a=1').error);
assert.ok(bixpay.validate('javascript:alert(1)').error);
});
await t('resolver: own link wins', async () => { const r = await bixpay.resolve(A['own@x.test']); assert.strictEqual(r.whose, 'you'); assert.strictEqual(r.link, PARTNER); });
await t('resolver: no own link -> first sponsor up the chain with one (level 3)', async () => { const r = await bixpay.resolve(A['leaf@x.test']); assert.strictEqual(r.whose, 'sponsor'); assert.strictEqual(r.name, '@s3'); assert.strictEqual(r.email, 's3@x.test'); assert.ok(r.link.includes('L3token_')); });
await t('resolver: nobody up the chain -> company (default = Marty’s partner link)', async () => { const r = await bixpay.resolve(A['orphan@x.test']); assert.strictEqual(r.whose, 'network'); assert.strictEqual(r.link, bixpay.DEFAULT_COMPANY_LINK); assert.strictEqual(r.name, null); });
await t('resolver: null member -> company', async () => { const r = await bixpay.resolve(null); assert.strictEqual(r.whose, 'network'); });
await t('resolver: the walk stops at 10 levels (link at level 12 is not reached)', async () => { const r = await bixpay.resolve(A['deep@x.test']); assert.strictEqual(r.whose, 'network'); });
await t('resolver: a sponsor loop ends in the company link, no hang', async () => { const r = await bixpay.resolve(A['loopa@x.test']); assert.strictEqual(r.whose, 'network'); });
await t('resolver: site config bixCompanyLink overrides the default; a bad one falls back', async () => {
site.bixCompanyLink = L3; assert.strictEqual((await bixpay.resolve(null)).link, L3.replace(/&a=1$/, '&a=1'));
site.bixCompanyLink = 'https://evil.example/x'; assert.strictEqual((await bixpay.resolve(null)).link, bixpay.DEFAULT_COMPANY_LINK);
site.bixCompanyLink = '';
});
await t('resolveRef: a public page ?ref resolves like that member', async () => { const r = await bixpay.resolveRef('leaf'); assert.strictEqual(r.whose, 'sponsor'); const o = await bixpay.resolveRef('own'); assert.strictEqual(o.whose, 'you'); const u = await bixpay.resolveRef('nobody_zz'); assert.strictEqual(u.whose, 'network'); });
await t('usingLine: the three wordings', async () => {
assert.strictEqual(bixpay.usingLine(await bixpay.resolve(A['own@x.test'])), 'Using: your link.');
assert.strictEqual(bixpay.usingLine(await bixpay.resolve(A['leaf@x.test'])), "Using: @s3's link. Add yours in Profile.");
assert.strictEqual(bixpay.usingLine(await bixpay.resolve(null)), 'Using: the network link. Add yours in Profile.');
});
await t('gate: live/announcing follow site config; email and nudge lines are empty while off', () => {
assert.ok(bixpay.live()); assert.ok(bixpay.announcing());
site.bixpayLiveSince = new Date(Date.now() - 8 * 86400000).toISOString(); assert.ok(!bixpay.announcing()); site.bixpayLiveSince = '';
assert.ok(bixpay.emailLine('own').includes('/go/bixpay?s=email&m=own')); assert.ok(bixpay.nudgeLine('own').includes('s=nudge'));
assert.ok(!/—/.test(bixpay.emailLine('own')));
site.bixpayLive = '0'; assert.ok(!bixpay.live()); assert.strictEqual(bixpay.emailLine('own'), ''); assert.strictEqual(bixpay.nudgeLine('own'), ''); site.bixpayLive = '1';
});
await t('walletnudge copy carries the BixPay sentence only when given one', () => {
const c0 = walletnudge.copy([{ key: 'g', name: 'Gem Kingdom', unpaid: 1.5 }], 0, 'https://instantadpay.com/my#wallet', '');
assert.ok(!/BixPay/.test(c0.text) && !/BixPay/.test(c0.html));
const c1 = walletnudge.copy([{ key: 'g', name: 'Gem Kingdom', unpaid: 1.5 }], 0, 'https://instantadpay.com/my#wallet', bixpay.nudgeLine('own'));
assert.ok(/BixPay Visa card/.test(c1.text) && /go\/bixpay\?s=nudge/.test(c1.html));
assert.ok(c1.text.indexOf('Link your wallet:') < c1.text.indexOf('BixPay'), 'the wallet ask stays first');
});
await t('clicks: per surface, per member, per day; unknown surface -> other; bot-free store', () => {
bixpay.click('wallet', 'own@x.test'); bixpay.click('promo', 'own@x.test'); bixpay.click('promo', 'own@x.test'); bixpay.click('guide', null); bixpay.click('weird', 'leaf@x.test');
const m = bixpay.memberClicks('own@x.test'); assert.strictEqual(m.total, 3); assert.strictEqual(m.promo, 2); assert.strictEqual(m.wallet, 1);
const v = bixpay.adminView(30); assert.strictEqual(v.total, 5); assert.strictEqual(v.bySurface.promo, 2); assert.strictEqual(v.bySurface.other, 1); assert.strictEqual(v.members[0].email, 'own@x.test'); assert.strictEqual(v.daily.length, 1);
bixpay._reset(); assert.strictEqual(bixpay.memberClicks('own@x.test').total, 3, 'persisted to disk');
});
await t('copy rules: no em dashes in any BixPay copy shipped to members', () => {
const files = ['bixpay.js', 'public/assets/promo.js', 'public/assets/my.js', 'public/bixpay.html', 'public/assets/bixpay-guide.js', 'chatbot.js'];
for (const f of files) { const s = fs.readFileSync(path.join(ROOT, f), 'utf8'); const lines = s.split('\n').filter(l => /bix/i.test(l) && /—/.test(l)); assert.strictEqual(lines.length, 0, f + ' has an em dash on a BixPay line'); }
const pj = fs.readFileSync(path.join(ROOT, 'public/assets/promo.js'), 'utf8');
assert.ok(/no load fee/.test(pj) && !/in-app swap/i.test(pj.split('BIX_POSTS')[1].split('BIX_CDN')[0]), 'posts never promise the in-app swap');
});
fs.rmSync(dir, { recursive: true, force: true });
console.log('\nbixpay: ' + (n - fails) + '/' + n + ' passed');
process.exit(fails ? 1 : 0);
})();
+4
View File
@@ -17,6 +17,7 @@
# bash qa/run.sh override # level-4 override: week math, hunt, house, dust carry, cap, balance, two concurrent payers (fake chain + signer, throwaway data)
# bash qa/run.sh convpixel # conversion pixel: lsclk click ids on /api/ads/click, signed push to a MOCK LinkSpin, own-click self flag, Campaigns > Conversion tracking + cost per goal, LinkSpin down (local copy, throwaway data)
# bash qa/run.sh fuel # Fuel Your Offers: refill notices, refuel streak, Refuel Kit, Engine Room (unit + two-copy tests, throwaway data)
# bash qa/run.sh bixpay # BixPay card: partner-link validator, sponsor-follows resolver (own / level 3 / company), gate, click store (unit, no server; also runs in member)
# Each local run boots server.js on its own port with a throwaway data dir (JSON store, no DB, no
# mail key, devCode sign-in), so nothing touches production data. Reports land in qa/out/.
set -u
@@ -45,6 +46,9 @@ elif [ "$MODE" = "member" ]; then
start_local 8796 && { LOCAL=http://127.0.0.1:8796 node qa/walk.mjs member || status=1; }; stop_local 8796
node qa/tank-hold.mjs || status=1
node qa/walletnudge.test.cjs || status=1
node qa/bixpay.test.cjs || status=1
elif [ "$MODE" = "bixpay" ]; then
node qa/bixpay.test.cjs || status=1
elif [ "$MODE" = "walletnudge" ]; then
node qa/walletnudge.test.cjs || status=1
elif [ "$MODE" = "tankhold" ]; then
+61
View File
@@ -125,6 +125,67 @@ if (MODE === 'member' || MODE === 'all') {
await page.goto(LOCAL + '/my#games'); await page.reload({ waitUntil: 'load' }); await page.waitForTimeout(2500); await hide(page); // a hash-only goto would not reload the card
if (await page.evaluate(() => { const c = document.getElementById('gpCard'); return !!(c && !c.hidden); })) note('bug', L + 'my#games/gamepass', 'Game Pass card shows while gamePassEnabled is off');
flush(bag, L + 'my#games/gamepass');
// BixPay card (2026-10-29): nothing while bixpayLive is off; once on: Wallet card, Overview card, Profile field (customer link refused,
// partner link saved, "Using: your link"), the Promo tab with posts + 4 banners + the tracked link, /bixpay 200 with the CTA, /go/bixpay 302s
const ADM = { Authorization: 'Bearer ' + (process.env.ADMIN_PASSWORD || 'localtest'), 'Content-Type': 'application/json' };
{
const B = L + 'bixpay';
const me0 = await page.evaluate(() => fetch('/api/me').then(r => r.json())); const tok = me0.username || me0.refCode;
await page.click('.bo-menu [data-pane="wallet"]'); await page.waitForTimeout(800);
if (await page.evaluate(() => { const c = document.getElementById('bixWalletCard'); return !!(c && !c.hidden); })) note('bug', B + '/off', 'Wallet card shows while bixpayLive is off');
if ((await page.request.get(LOCAL + '/bixpay')).status() !== 404) note('bug', B + '/off', '/bixpay served while bixpayLive is off');
await page.request.patch(LOCAL + '/api/admin/site', { headers: ADM, data: { bixpayLive: '1' } }).catch(() => {});
await page.goto(LOCAL + '/my#wallet'); await page.reload({ waitUntil: 'load' }); await page.waitForTimeout(2500); await hide(page);
const wc = await page.evaluate(() => { const c = document.getElementById('bixWalletCard'); return c && !c.hidden ? c.textContent : ''; });
if (!/Spend your POL anywhere with a BixPay Visa card/.test(wc) || !/3% per purchase, no load fee/.test(wc) || !/31 US states/.test(wc) || !/Using: the network link/.test(wc)) note('bug', B + '/wallet', 'Wallet card missing or wrong copy: ' + wc.slice(0, 120));
const goHref = await page.$eval('#bixWalletGo', e => e.getAttribute('href')).catch(() => '');
if (!/\/go\/bixpay\?s=wallet/.test(goHref)) note('bug', B + '/wallet', 'button is not the counted /go link: ' + goHref);
await domChecks(page, B + '/wallet'); await page.screenshot({ path: OUT + '/my-wallet-bixpay.png' }).catch(() => {});
await page.click('.bo-menu [data-pane="overview"]'); await page.waitForTimeout(800);
if (!(await page.evaluate(() => { const c = document.getElementById('bixCard'); return !!(c && !c.hidden && /Visa card for your POL/.test(c.textContent) && c.querySelector('.card-x')); }))) note('bug', B + '/overview', 'announcement card missing or not dismissable');
// profile: the customer link is refused, the partner link saves, the wallet card switches to "your link"
await page.click('.bo-menu [data-pane="profile"]'); await page.waitForTimeout(800); await hide(page);
if (!(await page.$('#pfBixCard:not([hidden])'))) note('bug', B + '/profile', 'BixPay card section hidden while live');
await page.fill('#pfBixLink', 'https://bix.ibportal.io/auth/register?e=boUGQ_dC9B472D9LGfzxPKvgfBw1iyqx-xffnx1kqPM&a=1&appId=3'); await page.click('#pfBixSave'); await page.waitForTimeout(900);
if (!/card-customer link/.test(await page.$eval('#pfBixStatus', e => e.textContent).catch(() => ''))) note('bug', B + '/profile', 'customer link (appId=3) was not refused with the message');
await page.fill('#pfBixLink', 'https://bix.ibportal.io/auth/register?e=QAwalkTOKENqawalkTOKENqawalkTOKENqawalkTOK&a=1'); await page.click('#pfBixSave'); await page.waitForTimeout(1200);
if (!/Saved/.test(await page.$eval('#pfBixStatus', e => e.textContent).catch(() => ''))) note('bug', B + '/profile', 'partner link did not save');
await page.screenshot({ path: OUT + '/my-profile-bixpay.png' }).catch(() => {});
const me2 = await page.evaluate(() => fetch('/api/me').then(r => r.json()));
if (!me2.bix || me2.bix.whose !== 'you' || !/e=QAwalkTOKEN/.test(me2.bix.link)) note('bug', B + '/api/me', 'resolved link is not the member’s own after saving: ' + JSON.stringify(me2.bix || {}).slice(0, 160));
await page.click('.bo-menu [data-pane="wallet"]'); await page.waitForTimeout(600);
if (!/Using: your link/.test(await page.$eval('#bixWalletCard', e => e.textContent).catch(() => ''))) note('bug', B + '/wallet', 'Wallet card did not switch to "Using: your link"');
// promo tab
await page.click('.bo-menu [data-pane="promo"]'); await page.waitForTimeout(600);
const bpill = await page.$('.promo-pills [data-promo="bixpay"]:not([hidden])'); if (!bpill) note('bug', B + '/promo', 'BixPay pill hidden while live');
else { await bpill.click(); await page.waitForTimeout(900);
const sec = await page.evaluate(() => { const s = document.getElementById('promo-bixpay'); return s && !s.hidden ? { posts: s.querySelectorAll('#bixPromoPosts .promo-block').length, swipe: s.querySelectorAll('#bixPromoSwipe .promo-block').length, banners: s.querySelectorAll('#bixPromoBanners .promo-block').length, link: document.getElementById('bixPromoLink').textContent, go: document.getElementById('bixPromoGo').textContent, text: s.textContent } : null; });
if (!sec) note('bug', B + '/promo', 'BixPay section did not show');
else { if (sec.posts !== 3 || sec.swipe !== 1 || sec.banners !== 4) note('bug', B + '/promo', 'expected 3 posts, 1 swipe, 4 banners; got ' + sec.posts + '/' + sec.swipe + '/' + sec.banners);
if (!/e=QAwalkTOKEN/.test(sec.link)) note('bug', B + '/promo', 'partner link box is not the member’s own');
if (!/\/go\/bixpay\?s=promo&m=/.test(sec.go)) note('bug', B + '/promo', 'tracked link missing: ' + sec.go);
if (/—/.test(sec.text)) note('bug', B + '/promo', 'em dash in BixPay promo copy'); }
await domChecks(page, B + '/promo'); await page.screenshot({ path: OUT + '/my-promo-bixpay.png', fullPage: true }).catch(() => {}); }
// the counted redirect + the public guide
const go = await page.request.get(LOCAL + '/go/bixpay?s=promo&m=' + tok, { maxRedirects: 0 });
if (go.status() !== 302 || !/e=QAwalkTOKEN/.test(go.headers().location || '')) note('bug', B + '/go', 'expected a 302 to the member’s partner link, got ' + go.status() + ' ' + (go.headers().location || ''));
const me3 = await page.evaluate(() => fetch('/api/me').then(r => r.json()));
if (!me3.bix || !me3.bix.clicks || !(me3.bix.clicks.promo >= 1)) note('bug', B + '/go', 'promo click was not counted for the member');
const gp = await page.request.get(LOCAL + '/bixpay?ref=' + tok); const gb = await gp.text();
if (gp.status() !== 200 || !/Get your BixPay card/.test(gb) || !/BixPay is a separate company/.test(gb)) note('bug', B + '/guide', '/bixpay did not serve with the CTA and the compliance box: ' + gp.status());
const pub = await (await page.request.get(LOCAL + '/api/public/bixpay?ref=' + tok)).json();
if (!pub.live || pub.whose !== 'you' || !/\/go\/bixpay\?s=guide&m=/.test(pub.go || '')) note('bug', B + '/guide', 'public resolver did not resolve the ?ref member: ' + JSON.stringify(pub).slice(0, 160));
const gctx = await browser.newContext({ viewport: { width: 1280, height: 900 } }); const gpage = await gctx.newPage(); const gbag = watch(gpage, LOCAL);
await gpage.goto(LOCAL + '/bixpay?ref=' + tok, { waitUntil: 'networkidle' }); await gpage.waitForTimeout(800);
await domChecks(gpage, B + '/guide'); flush(gbag, B + '/guide'); await gpage.screenshot({ path: OUT + '/bixpay-guide.png', fullPage: true }).catch(() => {}); await gctx.close();
// clean up: link removed, switch back off, everything hidden again
await page.evaluate(() => fetch('/api/my/bixpay', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{"link":""}' }).then(r => r.json())); // read the body before navigating, or the walk logs its own aborted request
await page.request.patch(LOCAL + '/api/admin/site', { headers: ADM, data: { bixpayLive: '0' } }).catch(() => {});
if ((await page.request.get(LOCAL + '/bixpay')).status() !== 404) note('bug', B + '/off', '/bixpay still served after switching off');
await page.goto(LOCAL + '/my#promo'); await page.reload({ waitUntil: 'load' }); await page.waitForTimeout(2500); await hide(page);
if (await page.$('.promo-pills [data-promo="bixpay"]:not([hidden])')) note('bug', B + '/off', 'BixPay pill still shows after switching off');
flush(bag, B); console.log('ok BixPay: wallet card, overview card, profile field, promo tab, /go, /bixpay');
}
await page.click('.bo-menu [data-pane="promo"]'); await page.waitForTimeout(800);
if (!(await page.$$('#promoPosts .promo-block')).length) note('bug', L + 'promo', 'no post cards rendered');
// viral links: the builder renders a ?ref= link; any page + ?ref=<member> redirects clean and sets the sponsor cookie; an unknown ref sets nothing