Authored by 郝肖肖

添加财付通异步地址

... ... @@ -194,6 +194,21 @@ const sendPayConfirm = (req, res, next) => {
}).catch(next);
};
// 支付异步回调
const notify = (req, res, next) => {
let type = req.params.type;
let query = req.query;
let payId = PayData.payments[type];
if (!payId) {
return res.json('');
}
PayHelpers.notifyPay(query, payId).then(result => {
res.json(result);
}).catch(next);
};
module.exports = {
online,
... ... @@ -201,5 +216,6 @@ module.exports = {
toPay,
weixinQr,
weixinPayState,
sendPayConfirm
sendPayConfirm,
notify
};
... ...
... ... @@ -65,7 +65,7 @@ const Tenpay = {
orderCode: orderCode,
payResult: 200,
totalFee: data.total_fee * 0.01,
tradeNo: '',
tradeNo: data.transaction_id,
bankBillNo: ''
};
},
... ... @@ -80,9 +80,7 @@ const Tenpay = {
signValue = data.sign;
delete data.sign;
let signStr = md5(sign.raw(data) + payParams.merchant_key).toLocaleUpperCase();
console.log(signValue, signStr, ' ==2222222222= ');
let signStr = md5(sign.raw(data) + '&key=' + payParams.merchant_key).toLocaleUpperCase();
return signValue === signStr;
}
... ...
... ... @@ -138,6 +138,7 @@ const Payment = {
let payResult = {};
let payData = {};
let payName = '';
let isPcpayNotify = false;// 回调地址,java未做,走前端逻辑
if (payId === PayData.payments.alipay) {
payResult = Alipay.notify(query, payInfo);
... ... @@ -147,8 +148,15 @@ const Payment = {
payResult = Unionpay.notify(query);
} else if (payId === PayData.payments.tenpay) {
payResult = Tenpay.notify(query, payInfo);
isPcpayNotify = true;
} else if (payId === PayData.payments.chinabank) {
payResult = Chinabank.notify(query, payInfo);
isPcpayNotify = true;
}
if (isPcpayNotify && payResult.payResult === 200) {
// 更新订单状态
yield PayData.pcpayNotify(Object.assign({payId: payId}, payResult));
}
payResult.bankName = payName = (payResult.bankName || payInfo.payName || '');
... ... @@ -238,6 +246,27 @@ const Payment = {
return data;
});
},
// 异步通知地址
notifyPay(query, payId) {
return co(function*() {
let d = '';
let payInfo = yield PayData.getPaymentInfo(payId);
if (payId === PayData.payments.tenpay) {
let payResult = Tenpay.notify(query, payInfo);
if (payResult.payResult === 200) {
// 更新订单状态
yield PayData.pcpayNotify(Object.assign({payId: payId}, payResult));
return 'success';
}
return 'fail';
}
return d;
})();
}
};
... ...
... ... @@ -126,6 +126,32 @@ const getOrderCountByUid = (uid) => {
});
};
/**
* [更新订单状态]
* @param {[type]} code [订单号]
* @param {[type]} payment [支付方式]
* @param {[type]} amount [金额(单位:元)]
* @param {[type]} bankName [银行名称]
* @param {[type]} bankCode [银行代码]
* @param {[type]} tradeNo [交易流水号]
* @param {[type]} bankBillNo [银行流水号]
* @return {[type]} [{}]
*/
const pcpayNotify = (code, payment, amount, bankName, bankCode, tradeNo, bankBillNo) => {
let params = {
method: 'web.SpaceOrders.pcpayNotify',
order_code: code,
payment: payment,
amount: amount,
bank_name: bankName || '',
bank_code: bankCode || '',
trade_no: tradeNo || '',
bank_bill_no: bankBillNo || ''
};
return api.get('', params);
};
module.exports = {
getPayProvider,
getPaymentInfo,
... ... @@ -137,5 +163,6 @@ module.exports = {
orderDetail,
updateOrderPayment,
getResourceData,
getOrderCountByUid
getOrderCountByUid,
pcpayNotify
};
... ...
... ... @@ -374,6 +374,15 @@ const deliveryData = (orderInfo, payId) => {
});
};
const pcpayNotify = (param) => {
return co(function *() {
return yield payApi.pcpayNotify(
param.orderCode, param.payId, param.totalFee, param.bankName || '',
param.bankCode || '', param.tradeNo || '', param.bankBillNo || ''
);
})();
};
module.exports = {
orderDetail,
getPayInfo,
... ... @@ -385,6 +394,7 @@ module.exports = {
procOrderData,
updateOrderPayment,
payments,
deliveryData
deliveryData,
pcpayNotify
};
... ...
... ... @@ -22,4 +22,7 @@ router.post('/pay/sendPayConfirm', auth, pay.sendPayConfirm);
router.get('/pay/callback/:type', auth, pay.callback);
router.post('/pay/callback/:type', auth, pay.callback);// 银联是post方式返回的
// 支付异步回调
router.get('/pay/notify/:type', auth, pay.notify);
module.exports = router;
... ...