feat: gate recharge payment by login device
This commit is contained in:
@@ -16,6 +16,20 @@ export type PaymentPlatformContext = {
|
||||
matchMedia?: Window['matchMedia'] | null;
|
||||
};
|
||||
|
||||
export function shouldShowRechargeEntry(
|
||||
context: PaymentPlatformContext = {},
|
||||
) {
|
||||
const location =
|
||||
context.location ?? (typeof window !== 'undefined' ? window.location : null);
|
||||
const navigatorLike =
|
||||
context.navigator ?? (typeof navigator !== 'undefined' ? navigator : null);
|
||||
|
||||
return (
|
||||
isWechatMiniProgramRuntime(location) ||
|
||||
isWechatBrowserRuntime(navigatorLike)
|
||||
);
|
||||
}
|
||||
|
||||
export function resolveProfileRechargePaymentChannel(
|
||||
context: PaymentPlatformContext = {},
|
||||
): ProfileRechargeWechatPaymentChannel {
|
||||
@@ -55,16 +69,21 @@ function isWechatMiniProgramRuntime(
|
||||
);
|
||||
}
|
||||
|
||||
function isWechatBrowserRuntime(
|
||||
navigatorLike: Partial<PaymentPlatformNavigator> | null | undefined,
|
||||
) {
|
||||
return (
|
||||
navigatorLike?.userAgent?.toLowerCase().includes('micromessenger') ??
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
function isMobileWebRuntime(
|
||||
navigatorLike: Partial<PaymentPlatformNavigator> | null | undefined,
|
||||
matchMedia: Window['matchMedia'] | null | undefined,
|
||||
) {
|
||||
const userAgent = navigatorLike?.userAgent?.toLowerCase() ?? '';
|
||||
if (
|
||||
/android|iphone|ipad|ipod|mobile|micromessenger|windows phone/u.test(
|
||||
userAgent,
|
||||
)
|
||||
) {
|
||||
if (/android|iphone|ipad|ipod|mobile|windows phone/u.test(userAgent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user