fix(payment): show selector only for Philippines

This commit is contained in:
2026-07-20 16:23:18 +08:00
parent 9920f97029
commit f44db8d8b2
5 changed files with 54 additions and 7 deletions
@@ -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);
});
});
+9 -1
View File
@@ -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";
}