JSAPI下单(合作伙伴模式)
除付款码支付场景以外,商户系统先调用该接口在微信支付服务后台生成预支付交易单,返回正确的预支付交易会话标识后再按Native、JSAPI、APP等不同场景生成交易串调起支付。 官方文档 官方文档
js
const { Formatter, Rsa } = require('wechatpay-axios-plugin')
wxpay.v3.pay.partner.transactions.jsapi.post({
sp_mchid,
sp_appid,
sub_mchid,
sub_appid,
description,
out_trade_no,
notify_url,
amount: { total, currency },
payer: { sp_openid, sub_openid },
})
.then(({ data: { prepay_id } }) => {
const nonceStr = Formatter.nonce();
const timeStamp = '' + Formatter.timestamp();
const packageStr = 'prepay_id=' + prepay_id;
return {
appId,
timeStamp,
nonceStr,
package: packageStr,
signType: 'RSA',
paySign: Rsa.sign(
Formatter.joinedByLineFeed(appId, timeStamp, nonceStr, packageStr),
merchantPrivateKeyInstance
)
}
})