fix(subscription): preselect pay channel before navigation

This commit is contained in:
2026-07-02 11:38:47 +08:00
parent 35c8de917d
commit cd25fa35f2
15 changed files with 121 additions and 56 deletions
+12 -4
View File
@@ -1,6 +1,7 @@
"use client";
import type { LoginStatus } from "@/data/dto/auth";
import type { PayChannel } from "@/data/dto/payment";
import { ROUTE_BUILDERS } from "@/router/routes";
import { AppEnvUtil, BrowserDetector } from "@/utils";
@@ -30,14 +31,20 @@ export function shouldStartExternalBrowserPrompt({
);
}
export function getChatPaywallSubscriptionUrl(): string {
export function getChatPaywallSubscriptionUrl(
payChannel: PayChannel = "stripe",
): string {
return ROUTE_BUILDERS.subscription("vip", {
payChannel,
returnTo: "chat",
});
}
export function getChatCreditsTopUpSubscriptionUrl(): string {
export function getChatCreditsTopUpSubscriptionUrl(
payChannel: PayChannel = "stripe",
): string {
return ROUTE_BUILDERS.subscription("topup", {
payChannel,
returnTo: "chat",
});
}
@@ -51,11 +58,12 @@ export function getInsufficientCreditsSubscriptionType(
export function getChatPaywallNavigationUrl(
loginStatus: LoginStatus,
type: "vip" | "topup" = "vip",
payChannel: PayChannel = "stripe",
): string {
const subscriptionUrl =
type === "topup"
? getChatCreditsTopUpSubscriptionUrl()
: getChatPaywallSubscriptionUrl();
? getChatCreditsTopUpSubscriptionUrl(payChannel)
: getChatPaywallSubscriptionUrl(payChannel);
if (deriveIsGuest(loginStatus)) {
return ROUTE_BUILDERS.authWithRedirect(subscriptionUrl);
}
+5
View File
@@ -13,6 +13,7 @@ import {
recordExternalBrowserPromptShown,
resolveExternalBrowserPromptEligibility,
} from "@/lib/chat/chat_external_browser";
import { getDefaultPayChannelForCountryCode } from "@/lib/payment/default_pay_channel";
import { MobileShell } from "@/app/_components/core";
@@ -115,10 +116,14 @@ export function ChatScreen() {
}
function handleMessageLimitUnlock(): void {
const defaultPayChannel = getDefaultPayChannelForCountryCode(
userState.currentUser?.countryCode,
);
router.push(
getChatPaywallNavigationUrl(
authState.loginStatus,
getInsufficientCreditsSubscriptionType(userState.isVip),
defaultPayChannel,
),
);
}
@@ -15,6 +15,7 @@ import {
type PendingChatUnlock,
type PendingChatUnlockKind,
} from "@/lib/navigation/chat_unlock_session";
import { getDefaultPayChannelForCountryCode } from "@/lib/payment/default_pay_channel";
import { getInsufficientCreditsSubscriptionType } from "../chat-screen.helpers";
@@ -135,10 +136,13 @@ export function useChatUnlockNavigationFlow({
stage: "payment",
});
chatDispatch({ type: "ChatUnlockPaywallNavigationConsumed" });
const defaultPayChannel = getDefaultPayChannelForCountryCode(
userState.currentUser?.countryCode,
);
router.push(
ROUTE_BUILDERS.subscription(
getInsufficientCreditsSubscriptionType(userState.isVip),
{ returnTo: "chat" },
{ payChannel: defaultPayChannel, returnTo: "chat" },
),
);
})();