You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.3 KiB
79 lines
2.3 KiB
"use strict";
|
|
const common_vendor = require("../../common/vendor.js");
|
|
const enums_appEnums = require("../../enums/appEnums.js");
|
|
const utils_client = require("../client.js");
|
|
class Wechat {
|
|
init(name, pay) {
|
|
pay[name] = this;
|
|
}
|
|
async run(options) {
|
|
try {
|
|
const res = await utils_client.handleClientEvent({
|
|
MP_WEIXIN: () => {
|
|
return new Promise((resolve) => {
|
|
common_vendor.index.requestPayment({
|
|
provider: "wxpay",
|
|
...options,
|
|
success() {
|
|
resolve(enums_appEnums.PayStatusEnum.SUCCESS);
|
|
},
|
|
fail() {
|
|
resolve(enums_appEnums.PayStatusEnum.FAIL);
|
|
}
|
|
});
|
|
});
|
|
},
|
|
OA_WEIXIN: () => {
|
|
return new Promise((resolve) => {
|
|
wechatOa.pay(options).then(() => {
|
|
resolve(enums_appEnums.PayStatusEnum.SUCCESS);
|
|
}).catch(() => {
|
|
resolve(enums_appEnums.PayStatusEnum.FAIL);
|
|
});
|
|
});
|
|
},
|
|
H5: () => {
|
|
return new Promise((resolve) => {
|
|
window.open(options, "_self");
|
|
resolve(enums_appEnums.PayStatusEnum.PENDING);
|
|
});
|
|
},
|
|
ANDROID: () => {
|
|
return new Promise((resolve, reject) => {
|
|
common_vendor.index.requestPayment({
|
|
provider: "wxpay",
|
|
orderInfo: options,
|
|
success() {
|
|
resolve(enums_appEnums.PayStatusEnum.SUCCESS);
|
|
},
|
|
fail(error) {
|
|
console.log(error);
|
|
resolve(enums_appEnums.PayStatusEnum.FAIL);
|
|
}
|
|
});
|
|
});
|
|
},
|
|
IOS: () => {
|
|
return new Promise((resolve, reject) => {
|
|
options.partnerid = String(options.partnerid);
|
|
common_vendor.index.requestPayment({
|
|
provider: "wxpay",
|
|
orderInfo: options,
|
|
success() {
|
|
resolve(enums_appEnums.PayStatusEnum.SUCCESS);
|
|
},
|
|
fail(err) {
|
|
console.log(err);
|
|
resolve(enums_appEnums.PayStatusEnum.FAIL);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
});
|
|
return res;
|
|
} catch (error) {
|
|
return Promise.reject(error);
|
|
}
|
|
}
|
|
}
|
|
exports.Wechat = Wechat;
|
|
|