fix: apply telegram group member monthly price

This commit is contained in:
2569718930@qq.com
2026-06-02 21:35:35 +08:00
parent 876417c5ec
commit 137b0d8b3a
7 changed files with 101 additions and 9 deletions
@@ -23,6 +23,10 @@ export function runTests() {
path.join(projectRoot, "components", "account", "usePaymentFlow.ts"),
"utf8",
);
const useBilling = fs.readFileSync(
path.join(projectRoot, "components", "account", "useBilling.ts"),
"utf8",
);
const types = fs.readFileSync(
path.join(projectRoot, "components", "account", "types.ts"),
"utf8",
@@ -59,6 +63,19 @@ export function runTests() {
!usePaymentFlow.includes("monthlyPlanList"),
"payment hooks must not filter checkout plans down to monthly only",
);
assert(
useAccountPayment.includes("applyTelegramGroupPricingToPlanList") &&
useAccountPayment.includes("backend?.telegram_pricing") &&
useAccountPayment.includes('=== "pro_monthly"') &&
useAccountPayment.includes("amount_usdc: telegramAmountUsdc"),
"account payment plan cards must display the 5 USDC Telegram group member monthly price after /bind verification",
);
assert(
useBilling.includes("telegramGroupPriceApplies") &&
useBilling.includes("backend?.telegram_pricing?.is_group_member") &&
useBilling.includes("!telegramGroupPriceApplies"),
"billing must not let referral first-month pricing override the lower Telegram group member monthly price",
);
assert(
types.includes("ReferralSummary") &&
types.includes("referral?: ReferralSummary | null") &&
+2 -2
View File
@@ -271,8 +271,8 @@ export function createAccountCopy(isEn: boolean): Record<string, string> {
verifyUnknown: isEn ? "Unknown error" : "未知错误",
// ── Telegram bind messages ────────────────────────────────────────
telegramVerifySuccess: isEn
? "Telegram group membership verified. Checkout follows the selected Pro plan."
: "Telegram 群成员验证成功,结算金额以当前选择的 Pro 套餐为准。",
? "Telegram group membership verified. Member monthly price {amount} USDC is active."
: "Telegram 群成员验证成功,群友月付价 {amount} USDC 已生效。",
telegramBindClickHint: isEn
? "Open the Telegram Bot, click Start, and confirm binding. Then refresh this page to request group entry."
: "已打开 Telegram Bot,请在 Bot 内点击 Start 并确认绑定;完成后刷新本页再申请入群。",
@@ -13,14 +13,37 @@ import type {
AuthMeResponse,
BoundWallet,
PaymentConfig,
PaymentPlan,
ProviderMode,
InjectedProviderOption,
TelegramPricing,
} from "./types";
import { usePaymentState } from "./usePaymentState";
import { useWalletBind } from "./useWalletBind";
import { usePaymentFlow } from "./usePaymentFlow";
import { useBilling } from "./useBilling";
// ============================================================
function telegramMemberAmountUsdc(pricing?: TelegramPricing | null) {
if (!pricing?.is_group_member) return "";
const amount = String(pricing.amount_usdc || "").trim();
const numeric = Number(amount);
return Number.isFinite(numeric) && numeric > 0 ? amount : "";
}
function applyTelegramGroupPricingToPlanList(
plans: PaymentPlan[],
pricing?: TelegramPricing | null,
): PaymentPlan[] {
const telegramAmountUsdc = telegramMemberAmountUsdc(pricing);
if (!telegramAmountUsdc) return plans;
return plans.map((plan) =>
String(plan.plan_code || "").toLowerCase() === "pro_monthly"
? { ...plan, amount_usdc: telegramAmountUsdc }
: plan,
);
}
// ============================================================
export interface UseAccountPaymentParams {
isEn: boolean;
@@ -387,7 +410,10 @@ export function useAccountPayment(params: UseAccountPaymentParams) {
]);
// ── Selected plan (derived, shared across sub-hooks) ───
const effectivePlanList = paymentConfig?.plans || [];
const effectivePlanList = applyTelegramGroupPricingToPlanList(
paymentConfig?.plans || [],
backend?.telegram_pricing,
);
const selectedPlan = effectivePlanList.find((p) => p.plan_code === selectedPlanCode) || effectivePlanList[0];
// ── useWalletBind ──────────────────────────────────────
@@ -122,6 +122,10 @@ export function useBilling(params: UseBillingParams) {
const listAmount =
Number.isFinite(listAmountRaw) && listAmountRaw > 0 ? listAmountRaw : 29.9;
const selectedPlanCode = String(selectedPlan?.plan_code || "").toLowerCase();
const telegramGroupPriceApplies = Boolean(
selectedPlanCode === "pro_monthly" &&
backend?.telegram_pricing?.is_group_member,
);
const referral = backend?.referral;
const referralPending = Boolean(
referral?.applied_code ||
@@ -137,6 +141,7 @@ export function useBilling(params: UseBillingParams) {
const referralApplies =
selectedPlanCode === "pro_monthly" &&
referralPending &&
!telegramGroupPriceApplies &&
backend?.subscription_active !== true;
const planAmount = referralApplies
? Number.isFinite(discountedMonthlyRaw) && discountedMonthlyRaw > 0
@@ -187,6 +192,7 @@ export function useBilling(params: UseBillingParams) {
paymentConfig?.points_redemption,
backend?.referral,
backend?.subscription_active,
backend?.telegram_pricing?.is_group_member,
selectedPlan?.plan_code,
selectedPlan?.amount_usdc,
totalPoints,