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:
N0VAN0M4LY committed 2026-12-04 19:55:04 +08:00
1 parent 429c5eec12
commit 12a573a333
10 files changed
+154 -29

No files matched your search

+35 -10
View File
@@ -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;