From ab9b227969f27144655331cf2079197e1c59fa21 Mon Sep 17 00:00:00 2001 From: chenhang Date: Tue, 7 Jul 2026 15:43:06 +0800 Subject: [PATCH] fix(subscription): show payment methods outside production --- .../subscription-screen.helpers.test.ts | 32 +++++++++++++++++-- .../subscription-screen.helpers.ts | 2 ++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/app/subscription/__tests__/subscription-screen.helpers.test.ts b/src/app/subscription/__tests__/subscription-screen.helpers.test.ts index 9e28537a..7cc8749a 100644 --- a/src/app/subscription/__tests__/subscription-screen.helpers.test.ts +++ b/src/app/subscription/__tests__/subscription-screen.helpers.test.ts @@ -1,4 +1,4 @@ -import { describe, expect, it } from "vitest"; +import { afterEach, describe, expect, it, vi } from "vitest"; import { PaymentPlan } from "@/data/dto/payment"; @@ -32,6 +32,10 @@ function makePlan( } describe("subscription screen helpers", () => { + afterEach(() => { + vi.unstubAllEnvs(); + }); + it("defaults Philippines users to Ezpay and other countries to Stripe", () => { expect(getDefaultPayChannelForCountryCode("PH")).toBe("ezpay"); expect(getDefaultPayChannelForCountryCode("ph")).toBe("ezpay"); @@ -40,14 +44,25 @@ describe("subscription screen helpers", () => { 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("HK")).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( resolveSubscriptionPayChannel({ countryCode: "PH", @@ -68,6 +83,17 @@ describe("subscription screen helpers", () => { ).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", () => { const plans = [ makePlan({ planId: "vip_monthly", planName: "Monthly" }), diff --git a/src/app/subscription/subscription-screen.helpers.ts b/src/app/subscription/subscription-screen.helpers.ts index cae8ce20..a770a8cd 100644 --- a/src/app/subscription/subscription-screen.helpers.ts +++ b/src/app/subscription/subscription-screen.helpers.ts @@ -1,5 +1,6 @@ import type { PayChannel, PaymentPlan } from "@/data/dto/payment"; import { getDefaultPayChannelForCountryCode } from "@/lib/payment/default_pay_channel"; +import { AppEnvUtil } from "@/utils/app-env"; export { getDefaultPayChannelForCountryCode } from "@/lib/payment/default_pay_channel"; import type { CoinsOfferPlanView } from "./components/subscription-coins-offer-section"; @@ -16,6 +17,7 @@ export interface FirstRechargeOfferView { export function canChooseSubscriptionPayChannel( countryCode: string | null | undefined, ): boolean { + if (!AppEnvUtil.isProduction()) return true; return countryCode?.trim().toUpperCase() === "PH"; }