fix(payment): show selector only for Philippines
This commit is contained in:
@@ -10,6 +10,7 @@ describe("PaymentMethodSelector", () => {
|
|||||||
config={{
|
config={{
|
||||||
canChoosePaymentMethod: true,
|
canChoosePaymentMethod: true,
|
||||||
initialPayChannel: "ezpay",
|
initialPayChannel: "ezpay",
|
||||||
|
showPaymentMethodSelector: true,
|
||||||
}}
|
}}
|
||||||
value="ezpay"
|
value="ezpay"
|
||||||
caption="GCash by default"
|
caption="GCash by default"
|
||||||
@@ -46,6 +47,7 @@ describe("PaymentMethodSelector", () => {
|
|||||||
config={{
|
config={{
|
||||||
canChoosePaymentMethod: true,
|
canChoosePaymentMethod: true,
|
||||||
initialPayChannel: "stripe",
|
initialPayChannel: "stripe",
|
||||||
|
showPaymentMethodSelector: true,
|
||||||
}}
|
}}
|
||||||
value="stripe"
|
value="stripe"
|
||||||
disabled
|
disabled
|
||||||
@@ -64,8 +66,9 @@ describe("PaymentMethodSelector", () => {
|
|||||||
const html = renderToStaticMarkup(
|
const html = renderToStaticMarkup(
|
||||||
<PaymentMethodSelector
|
<PaymentMethodSelector
|
||||||
config={{
|
config={{
|
||||||
canChoosePaymentMethod: false,
|
canChoosePaymentMethod: true,
|
||||||
initialPayChannel: "stripe",
|
initialPayChannel: "stripe",
|
||||||
|
showPaymentMethodSelector: false,
|
||||||
}}
|
}}
|
||||||
value="stripe"
|
value="stripe"
|
||||||
analyticsKey="tip.payment_method"
|
analyticsKey="tip.payment_method"
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export function PaymentMethodSelector({
|
|||||||
analyticsKey,
|
analyticsKey,
|
||||||
onChange,
|
onChange,
|
||||||
}: PaymentMethodSelectorProps) {
|
}: PaymentMethodSelectorProps) {
|
||||||
if (!config.canChoosePaymentMethod) return null;
|
if (!config.showPaymentMethodSelector) return null;
|
||||||
|
|
||||||
const paymentMethods =
|
const paymentMethods =
|
||||||
config.initialPayChannel === "ezpay"
|
config.initialPayChannel === "ezpay"
|
||||||
|
|||||||
@@ -27,7 +27,11 @@ describe("usePaymentMethodSelection", () => {
|
|||||||
it("forces Stripe when payment method selection is unavailable", () => {
|
it("forces Stripe when payment method selection is unavailable", () => {
|
||||||
const onChange = vi.fn();
|
const onChange = vi.fn();
|
||||||
renderHarness(root, {
|
renderHarness(root, {
|
||||||
config: { canChoosePaymentMethod: false, initialPayChannel: "stripe" },
|
config: {
|
||||||
|
canChoosePaymentMethod: false,
|
||||||
|
initialPayChannel: "stripe",
|
||||||
|
showPaymentMethodSelector: false,
|
||||||
|
},
|
||||||
currentPayChannel: "ezpay",
|
currentPayChannel: "ezpay",
|
||||||
onChange,
|
onChange,
|
||||||
});
|
});
|
||||||
@@ -40,6 +44,7 @@ describe("usePaymentMethodSelection", () => {
|
|||||||
const config = {
|
const config = {
|
||||||
canChoosePaymentMethod: true,
|
canChoosePaymentMethod: true,
|
||||||
initialPayChannel: "ezpay",
|
initialPayChannel: "ezpay",
|
||||||
|
showPaymentMethodSelector: true,
|
||||||
} as const;
|
} as const;
|
||||||
renderHarness(root, {
|
renderHarness(root, {
|
||||||
config,
|
config,
|
||||||
@@ -59,13 +64,21 @@ describe("usePaymentMethodSelection", () => {
|
|||||||
it("preserves an explicit return channel and pauses while payment is busy", () => {
|
it("preserves an explicit return channel and pauses while payment is busy", () => {
|
||||||
const onChange = vi.fn();
|
const onChange = vi.fn();
|
||||||
renderHarness(root, {
|
renderHarness(root, {
|
||||||
config: { canChoosePaymentMethod: true, initialPayChannel: "ezpay" },
|
config: {
|
||||||
|
canChoosePaymentMethod: true,
|
||||||
|
initialPayChannel: "ezpay",
|
||||||
|
showPaymentMethodSelector: true,
|
||||||
|
},
|
||||||
currentPayChannel: "stripe",
|
currentPayChannel: "stripe",
|
||||||
requestedPayChannel: "stripe",
|
requestedPayChannel: "stripe",
|
||||||
onChange,
|
onChange,
|
||||||
});
|
});
|
||||||
renderHarness(root, {
|
renderHarness(root, {
|
||||||
config: { canChoosePaymentMethod: false, initialPayChannel: "stripe" },
|
config: {
|
||||||
|
canChoosePaymentMethod: false,
|
||||||
|
initialPayChannel: "stripe",
|
||||||
|
showPaymentMethodSelector: false,
|
||||||
|
},
|
||||||
currentPayChannel: "ezpay",
|
currentPayChannel: "ezpay",
|
||||||
isPaymentBusy: true,
|
isPaymentBusy: true,
|
||||||
onChange,
|
onChange,
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ describe("payment method rules", () => {
|
|||||||
).toEqual({
|
).toEqual({
|
||||||
canChoosePaymentMethod: false,
|
canChoosePaymentMethod: false,
|
||||||
initialPayChannel: "stripe",
|
initialPayChannel: "stripe",
|
||||||
|
showPaymentMethodSelector: false,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -51,7 +52,7 @@ describe("payment method rules", () => {
|
|||||||
).toBe("stripe");
|
).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");
|
vi.stubEnv("NEXT_PUBLIC_APP_ENV", "test");
|
||||||
|
|
||||||
expect(canChoosePayChannel(null)).toBe(true);
|
expect(canChoosePayChannel(null)).toBe(true);
|
||||||
@@ -61,5 +62,27 @@ describe("payment method rules", () => {
|
|||||||
requestedPayChannel: "ezpay",
|
requestedPayChannel: "ezpay",
|
||||||
}),
|
}),
|
||||||
).toBe("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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,13 +6,14 @@ import { getDefaultPayChannelForCountryCode } from "./default_pay_channel";
|
|||||||
export interface PaymentMethodConfig {
|
export interface PaymentMethodConfig {
|
||||||
canChoosePaymentMethod: boolean;
|
canChoosePaymentMethod: boolean;
|
||||||
initialPayChannel: PayChannel;
|
initialPayChannel: PayChannel;
|
||||||
|
showPaymentMethodSelector: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function canChoosePayChannel(
|
export function canChoosePayChannel(
|
||||||
countryCode: string | null | undefined,
|
countryCode: string | null | undefined,
|
||||||
): boolean {
|
): boolean {
|
||||||
if (!AppEnvUtil.isProduction()) return true;
|
if (!AppEnvUtil.isProduction()) return true;
|
||||||
return countryCode?.trim().toUpperCase() === "PH";
|
return isPhilippinesCountryCode(countryCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolvePayChannel(input: {
|
export function resolvePayChannel(input: {
|
||||||
@@ -33,5 +34,12 @@ export function getPaymentMethodConfig(input: {
|
|||||||
return {
|
return {
|
||||||
canChoosePaymentMethod: canChoosePayChannel(input.countryCode),
|
canChoosePaymentMethod: canChoosePayChannel(input.countryCode),
|
||||||
initialPayChannel: resolvePayChannel(input),
|
initialPayChannel: resolvePayChannel(input),
|
||||||
|
showPaymentMethodSelector: isPhilippinesCountryCode(input.countryCode),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isPhilippinesCountryCode(
|
||||||
|
countryCode: string | null | undefined,
|
||||||
|
): boolean {
|
||||||
|
return countryCode?.trim().toUpperCase() === "PH";
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user