async precreateOrder(options) {
// listing out needed params
const { body, fee_type, total_fee, spbill_create_ip, trade_type, notify_url } = options
const mch_id = this.mch_id
const url = this.placeOrderUrl
const nonce = stringHelper.generateNonce(32)
const out_trade_no = this._generateOutTradeNoWithDate()
// build a payment source string
const source = `body=${body}&fee_type=${fee_type}&mch_id=${mch_id}&nonce_str=${nonce}¬ify_url=${notify_url}&out_trade_no=${out_trade_no}&spbill_create_ip=${spbill_create_ip}&total_fee=${total_fee}&trade_type=${trade_type}&key=${this.api_key}`
// sign the payment source string
const sign = this._generateSignature(source)
// build xml template
var xml = jsonxml({
xml: [
{ name: 'body', text: `${body}` }, // food-McNuggets
{ name: 'fee_type', text: `${fee_type}` }, // CNY
{ name: 'mch_id', text: `${mch_id}` }, // 123123
{ name: 'nonce_str', text: `${nonce}` }, // 123123
{ name: 'notify_url', text: `${notify_url}` }, // some_endpoint_on_aws
{ name: 'out_trade_no', text: `${out_trade_no}` }, // 商户支付的订单号由商户自定义生成 (user generated unuique product id)
{ name: 'sign', text: `${sign}` }, // 123123
{ name: 'spbill_create_ip', text: `${spbill_create_ip}` }, // 172.31.99.191 -- server ip
{ name: 'total_fee', text: `${total_fee}` }, // 300
{ name: 'trade_type', text: `${trade_type}` } // NATIVE
]
})
// send xml request to QQPay
const requestOptions = {
method: 'POST',
uri: url,
headers: { 'Content-Type': 'application/xml; charset=utf-8' },
body: xml,
xml: true
}
return request(url, requestOptions, (err, res, body) => {
const resultJSON = xml2js.parseString(body)
printer.prettyPrint(xml)
printer.prettyPrint(body)
return body
})
}