@liuhlightning/wx-pay
Version:
communicate to wx pay
93 lines • 2.47 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.postTransactionJsApi = postTransactionJsApi;
exports.postTransactionApp = postTransactionApp;
exports.postTransactionH5 = postTransactionH5;
exports.postTransactionNative = postTransactionNative;
const nonceStr_1 = require("../../util/nonceStr");
const timestamp_1 = require("../../util/timestamp");
/**
* JSAPI下单 小程序支付也用这个接口
*
* https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_1.shtml
*/
async function postTransactionJsApi(data) {
const { status, data: { prepay_id }, } = await this.request({
url: "/v3/pay/transactions/jsapi",
method: "post",
data: {
appid: this.appId,
mchid: this.mchId,
notify_url: this.notifyUrl,
...data,
},
});
const t = (0, timestamp_1.timestamp)();
const n = (0, nonceStr_1.nonceStr)();
const pkg = `prepay_id=${prepay_id}`;
const signStr = `${this.appId}\n${t}\n${n}\n${pkg}\n`;
const paySign = this.sign(signStr);
return {
status,
data: {
appId: this.appId,
timeStamp: t,
nonceStr: n,
package: pkg,
signType: "RSA",
paySign,
},
};
}
/**
* APP下单
*
* https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_2_1.shtml
*/
function postTransactionApp(data) {
return this.request({
method: "POST",
url: "/v3/pay/transactions/app",
data: {
appid: this.appId,
mchid: this.mchId,
notify_url: this.notifyUrl,
...data,
},
});
}
/**
* H5下单
*
* https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_3_1.shtml
*/
function postTransactionH5(data) {
return this.request({
method: "POST",
url: "/v3/pay/transactions/h5",
data: {
appid: this.appId,
mchid: this.mchId,
notify_url: this.notifyUrl,
...data,
},
});
}
/**
* Native下单
*
* https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_4_1.shtml
*/
function postTransactionNative(data) {
return this.request({
method: "POST",
url: "/v3/pay/transactions/native",
data: {
appid: this.appId,
mchid: this.mchId,
notify_url: this.notifyUrl,
...data,
},
});
}
//# sourceMappingURL=post.js.map