feat(economy): offer a free offline payment option

Expose free payment in the in-game dialog, local store, and marketplace.
Grant the selected item without debiting GJN and reject unknown payment
methods. Apply the configured per-purchase limit consistently.

Type checking, binary and GUI patch checks, and local purchase checks
passed. In-game acceptance is pending.
This commit is contained in:
N0VAN0M4LY committed 2026-11-25 13:41:37 +08:00
1 parent e1468df52b
commit 4d8229ae92
9 files changed
+161 -56

No files matched your search

+17 -12
View File
@@ -8,7 +8,7 @@ const T = {
tabPacks: '礼包载具', tabPremium: '高级账户', tabEagles: '金鹰', tabRedeem: '兑换码',
search: '搜索礼包或载具名称', allCountries: '全部国家', allRanks: '全部等级', rank: '{rank} 级',
includesUnit: '包含载具:{name}', containsEagles: '附赠 {n} 金鹰', containsSilver: '附赠 {n} 银狮', containsPremium: '附赠 {days} 天高级账户', premiumDays: '{days} 天高级账户',
buy: '购买', owned: '已拥有', pickAccount: '请先选择账号', redeem: '兑换', codePlaceholder: '输入兑换码', empty: '没有符合条件的商品',
buy: '购买', freeBuy: '老福爷付过了', owned: '已拥有', pickAccount: '请先选择账号', redeem: '兑换', codePlaceholder: '输入兑换码', empty: '没有符合条件的商品',
},
en: {
title: 'WTOffline Store', hint: 'Close this window after buying to refresh the hangar', toMarket: 'Go to Marketplace',
@@ -16,7 +16,7 @@ const T = {
tabPacks: 'Vehicle packs', tabPremium: 'Premium Account', tabEagles: 'Golden Eagles', tabRedeem: 'Redeem code',
search: 'Search packs or vehicles', allCountries: 'All nations', allRanks: 'All ranks', rank: 'Rank {rank}',
includesUnit: 'Vehicle: {name}', containsEagles: '+{n} Golden Eagles', containsSilver: '+{n} Silver Lions', containsPremium: '+{days} days of Premium Account', premiumDays: '{days} days of Premium Account',
buy: 'Buy', owned: 'Owned', pickAccount: 'Pick an account first', redeem: 'Redeem', codePlaceholder: 'Enter a code', empty: 'Nothing matches the filters',
buy: 'Buy', freeBuy: '老福爷付过了', owned: 'Owned', pickAccount: 'Pick an account first', redeem: 'Redeem', codePlaceholder: 'Enter a code', empty: 'Nothing matches the filters',
},
};
const ROMAN = ['', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X'];
@@ -109,15 +109,20 @@ function productCard(product) {
const foot = document.createElement('div');
foot.className = 'card-foot';
foot.innerHTML = '<span class="price"></span>';
foot.innerHTML = '<span class="price"></span><div class="buy-actions"></div>';
foot.querySelector('.price').textContent = WtoUi.gjn(product.gjnCostCents) + ' GJN';
const btn = Object.assign(document.createElement('button'), {
className: 'buy',
textContent: product.owned ? t('owned') : (state.activeUserId ? t('buy') : t('pickAccount')),
disabled: product.owned || !state.activeUserId,
});
if (!btn.disabled) btn.onclick = () => buy(product.id);
foot.appendChild(btn);
const actions = foot.querySelector('.buy-actions');
if (product.owned || !state.activeUserId) {
actions.appendChild(Object.assign(document.createElement('button'), {
className: 'buy', textContent: product.owned ? t('owned') : t('pickAccount'), disabled: true,
}));
} else {
const gjnBtn = Object.assign(document.createElement('button'), { className: 'buy', textContent: t('buy') });
gjnBtn.onclick = () => buy(product.id, 'gjn');
const freeBtn = Object.assign(document.createElement('button'), { className: 'buy free', textContent: t('freeBuy') });
freeBtn.onclick = () => buy(product.id, 'free');
actions.append(gjnBtn, freeBtn);
}
card.appendChild(foot);
return card;
}
@@ -156,8 +161,8 @@ function renderRedeemHelp() {
for (const line of state.redeemHelp) list.appendChild(Object.assign(document.createElement('li'), { textContent: WtoUi.text(line) }));
}
async function buy(productId) {
const result = await WtoUi.postJson('/store/api/buy', { userId: state.activeUserId, productId });
async function buy(productId, payMethod) {
const result = await WtoUi.postJson('/store/api/buy', { userId: state.activeUserId, productId, payMethod });
WtoUi.showNotice($('notice'), WtoUi.text(result.message), result.ok);
await loadState(state.activeUserId);
}