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:
1 parent
e1468df52b
commit
4d8229ae92
9 files changed
+161
-56
No files matched your search
@@ -8,14 +8,14 @@ const T = {
|
||||
eagles: '金鹰', lions: '银狮',
|
||||
catAll: '全部', catVehicle: '载具券', catSkin: '涂装券', catAttachable: '挂件券', catDecal: '贴花券', catUnlock: '头像与解锁券',
|
||||
search: '搜索名称或编号', allCountries: '全部国家', allClasses: '全部兵种', rank: '{rank} 级',
|
||||
held: '库存 ×{n}', activated: '已拥有', buy: '购买', pickAccount: '请先选择账号', empty: '没有符合条件的兑换券',
|
||||
held: '库存 ×{n}', activated: '已拥有', buy: '购买', freeBuy: '老福爷付过了', pickAccount: '请先选择账号', empty: '没有符合条件的兑换券',
|
||||
},
|
||||
en: {
|
||||
title: 'WTOffline Marketplace', hint: 'Coupons go straight to your inventory (Items → Inventory in the hangar)', toStore: 'Go to Store',
|
||||
eagles: 'Golden Eagles', lions: 'Silver Lions',
|
||||
catAll: 'All', catVehicle: 'Vehicles', catSkin: 'Camouflages', catAttachable: 'Decorations', catDecal: 'Decals', catUnlock: 'Icons and unlocks',
|
||||
search: 'Search name or id', allCountries: 'All nations', allClasses: 'All types', rank: 'Rank {rank}',
|
||||
held: 'In inventory ×{n}', activated: 'Owned', buy: 'Buy', pickAccount: 'Pick an account first', empty: 'Nothing matches the filters',
|
||||
held: 'In inventory ×{n}', activated: 'Owned', buy: 'Buy', freeBuy: '老福爷付过了', pickAccount: 'Pick an account first', empty: 'Nothing matches the filters',
|
||||
},
|
||||
};
|
||||
// Vehicle class of a listing -> the game's own type name (lang/menu.csv).
|
||||
@@ -114,21 +114,24 @@ function listingCard(listing) {
|
||||
|
||||
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(listing.gjnCostCents) + ' GJN';
|
||||
const btn = Object.assign(document.createElement('button'), {
|
||||
className: 'buy',
|
||||
textContent: state.currentUserId ? t('buy') : t('pickAccount'),
|
||||
disabled: !state.currentUserId,
|
||||
});
|
||||
if (!btn.disabled) btn.onclick = () => buy(listing.itemdefId);
|
||||
foot.appendChild(btn);
|
||||
const actions = foot.querySelector('.buy-actions');
|
||||
if (!state.currentUserId) {
|
||||
actions.appendChild(Object.assign(document.createElement('button'), { className: 'buy', textContent: t('pickAccount'), disabled: true }));
|
||||
} else {
|
||||
const gjnBtn = Object.assign(document.createElement('button'), { className: 'buy', textContent: t('buy') });
|
||||
gjnBtn.onclick = () => buy(listing.itemdefId, 'gjn');
|
||||
const freeBtn = Object.assign(document.createElement('button'), { className: 'buy free', textContent: t('freeBuy') });
|
||||
freeBtn.onclick = () => buy(listing.itemdefId, 'free');
|
||||
actions.append(gjnBtn, freeBtn);
|
||||
}
|
||||
card.appendChild(foot);
|
||||
return card;
|
||||
}
|
||||
|
||||
async function buy(itemdefId) {
|
||||
const result = await WtoUi.postJson('/trade.gaijin.net/api/buy', { userId: state.currentUserId, itemdefId, quantity: 1 });
|
||||
async function buy(itemdefId, payMethod) {
|
||||
const result = await WtoUi.postJson('/trade.gaijin.net/api/buy', { userId: state.currentUserId, itemdefId, quantity: 1, payMethod });
|
||||
WtoUi.showNotice($('notice'), WtoUi.text(result.message), result.ok);
|
||||
if (result.ok) await loadState(state.currentUserId);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user