fix(subscription): show payment methods outside production

This commit is contained in:
2026-07-07 15:43:06 +08:00
parent 9f5e1533fc
commit ab9b227969
2 changed files with 31 additions and 3 deletions
@@ -1,4 +1,4 @@
import { describe, expect, it } from "vitest"; import { afterEach, describe, expect, it, vi } from "vitest";
import { PaymentPlan } from "@/data/dto/payment"; import { PaymentPlan } from "@/data/dto/payment";
@@ -32,6 +32,10 @@ function makePlan(
} }
describe("subscription screen helpers", () => { describe("subscription screen helpers", () => {
afterEach(() => {
vi.unstubAllEnvs();
});
it("defaults Philippines users to Ezpay and other countries to Stripe", () => { it("defaults Philippines users to Ezpay and other countries to Stripe", () => {
expect(getDefaultPayChannelForCountryCode("PH")).toBe("ezpay"); expect(getDefaultPayChannelForCountryCode("PH")).toBe("ezpay");
expect(getDefaultPayChannelForCountryCode("ph")).toBe("ezpay"); expect(getDefaultPayChannelForCountryCode("ph")).toBe("ezpay");
@@ -40,14 +44,25 @@ describe("subscription screen helpers", () => {
expect(getDefaultPayChannelForCountryCode(null)).toBe("stripe"); expect(getDefaultPayChannelForCountryCode(null)).toBe("stripe");
}); });
it("only allows payment method switching for Philippines users", () => { it("only allows payment method switching for Philippines users in production", () => {
vi.stubEnv("NEXT_PUBLIC_APP_ENV", "production");
expect(canChooseSubscriptionPayChannel("PH")).toBe(true); expect(canChooseSubscriptionPayChannel("PH")).toBe(true);
expect(canChooseSubscriptionPayChannel("ph")).toBe(true); expect(canChooseSubscriptionPayChannel("ph")).toBe(true);
expect(canChooseSubscriptionPayChannel("HK")).toBe(false); expect(canChooseSubscriptionPayChannel("HK")).toBe(false);
expect(canChooseSubscriptionPayChannel(null)).toBe(false); expect(canChooseSubscriptionPayChannel(null)).toBe(false);
}); });
it("resolves subscription pay channel by country", () => { it("allows payment method switching in non-production", () => {
vi.stubEnv("NEXT_PUBLIC_APP_ENV", "test");
expect(canChooseSubscriptionPayChannel("HK")).toBe(true);
expect(canChooseSubscriptionPayChannel(null)).toBe(true);
});
it("resolves subscription pay channel by country in production", () => {
vi.stubEnv("NEXT_PUBLIC_APP_ENV", "production");
expect( expect(
resolveSubscriptionPayChannel({ resolveSubscriptionPayChannel({
countryCode: "PH", countryCode: "PH",
@@ -68,6 +83,17 @@ describe("subscription screen helpers", () => {
).toBe("stripe"); ).toBe("stripe");
}); });
it("keeps requested pay channel in non-production", () => {
vi.stubEnv("NEXT_PUBLIC_APP_ENV", "test");
expect(
resolveSubscriptionPayChannel({
countryCode: "HK",
requestedPayChannel: "ezpay",
}),
).toBe("ezpay");
});
it("maps at most three VIP plans and all coin plans", () => { it("maps at most three VIP plans and all coin plans", () => {
const plans = [ const plans = [
makePlan({ planId: "vip_monthly", planName: "Monthly" }), makePlan({ planId: "vip_monthly", planName: "Monthly" }),
@@ -1,5 +1,6 @@
import type { PayChannel, PaymentPlan } from "@/data/dto/payment"; import type { PayChannel, PaymentPlan } from "@/data/dto/payment";
import { getDefaultPayChannelForCountryCode } from "@/lib/payment/default_pay_channel"; import { getDefaultPayChannelForCountryCode } from "@/lib/payment/default_pay_channel";
import { AppEnvUtil } from "@/utils/app-env";
export { getDefaultPayChannelForCountryCode } from "@/lib/payment/default_pay_channel"; export { getDefaultPayChannelForCountryCode } from "@/lib/payment/default_pay_channel";
import type { CoinsOfferPlanView } from "./components/subscription-coins-offer-section"; import type { CoinsOfferPlanView } from "./components/subscription-coins-offer-section";
@@ -16,6 +17,7 @@ export interface FirstRechargeOfferView {
export function canChooseSubscriptionPayChannel( export function canChooseSubscriptionPayChannel(
countryCode: string | null | undefined, countryCode: string | null | undefined,
): boolean { ): boolean {
if (!AppEnvUtil.isProduction()) return true;
return countryCode?.trim().toUpperCase() === "PH"; return countryCode?.trim().toUpperCase() === "PH";
} }