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
@@ -0,0 +1,15 @@
import { describe, expect, it } from "vitest";
import { buildPendingPaymentSubscriptionUrl } from "../pending_payment_order";
describe("pending payment order helpers", () => {
it("keeps the pay channel when rebuilding subscription return urls", () => {
expect(
buildPendingPaymentSubscriptionUrl({
payChannel: "ezpay",
returnTo: "chat",
subscriptionType: "topup",
}),
).toBe("/subscription?type=topup&payChannel=ezpay&paymentReturn=1&returnTo=chat");
});
});
+7
View File
@@ -0,0 +1,7 @@
import type { PayChannel } from "@/data/dto/payment";
export function getDefaultPayChannelForCountryCode(
countryCode: string | null | undefined,
): PayChannel {
return countryCode?.trim().toUpperCase() === "PH" ? "ezpay" : "stripe";
}
+5 -1
View File
@@ -43,10 +43,14 @@ export function clearPendingPaymentOrder(): Promise<Result<void>> {
}
export function buildPendingPaymentSubscriptionUrl(
order: Pick<PendingPaymentOrder, "subscriptionType" | "returnTo">,
order: Pick<
PendingPaymentOrder,
"payChannel" | "returnTo" | "subscriptionType"
>,
): string {
const params = new URLSearchParams({
type: order.subscriptionType,
payChannel: order.payChannel,
paymentReturn: "1",
});
if (order.returnTo) params.set("returnTo", order.returnTo);