feat(store): default free offline payment label to Direct Claim and make it tunable
Add tuning/store.jsonc freePaymentLabel (default Direct Claim in Chinese and English) and apply it consistently across the local web store, local marketplace, and the in-game payment dialog via cln_get_entitlements_price_ex top-level metadata.
This commit is contained in:
1 parent
429c5eec12
commit
12a573a333
10 files changed
+154
-29
No files matched your search
@@ -39,7 +39,27 @@ export interface MultiVehiclePack extends VehiclePackContent {
|
||||
readonly vehicles: readonly string[];
|
||||
}
|
||||
|
||||
export const DEFAULT_FREE_PAYMENT_LABEL: LocalizedText = {
|
||||
zh: '直接获取',
|
||||
en: 'Direct Claim',
|
||||
};
|
||||
|
||||
const MAX_FREE_PAYMENT_LABEL_LENGTH = 64;
|
||||
const freePaymentLabelsByStore = new WeakMap<object, LocalizedText>();
|
||||
|
||||
/** Associate a configured free payment label with a StoreCatalogue instance. */
|
||||
export function bindStoreFreePaymentLabel(store: object, label: LocalizedText): void {
|
||||
freePaymentLabelsByStore.set(store, label);
|
||||
}
|
||||
|
||||
/** Return the configured free payment label for a StoreCatalogue instance, falling back to the default. */
|
||||
export function freePaymentLabelForStore(store: object): LocalizedText {
|
||||
return freePaymentLabelsByStore.get(store) ?? DEFAULT_FREE_PAYMENT_LABEL;
|
||||
}
|
||||
|
||||
export interface StoreTuning {
|
||||
/** Localized label for the no-GJN offline payment button in the game dialog, local store, and marketplace. */
|
||||
readonly freePaymentLabel: LocalizedText;
|
||||
readonly goldenEaglePacks: readonly GoldenEaglePack[];
|
||||
readonly silverLionPacks: readonly SilverLionPack[];
|
||||
readonly premiumForGoldenEagles: readonly PremiumTier[];
|
||||
@@ -53,6 +73,7 @@ export interface StoreTuning {
|
||||
}
|
||||
|
||||
export function readStoreTuning(file: TuningReader): StoreTuning {
|
||||
const freePaymentLabel = readFreePaymentLabel(file);
|
||||
const packs = file.object('vehiclePacks');
|
||||
const byRank = packs.list('byRank', (entry) => ({ upToRank: entry.int('upToRank', { min: 1 }), ...packContent(entry) }))
|
||||
.sort((a, b) => a.upToRank - b.upToRank);
|
||||
@@ -66,6 +87,7 @@ export function readStoreTuning(file: TuningReader): StoreTuning {
|
||||
|
||||
validateStoreUniqueness(goldenEaglePacks, silverLionPacks, premiumForGoldenEagles, premiumForGjn, multiVehiclePacks);
|
||||
return {
|
||||
freePaymentLabel,
|
||||
goldenEaglePacks,
|
||||
silverLionPacks,
|
||||
premiumForGoldenEagles,
|
||||
@@ -76,6 +98,27 @@ export function readStoreTuning(file: TuningReader): StoreTuning {
|
||||
};
|
||||
}
|
||||
|
||||
function readFreePaymentLabel(file: TuningReader): LocalizedText {
|
||||
const labelObj = file.object('freePaymentLabel');
|
||||
return {
|
||||
zh: readFreePaymentLabelPart(labelObj, 'zh'),
|
||||
en: readFreePaymentLabelPart(labelObj, 'en'),
|
||||
};
|
||||
}
|
||||
|
||||
function readFreePaymentLabelPart(entry: TuningReader, key: 'zh' | 'en'): string {
|
||||
const trimmed = entry.string(key).trim();
|
||||
if (trimmed === '') {
|
||||
throw new TuningError(`tuning file store.jsonc: freePaymentLabel.${key} must not be blank`);
|
||||
}
|
||||
if (trimmed.length > MAX_FREE_PAYMENT_LABEL_LENGTH) {
|
||||
throw new TuningError(
|
||||
`tuning file store.jsonc: freePaymentLabel.${key} must be at most ${MAX_FREE_PAYMENT_LABEL_LENGTH} characters`,
|
||||
);
|
||||
}
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
/** The pack content for a vehicle: its own entry over the first rank tier that covers its rank (the last tier above the highest). */
|
||||
export function vehiclePackContent(tuning: StoreTuning, vehicle: string, rank: number): VehiclePackContent {
|
||||
const tier = tuning.vehiclePacksByRank.find((entry) => rank <= entry.upToRank) ?? tuning.vehiclePacksByRank[tuning.vehiclePacksByRank.length - 1]!;
|
||||
|
||||
@@ -20,6 +20,7 @@ import { describeRedeemCodes, gjnText, redeemStoreCode, type RedeemOutcome } fro
|
||||
import type { RedeemTuning } from './redeem-tuning.ts';
|
||||
import type { StoreCatalogue, StoreProduct } from './store-catalogue.ts';
|
||||
import { buyFreeStoreProduct, buyGjnProduct, buyStoreCart, canBuyGjnProduct, type GjnPurchaseOutcome, type StoreCheckoutOutcome } from './store-purchase.ts';
|
||||
import { freePaymentLabelForStore } from './store-tuning.ts';
|
||||
|
||||
const NO_ACCOUNT: LocalizedText = { zh: '没有找到这个账号,请先在右上角选择账号。', en: 'Account not found. Pick an account at the top right first.' };
|
||||
|
||||
@@ -31,12 +32,20 @@ export class StoreWebApi {
|
||||
readonly #profiles: PlayerProfiles;
|
||||
readonly #catalogue: StoreCatalogue;
|
||||
readonly #redeemCodes: RedeemTuning;
|
||||
readonly #freePaymentLabel: LocalizedText;
|
||||
|
||||
constructor(accounts: AccountStore, profiles: PlayerProfiles, catalogue: StoreCatalogue, redeemCodes: RedeemTuning) {
|
||||
constructor(
|
||||
accounts: AccountStore,
|
||||
profiles: PlayerProfiles,
|
||||
catalogue: StoreCatalogue,
|
||||
redeemCodes: RedeemTuning,
|
||||
freePaymentLabel?: LocalizedText,
|
||||
) {
|
||||
this.#accounts = accounts;
|
||||
this.#profiles = profiles;
|
||||
this.#catalogue = catalogue;
|
||||
this.#redeemCodes = redeemCodes;
|
||||
this.#freePaymentLabel = freePaymentLabel ?? freePaymentLabelForStore(catalogue);
|
||||
}
|
||||
|
||||
/** The answer for /store/api/<name>, or undefined when it is not an API request. */
|
||||
@@ -64,6 +73,7 @@ export class StoreWebApi {
|
||||
products,
|
||||
cartProductIds: profile ? storeCartIds(profile) : [],
|
||||
redeemHelp: describeRedeemCodes(this.#redeemCodes),
|
||||
freePaymentLabel: this.#freePaymentLabel,
|
||||
}, `store web state (${account?.userId ?? 'no account'})`);
|
||||
}
|
||||
|
||||
@@ -94,7 +104,10 @@ export class StoreWebApi {
|
||||
return true;
|
||||
});
|
||||
const modeTag = isFree ? 'free' : 'gjn';
|
||||
return jsonResponse({ ok: outcome.ok, cartProductIds, message: purchaseMessage(outcome, product, isFree) }, `store web buy ${product.id} (${modeTag}): ${outcome.ok ? 'OK' : outcome.reason}`);
|
||||
return jsonResponse(
|
||||
{ ok: outcome.ok, cartProductIds, message: purchaseMessage(outcome, product, isFree, this.#freePaymentLabel) },
|
||||
`store web buy ${product.id} (${modeTag}): ${outcome.ok ? 'OK' : outcome.reason}`,
|
||||
);
|
||||
}
|
||||
|
||||
#cart(request: ServiceRequest): ServiceResponse {
|
||||
@@ -153,7 +166,7 @@ export class StoreWebApi {
|
||||
return false;
|
||||
}
|
||||
const outcome = buyStoreCart(profile, products, payMethod, now);
|
||||
message = checkoutMessage(outcome, products, payMethod);
|
||||
message = checkoutMessage(outcome, products, payMethod, this.#freePaymentLabel);
|
||||
if (!outcome.ok) return false;
|
||||
clearStoreCart(profile);
|
||||
cartProductIds = [];
|
||||
@@ -177,13 +190,18 @@ export class StoreWebApi {
|
||||
}
|
||||
}
|
||||
|
||||
function purchaseMessage(outcome: GjnPurchaseOutcome, product: StoreProduct, isFree: boolean): LocalizedText {
|
||||
function purchaseMessage(
|
||||
outcome: GjnPurchaseOutcome,
|
||||
product: StoreProduct,
|
||||
isFree: boolean,
|
||||
freePaymentLabel: LocalizedText,
|
||||
): LocalizedText {
|
||||
const cost = gjnText(product.gjnCostCents ?? 0);
|
||||
if (outcome.ok) {
|
||||
return isFree
|
||||
? {
|
||||
zh: `老福爷付过了!已直接获得「${product.title.zh}」。关闭商店窗口后机库会自动刷新。`,
|
||||
en: `Paid by 老福爷! Claimed "${product.title.en}". Close the store window to refresh the hangar.`,
|
||||
zh: `已通过「${freePaymentLabel.zh}」获得「${product.title.zh}」。关闭商店窗口后机库会自动刷新。`,
|
||||
en: `Claimed "${product.title.en}" via "${freePaymentLabel.en}". Close the store window to refresh the hangar.`,
|
||||
}
|
||||
: {
|
||||
zh: `已购买「${product.title.zh}」,花费 ${cost} GJN。关闭商店窗口后机库会自动刷新。`,
|
||||
@@ -191,7 +209,10 @@ function purchaseMessage(outcome: GjnPurchaseOutcome, product: StoreProduct, isF
|
||||
};
|
||||
}
|
||||
if (outcome.reason === 'NOT_ENOUGH_GJN') {
|
||||
return { zh: `GJN 不够:需要 ${cost} GJN。可直接点「老福爷付过了」,或在"兑换码"页用 GJN 充值码补充。`, en: `Not enough GJN: ${cost} GJN needed. Use "老福爷付过了" or a GJN code on the Redeem tab.` };
|
||||
return {
|
||||
zh: `GJN 不够:需要 ${cost} GJN。可直接点「${freePaymentLabel.zh}」,或在"兑换码"页用 GJN 充值码补充。`,
|
||||
en: `Not enough GJN: ${cost} GJN needed. Use "${freePaymentLabel.en}" or a GJN code on the Redeem tab.`,
|
||||
};
|
||||
}
|
||||
if (outcome.reason === 'ALREADY_BOUGHT') return alreadyBoughtMessage(product);
|
||||
return { zh: '这个商品现在买不了。', en: 'This product cannot be bought right now.' };
|
||||
@@ -208,19 +229,23 @@ function checkoutMessage(
|
||||
outcome: StoreCheckoutOutcome,
|
||||
products: readonly StoreProduct[],
|
||||
payMethod: 'gjn' | 'free',
|
||||
freePaymentLabel: LocalizedText,
|
||||
): LocalizedText {
|
||||
if (outcome.ok) {
|
||||
const count = products.length;
|
||||
const cost = gjnText(outcome.costCents);
|
||||
return payMethod === 'free'
|
||||
? { zh: `老福爷付过了!已领取 ${count} 件商品。关闭商城窗口后机库会自动刷新。`,
|
||||
en: `Paid by 老福爷! Claimed ${count} items. Close the store to refresh the hangar.` }
|
||||
? { zh: `已通过「${freePaymentLabel.zh}」领取 ${count} 件商品。关闭商城窗口后机库会自动刷新。`,
|
||||
en: `Claimed ${count} items via "${freePaymentLabel.en}". Close the store to refresh the hangar.` }
|
||||
: { zh: `已购买 ${count} 件商品,花费 ${cost} GJN。关闭商城窗口后机库会自动刷新。`,
|
||||
en: `Bought ${count} items for ${cost} GJN. Close the store to refresh the hangar.` };
|
||||
}
|
||||
if (outcome.reason === 'NOT_ENOUGH_GJN') {
|
||||
const cost = gjnText(outcome.costCents);
|
||||
return { zh: `购物车共需 ${cost} GJN,当前余额不足。`, en: `Your cart costs ${cost} GJN. Your balance is too low.` };
|
||||
return {
|
||||
zh: `购物车共需 ${cost} GJN,当前余额不足。可直接点「${freePaymentLabel.zh}」。`,
|
||||
en: `Your cart costs ${cost} GJN. Your balance is too low. Use "${freePaymentLabel.en}" instead.`,
|
||||
};
|
||||
}
|
||||
const product = products.find((item) => item.id === outcome.productId);
|
||||
return outcome.reason === 'ALREADY_BOUGHT' && product ? alreadyBoughtMessage(product) : NO_PRODUCT;
|
||||
|
||||
@@ -9,7 +9,7 @@ const T = {
|
||||
search: '搜索礼包或载具', allCountries: '所有国家', allRanks: '所有等级', rank: '{rank} 级',
|
||||
sort: '商品排序', sortBest: '最畅销', sortNewest: '最新上架', sortPriceAsc: '价格从低到高', sortPriceDesc: '价格从高到低',
|
||||
containsEagles: '{n} 金鹰', containsSilver: '{n} 银狮', containsPremium: '{days} 天高级账户',
|
||||
buy: '购买', freeBuy: '老福爷付过了', owned: '已拥有', pickAccount: '请先选择账号',
|
||||
buy: '购买', freeBuy: '直接获取', owned: '已拥有', pickAccount: '请先选择账号',
|
||||
redeem: '兑换', codePlaceholder: '输入兑换码', empty: '没有符合条件的商品',
|
||||
featured: '推荐礼包', bestSeller: '畅销', viewPack: '查看礼包', related: '更多推荐', packPrice: '礼包价格',
|
||||
includes: '礼包内容', back: '返回目录', bonusTitle: '高级载具权益',
|
||||
@@ -31,7 +31,7 @@ const T = {
|
||||
search: 'Search packs or vehicles', allCountries: 'All nations', allRanks: 'All ranks', rank: 'Rank {rank}',
|
||||
sort: 'Sort products', sortBest: 'Top sellers', sortNewest: 'Newest', sortPriceAsc: 'Price: low to high', sortPriceDesc: 'Price: high to low',
|
||||
containsEagles: '{n} Golden Eagles', containsSilver: '{n} Silver Lions', containsPremium: '{days} days of Premium Account',
|
||||
buy: 'Buy', freeBuy: '老福爷付过了', owned: 'Owned', pickAccount: 'Pick an account first',
|
||||
buy: 'Buy', freeBuy: 'Direct Claim', owned: 'Owned', pickAccount: 'Pick an account first',
|
||||
redeem: 'Redeem', codePlaceholder: 'Enter a code', empty: 'Nothing matches the filters',
|
||||
featured: 'Featured packs', bestSeller: 'Top seller', viewPack: 'View pack', related: 'Explore other packs', packPrice: 'Pack price',
|
||||
includes: 'Pack contents', back: 'Back to catalog', bonusTitle: 'Premium bonuses',
|
||||
@@ -53,7 +53,7 @@ const t = (key, params) => WtoUi.tr(T, key, params);
|
||||
const $ = (id) => document.getElementById(id);
|
||||
|
||||
let initialGuid = (WtoUi.query.get('item') || '').toUpperCase();
|
||||
let state = { accounts: [], activeUserId: '', balance: { gjnCents: 0 }, products: [], cartProductIds: [], redeemHelp: [] };
|
||||
let state = { accounts: [], activeUserId: '', balance: { gjnCents: 0 }, products: [], cartProductIds: [], redeemHelp: [], freePaymentLabel: null };
|
||||
let currentTab = 'vehicle-pack';
|
||||
let detailId = '';
|
||||
let catalogScroll = 0;
|
||||
@@ -61,9 +61,14 @@ let loadVersion = 0;
|
||||
let loading = true;
|
||||
const checkout = createStoreCheckout(loadState);
|
||||
|
||||
function freePaymentLabel() {
|
||||
return WtoUi.text(state.freePaymentLabel) || t('freeBuy');
|
||||
}
|
||||
|
||||
function applyStaticTexts() {
|
||||
for (const el of document.querySelectorAll('[data-t]')) el.textContent = t(el.dataset.t);
|
||||
for (const el of document.querySelectorAll('[data-label]')) el.setAttribute('aria-label', t(el.dataset.label));
|
||||
$('payFree').textContent = freePaymentLabel();
|
||||
$('searchInput').placeholder = t('search');
|
||||
$('codeInput').placeholder = t('codePlaceholder');
|
||||
$('marketLink').href = WtoUi.pageLink('/trade.gaijin.net/');
|
||||
@@ -88,6 +93,7 @@ async function loadState(userId) {
|
||||
return await loadState('');
|
||||
}
|
||||
state = next;
|
||||
$('payFree').textContent = freePaymentLabel();
|
||||
WtoUi.fillAccountSelect($('accountSelect'), state.accounts, state.activeUserId);
|
||||
$('gjnVal').textContent = WtoUi.gjn(state.balance.gjnCents);
|
||||
$('goldVal').textContent = WtoUi.num(state.balance.goldenEagles);
|
||||
|
||||
Reference in new issue
Block a user