fix wechat virtual payment coin flow
This commit is contained in:
@@ -105,6 +105,10 @@ function requestOrdinaryPayment(payParams) {
|
||||
function requestVirtualPayment(payParams) {
|
||||
return new Promise((resolve) => {
|
||||
if (!canUseVirtualPayment() || typeof wx.requestVirtualPayment !== 'function') {
|
||||
console.error('[wechat-pay] requestVirtualPayment unavailable', {
|
||||
canUseVirtualPayment: canUseVirtualPayment(),
|
||||
hasRequestVirtualPayment: typeof wx.requestVirtualPayment === 'function',
|
||||
});
|
||||
resolve({
|
||||
status: 'fail',
|
||||
errorMessage: '当前微信基础库不支持 requestVirtualPayment',
|
||||
@@ -120,6 +124,7 @@ function requestVirtualPayment(payParams) {
|
||||
resolve({ status: 'success', errorMessage: '' });
|
||||
},
|
||||
fail(error) {
|
||||
console.error('[wechat-pay] requestVirtualPayment failed', error);
|
||||
resolve({
|
||||
status: resolvePayStatus(error),
|
||||
errorMessage: normalizePayError(error),
|
||||
|
||||
@@ -11,6 +11,7 @@ const {
|
||||
|
||||
describe('wechat-pay mini program payment bridge', () => {
|
||||
beforeEach(() => {
|
||||
vi.spyOn(console, 'error').mockImplementation(() => {});
|
||||
globalThis.wx = {
|
||||
requestPayment: vi.fn(),
|
||||
requestVirtualPayment: vi.fn(),
|
||||
@@ -100,8 +101,12 @@ describe('wechat-pay mini program payment bridge', () => {
|
||||
});
|
||||
|
||||
test('maps virtual payment cancel errCode to cancel result', async () => {
|
||||
const payError = {
|
||||
errCode: -2,
|
||||
errMsg: 'requestVirtualPayment:fail cancel',
|
||||
};
|
||||
globalThis.wx.requestVirtualPayment.mockImplementationOnce((options) => {
|
||||
options.fail?.({ errCode: -2, errMsg: 'requestVirtualPayment:fail cancel' });
|
||||
options.fail?.(payError);
|
||||
});
|
||||
|
||||
await expect(
|
||||
@@ -118,6 +123,10 @@ describe('wechat-pay mini program payment bridge', () => {
|
||||
errMsg: 'requestVirtualPayment:fail cancel',
|
||||
}),
|
||||
});
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
'[wechat-pay] requestVirtualPayment failed',
|
||||
payError,
|
||||
);
|
||||
});
|
||||
|
||||
test('page notifies previous web-view after virtual payment', async () => {
|
||||
|
||||
Reference in New Issue
Block a user