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
@@ -1,4 +1,5 @@
import type { PaymentPlan } from "@/data/dto/payment";
import type { PayChannel, PaymentPlan } from "@/data/dto/payment";
import { getDefaultPayChannelForCountryCode } from "@/lib/payment/default_pay_channel";
export { getDefaultPayChannelForCountryCode } from "@/lib/payment/default_pay_channel";
import type { CoinsOfferPlanView } from "./components/subscription-coins-offer-section";
@@ -12,6 +13,23 @@ export interface FirstRechargeOfferView {
subtitle: string;
}
export function canChooseSubscriptionPayChannel(
countryCode: string | null | undefined,
): boolean {
return countryCode?.trim().toUpperCase() === "PH";
}
export function resolveSubscriptionPayChannel(input: {
countryCode: string | null | undefined;
requestedPayChannel: PayChannel | null | undefined;
}): PayChannel {
if (!canChooseSubscriptionPayChannel(input.countryCode)) return "stripe";
return (
input.requestedPayChannel ??
getDefaultPayChannelForCountryCode(input.countryCode)
);
}
export function isVipPlan(plan: PaymentPlan): boolean {
return plan.vipDays !== null;
}