oak-pay-business/lib/utils/payClazz/WechatPay/WechatPay.debug.js

94 lines
2.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerGetPayStateResult = void 0;
const PayConfig_1 = require("../../../types/PayConfig");
let _PAY_STATE = '';
function registerGetPayStateResult(payState) {
_PAY_STATE = payState;
}
exports.registerGetPayStateResult = registerGetPayStateResult;
class WechatPay {
channel;
constructor(channel, appId, config) {
// todo
this.channel = channel;
}
async refund(refund) {
return {
externalId: Math.random().toString(),
};
}
async closeRefund(refund) {
return;
}
async getRefundState(refund) {
const r = Math.random();
if (r < 0.5) {
return ['refunded', undefined];
}
return ['failed', {
reason: '微信觉得你长得太丑了,就不想给你退款,让你去深圳找马化腾',
}];
}
decodePayNotification(params, body) {
throw new Error("Method not implemented.");
}
/**
* 参照微信支付prepay接口模拟返回
* @param pay
* @param data
* @param context
*/
async prepay(pay, data, context) {
switch (this.channel) {
case PayConfig_1.PAY_CHANNEL_WECHAT_APP_NAME:
case PayConfig_1.PAY_CHANNEL_WECHAT_JS_NAME:
case PayConfig_1.PAY_CHANNEL_WECHAT_MP_NAME: {
const prepayId = Math.random().toString();
data.externalId = prepayId;
data.meta = {
prepayId,
};
break;
}
case PayConfig_1.PAY_CHANNEL_WECHAT_H5_NAME: {
const h5Url = Math.random().toString();
data.externalId = h5Url;
data.meta = {
h5Url,
};
break;
}
case PayConfig_1.PAY_CHANNEL_WECHAT_NATIVE_NAME: {
const codeUrl = Math.random().toString();
data.externalId = codeUrl;
data.meta = {
codeUrl,
};
break;
}
}
;
data.timeoutAt = Date.now() + 7000 * 1000; // 微信官方文档过期时间2小时提前一点
}
async getState(pay) {
if (_PAY_STATE) {
return [_PAY_STATE, {}];
}
const r = Math.random();
if (r < 0.3) {
return ['paying', {}];
}
else if (r > 0.95) {
return ['closed', {}];
}
return ['paid', {
forbidRefundAt: Date.now() + 24 * 3600 * 1000,
refundable: true,
}];
}
async close(pay) {
}
}
exports.default = WechatPay;