fix(subscription): restrict payment methods by country

This commit is contained in:
2026-07-02 15:00:06 +08:00
parent 3032f28d64
commit 515fdcaa56
5 changed files with 116 additions and 20 deletions
@@ -3,10 +3,12 @@ import { describe, expect, it } from "vitest";
import { PaymentPlan } from "@/data/dto/payment";
import {
canChooseSubscriptionPayChannel,
findSelectedSubscriptionPlan,
getDefaultPayChannelForCountryCode,
getDefaultSubscriptionPlanId,
getFirstRechargeOfferView,
resolveSubscriptionPayChannel,
toCoinsOfferPlanViews,
toVipOfferPlanViews,
} from "../subscription-screen.helpers";
@@ -38,6 +40,34 @@ describe("subscription screen helpers", () => {
expect(getDefaultPayChannelForCountryCode(null)).toBe("stripe");
});
it("only allows payment method switching for Philippines users", () => {
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", () => {
expect(
resolveSubscriptionPayChannel({
countryCode: "PH",
requestedPayChannel: null,
}),
).toBe("ezpay");
expect(
resolveSubscriptionPayChannel({
countryCode: "PH",
requestedPayChannel: "stripe",
}),
).toBe("stripe");
expect(
resolveSubscriptionPayChannel({
countryCode: "HK",
requestedPayChannel: "ezpay",
}),
).toBe("stripe");
});
it("maps at most three VIP plans and all coin plans", () => {
const plans = [
makePlan({ planId: "vip_monthly", planName: "Monthly" }),