From f44db8d8b21f7d9cc88359d173d5449eff5f46d0 Mon Sep 17 00:00:00 2001 From: chenhang Date: Mon, 20 Jul 2026 16:23:18 +0800 Subject: [PATCH] fix(payment): show selector only for Philippines --- .../payment-method-selector.test.tsx | 5 +++- .../payment/payment-method-selector.tsx | 2 +- .../use-payment-method-selection.test.tsx | 19 +++++++++++--- .../payment/__tests__/payment_method.test.ts | 25 ++++++++++++++++++- src/lib/payment/payment_method.ts | 10 +++++++- 5 files changed, 54 insertions(+), 7 deletions(-) diff --git a/src/app/_components/payment/__tests__/payment-method-selector.test.tsx b/src/app/_components/payment/__tests__/payment-method-selector.test.tsx index 4aa16944..49c8d895 100644 --- a/src/app/_components/payment/__tests__/payment-method-selector.test.tsx +++ b/src/app/_components/payment/__tests__/payment-method-selector.test.tsx @@ -10,6 +10,7 @@ describe("PaymentMethodSelector", () => { config={{ canChoosePaymentMethod: true, initialPayChannel: "ezpay", + showPaymentMethodSelector: true, }} value="ezpay" caption="GCash by default" @@ -46,6 +47,7 @@ describe("PaymentMethodSelector", () => { config={{ canChoosePaymentMethod: true, initialPayChannel: "stripe", + showPaymentMethodSelector: true, }} value="stripe" disabled @@ -64,8 +66,9 @@ describe("PaymentMethodSelector", () => { const html = renderToStaticMarkup( { it("forces Stripe when payment method selection is unavailable", () => { const onChange = vi.fn(); renderHarness(root, { - config: { canChoosePaymentMethod: false, initialPayChannel: "stripe" }, + config: { + canChoosePaymentMethod: false, + initialPayChannel: "stripe", + showPaymentMethodSelector: false, + }, currentPayChannel: "ezpay", onChange, }); @@ -40,6 +44,7 @@ describe("usePaymentMethodSelection", () => { const config = { canChoosePaymentMethod: true, initialPayChannel: "ezpay", + showPaymentMethodSelector: true, } as const; renderHarness(root, { config, @@ -59,13 +64,21 @@ describe("usePaymentMethodSelection", () => { it("preserves an explicit return channel and pauses while payment is busy", () => { const onChange = vi.fn(); renderHarness(root, { - config: { canChoosePaymentMethod: true, initialPayChannel: "ezpay" }, + config: { + canChoosePaymentMethod: true, + initialPayChannel: "ezpay", + showPaymentMethodSelector: true, + }, currentPayChannel: "stripe", requestedPayChannel: "stripe", onChange, }); renderHarness(root, { - config: { canChoosePaymentMethod: false, initialPayChannel: "stripe" }, + config: { + canChoosePaymentMethod: false, + initialPayChannel: "stripe", + showPaymentMethodSelector: false, + }, currentPayChannel: "ezpay", isPaymentBusy: true, onChange, diff --git a/src/lib/payment/__tests__/payment_method.test.ts b/src/lib/payment/__tests__/payment_method.test.ts index 136b1c98..f507a8ef 100644 --- a/src/lib/payment/__tests__/payment_method.test.ts +++ b/src/lib/payment/__tests__/payment_method.test.ts @@ -34,6 +34,7 @@ describe("payment method rules", () => { ).toEqual({ canChoosePaymentMethod: false, initialPayChannel: "stripe", + showPaymentMethodSelector: false, }); }); @@ -51,7 +52,7 @@ describe("payment method rules", () => { ).toBe("stripe"); }); - it("allows every user and keeps the requested channel outside production", () => { + it("keeps test channels but shows the selector only for Philippines", () => { vi.stubEnv("NEXT_PUBLIC_APP_ENV", "test"); expect(canChoosePayChannel(null)).toBe(true); @@ -61,5 +62,27 @@ describe("payment method rules", () => { requestedPayChannel: "ezpay", }), ).toBe("ezpay"); + expect( + getPaymentMethodConfig({ + countryCode: "HK", + requestedPayChannel: "ezpay", + }), + ).toEqual({ + canChoosePaymentMethod: true, + initialPayChannel: "ezpay", + showPaymentMethodSelector: false, + }); + expect( + getPaymentMethodConfig({ + countryCode: " ph ", + requestedPayChannel: null, + }).showPaymentMethodSelector, + ).toBe(true); + expect( + getPaymentMethodConfig({ + countryCode: undefined, + requestedPayChannel: null, + }).showPaymentMethodSelector, + ).toBe(false); }); }); diff --git a/src/lib/payment/payment_method.ts b/src/lib/payment/payment_method.ts index 74a2b8f9..3dba5018 100644 --- a/src/lib/payment/payment_method.ts +++ b/src/lib/payment/payment_method.ts @@ -6,13 +6,14 @@ import { getDefaultPayChannelForCountryCode } from "./default_pay_channel"; export interface PaymentMethodConfig { canChoosePaymentMethod: boolean; initialPayChannel: PayChannel; + showPaymentMethodSelector: boolean; } export function canChoosePayChannel( countryCode: string | null | undefined, ): boolean { if (!AppEnvUtil.isProduction()) return true; - return countryCode?.trim().toUpperCase() === "PH"; + return isPhilippinesCountryCode(countryCode); } export function resolvePayChannel(input: { @@ -33,5 +34,12 @@ export function getPaymentMethodConfig(input: { return { canChoosePaymentMethod: canChoosePayChannel(input.countryCode), initialPayChannel: resolvePayChannel(input), + showPaymentMethodSelector: isPhilippinesCountryCode(input.countryCode), }; } + +function isPhilippinesCountryCode( + countryCode: string | null | undefined, +): boolean { + return countryCode?.trim().toUpperCase() === "PH"; +}