66 lines
2.0 KiB
JavaScript
66 lines
2.0 KiB
JavaScript
"use strict";
|
|
var __async = (__this, __arguments, generator) => {
|
|
return new Promise((resolve, reject) => {
|
|
var fulfilled = (value) => {
|
|
try {
|
|
step(generator.next(value));
|
|
} catch (e) {
|
|
reject(e);
|
|
}
|
|
};
|
|
var rejected = (value) => {
|
|
try {
|
|
step(generator.throw(value));
|
|
} catch (e) {
|
|
reject(e);
|
|
}
|
|
};
|
|
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
});
|
|
};
|
|
const common_vendor = require("../common/vendor.js");
|
|
const utils_http = require("../utils/http.js");
|
|
const pay = (order) => __async(exports, null, function* () {
|
|
try {
|
|
const createOrder = yield utils_http.httpPost("/order/create", order);
|
|
if (createOrder.code === 200) {
|
|
const orderData = createOrder.data;
|
|
const wxres = yield requestPayment(orderData.payData);
|
|
if (wxres.errMsg === "requestPayment:ok") {
|
|
common_vendor.index.showToast({ title: "支付成功", icon: "success" });
|
|
} else {
|
|
common_vendor.index.showToast({ title: "支付失败", icon: "none" });
|
|
}
|
|
}
|
|
} catch (err) {
|
|
common_vendor.index.showToast({ title: "创建订单失败", icon: "none" });
|
|
}
|
|
});
|
|
const payOrder = (orderId) => __async(exports, null, function* () {
|
|
const payRes = yield utils_http.httpPost("/order/pay/" + orderId, {});
|
|
return payRes;
|
|
});
|
|
function requestPayment(paymentData) {
|
|
return new Promise((resolve, reject) => {
|
|
common_vendor.index.requestPayment({
|
|
provider: "wxpay",
|
|
// 微信支付
|
|
timeStamp: paymentData.timeStamp,
|
|
nonceStr: paymentData.nonceStr,
|
|
package: paymentData.package,
|
|
signType: paymentData.signType,
|
|
paySign: paymentData.paySign,
|
|
success: function(res) {
|
|
resolve(res);
|
|
},
|
|
fail: function(err) {
|
|
reject(err);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
exports.pay = pay;
|
|
exports.payOrder = payOrder;
|
|
//# sourceMappingURL=pay.js.map
|