feat: switch mini program recharge to virtual payment

This commit is contained in:
kdletters
2026-05-26 22:32:16 +08:00
parent b388b124da
commit f36b90ebdb
22 changed files with 959 additions and 137 deletions

View File

@@ -2,20 +2,45 @@ import { describe, expect, test } from 'vitest';
import {
resolveProfileRechargePaymentChannel,
resolveProfileRechargeProductPaymentChannel,
shouldShowRechargeEntry,
WECHAT_H5_PAYMENT_CHANNEL,
WECHAT_MINI_PROGRAM_PAYMENT_CHANNEL,
WECHAT_MINI_PROGRAM_VIRTUAL_PAYMENT_CHANNEL,
WECHAT_NATIVE_PAYMENT_CHANNEL,
} from './paymentPlatform';
describe('resolveProfileRechargePaymentChannel', () => {
test('小程序运行态选择 wechat_mp', () => {
test('小程序运行态基础通道选择 wechat_mp_virtual', () => {
expect(
resolveProfileRechargePaymentChannel({
location: { search: '?clientRuntime=wechat_mini_program' },
navigator: { userAgent: 'Mozilla/5.0 (iPhone)' },
}),
).toBe(WECHAT_MINI_PROGRAM_PAYMENT_CHANNEL);
).toBe(WECHAT_MINI_PROGRAM_VIRTUAL_PAYMENT_CHANNEL);
});
test('点数商品在小程序运行态选择 wechat_mp_virtual', () => {
expect(
resolveProfileRechargeProductPaymentChannel(
{ kind: 'points' },
{
location: { search: '?clientRuntime=wechat_mini_program' },
navigator: { userAgent: 'Mozilla/5.0 (iPhone)' },
},
),
).toBe(WECHAT_MINI_PROGRAM_VIRTUAL_PAYMENT_CHANNEL);
});
test('会员商品在小程序运行态也选择 wechat_mp_virtual', () => {
expect(
resolveProfileRechargeProductPaymentChannel(
{ kind: 'membership' },
{
location: { search: '?clientRuntime=wechat_mini_program' },
navigator: { userAgent: 'Mozilla/5.0 (iPhone)' },
},
),
).toBe(WECHAT_MINI_PROGRAM_VIRTUAL_PAYMENT_CHANNEL);
});
test('移动网页选择 wechat_h5', () => {

View File

@@ -1,13 +1,19 @@
export const WECHAT_MINI_PROGRAM_PAYMENT_CHANNEL = 'wechat_mp';
export const WECHAT_MINI_PROGRAM_VIRTUAL_PAYMENT_CHANNEL = 'wechat_mp_virtual';
export const WECHAT_H5_PAYMENT_CHANNEL = 'wechat_h5';
export const WECHAT_NATIVE_PAYMENT_CHANNEL = 'wechat_native';
export const MOCK_PAYMENT_CHANNEL = 'mock';
export type ProfileRechargeWechatPaymentChannel =
| typeof WECHAT_MINI_PROGRAM_PAYMENT_CHANNEL
| typeof WECHAT_MINI_PROGRAM_VIRTUAL_PAYMENT_CHANNEL
| typeof WECHAT_H5_PAYMENT_CHANNEL
| typeof WECHAT_NATIVE_PAYMENT_CHANNEL;
export type ProfileRechargeProductPaymentMode = {
kind: 'points' | 'membership';
};
type PaymentPlatformNavigator = Pick<Navigator, 'userAgent' | 'maxTouchPoints'>;
export type PaymentPlatformContext = {
@@ -45,7 +51,7 @@ export function resolveProfileRechargePaymentChannel(
: null);
if (isWechatMiniProgramRuntime(location)) {
return WECHAT_MINI_PROGRAM_PAYMENT_CHANNEL;
return WECHAT_MINI_PROGRAM_VIRTUAL_PAYMENT_CHANNEL;
}
if (isMobileWebRuntime(navigatorLike, matchMedia)) {
@@ -55,6 +61,13 @@ export function resolveProfileRechargePaymentChannel(
return WECHAT_NATIVE_PAYMENT_CHANNEL;
}
export function resolveProfileRechargeProductPaymentChannel(
_product: ProfileRechargeProductPaymentMode,
context: PaymentPlatformContext = {},
): ProfileRechargeWechatPaymentChannel {
return resolveProfileRechargePaymentChannel(context);
}
export function isManualMockPaymentChannel(paymentChannel: string) {
return paymentChannel.trim() === MOCK_PAYMENT_CHANNEL;
}