|
|
/**
|
|
|
* 各种支付的入口
|
|
|
*
|
|
|
* TAR NOTE: 本项目中仅支持支付宝和微信支付,其他支付方式需调试
|
|
|
* @author: jiangfeng<jeff.jiang@yoho.cn>
|
|
|
* @date: 16/7/22
|
|
|
*/
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
const PayData = require('../models/pay');
|
|
|
const OrderData = require('../models/order');
|
|
|
const PayModel = require('../models/pay');
|
|
|
const Alipay = require('./pay/alipay');
|
|
|
const Alibank = require('./pay/alibank');
|
|
|
const Wechat = require('./pay/wechat');
|
|
|
const Promise = require('bluebird');
|
|
|
const common = require('./pay/common');
|
...
|
...
|
@@ -48,20 +48,25 @@ const Payment = { |
|
|
|
|
|
let method = paymentPars[0] * 1;
|
|
|
|
|
|
if (method === PayData.payments.wechat) {
|
|
|
if (method === PayModel.payments.wechat) {
|
|
|
// 如果是微信支付,不需要调用获取支付方式详情接口
|
|
|
result = yield Wechat.pay(user, order, { id: PayData.payments.wechat });
|
|
|
result = yield Wechat.pay(user, order, { id: PayModel.payments.wechat });
|
|
|
} else {
|
|
|
payInfo = yield PayData.getPaymentInfo(method);
|
|
|
payInfo = yield PayModel.getPaymentInfo(method);
|
|
|
|
|
|
if (!payInfo.payParams) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
switch (payInfo.id) {
|
|
|
case PayData.payments.alipay:
|
|
|
case PayModel.payments.alipay:
|
|
|
result = Alipay.pay(user, order, payInfo, protocol);
|
|
|
break;
|
|
|
case PayModel.payments.alibank:
|
|
|
bankCode = paymentPars[1];
|
|
|
payInfo.bankCode = bankCode; // 设置默认银行
|
|
|
result = Alibank.pay(user, order, payInfo, protocol);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
...
|
...
|
@@ -83,8 +88,8 @@ const Payment = { |
|
|
|
|
|
beforePay(user, order, method, bankCode) {
|
|
|
return Promise.all([
|
|
|
OrderData.updateOrderPayment(order.order_code, method, user.uid),
|
|
|
PayData.getBankByOrder(order.order_code)
|
|
|
PayModel.updateOrderPayment(order.order_code, method, user.uid),
|
|
|
PayModel.getBankByOrder(order.order_code)
|
|
|
]).then(result => {
|
|
|
let paymentRecord = result[0];
|
|
|
let bankRecord = result[1];
|
...
|
...
|
@@ -96,9 +101,9 @@ const Payment = { |
|
|
}
|
|
|
|
|
|
if (bankRecord && bankRecord.bankCode) {
|
|
|
return PayData.updateOrderPayBank(order.order_code, method, bankCode);
|
|
|
return PayModel.updateOrderPayBank(order.order_code, method, bankCode);
|
|
|
} else {
|
|
|
return PayData.setOrderPayBank(order.order_code, method, bankCode);
|
|
|
return PayModel.setOrderPayBank(order.order_code, method, bankCode);
|
|
|
}
|
|
|
|
|
|
}).catch(e => {
|
...
|
...
|
@@ -111,37 +116,37 @@ const Payment = { |
|
|
});
|
|
|
},
|
|
|
|
|
|
afterPay(query, payId, user) {
|
|
|
afterPay(query, payId, user, sessionKey) {
|
|
|
return co(function*() {
|
|
|
let payInfo = yield PayData.getPaymentInfo(payId);
|
|
|
let payInfo = yield PayModel.getPaymentInfo(payId);
|
|
|
let payResult = {};
|
|
|
let payData = {};
|
|
|
let payName = '';
|
|
|
|
|
|
if (payId === PayData.payments.alipay) {
|
|
|
if (payId === PayModel.payments.alipay) {
|
|
|
payResult = Alipay.notify(query, payInfo);
|
|
|
} else if (payId === PayData.payments.alibank) {
|
|
|
} else if (payId === PayModel.payments.alibank) {
|
|
|
payResult = Alibank.notify(query, payInfo);
|
|
|
}
|
|
|
|
|
|
payResult.bankName = payName = payResult.bankName || payInfo.payName || '';
|
|
|
payResult.bankCode = payResult.bankCode || payInfo.pay_code || '';
|
|
|
|
|
|
//记录日志
|
|
|
// 记录日志
|
|
|
logger.info(`\r\n\r\n pay back confirm,req = ${JSON.stringify({
|
|
|
query: query,
|
|
|
payId: payId,
|
|
|
user: user,
|
|
|
payResult: payResult
|
|
|
})}`);
|
|
|
query: query,
|
|
|
payId: payId,
|
|
|
user: user,
|
|
|
payResult: payResult
|
|
|
})}`);
|
|
|
|
|
|
if (payResult && payResult.payResult === 200) {
|
|
|
if (payResult.orderCode) {
|
|
|
logger.info('pay back confirm');
|
|
|
yield PayData.sendPayConfirm(payResult.orderCode, payId, user.uid);
|
|
|
yield PayModel.sendPayConfirm(payResult.orderCode, payId, user.uid);
|
|
|
}
|
|
|
|
|
|
payData = yield PayData.procOrderData(payResult, user.uid);
|
|
|
payData = yield PayModel.procOrderData(payResult, user.uid, sessionKey);
|
|
|
} else {
|
|
|
payData = {
|
|
|
code: 500,
|
...
|
...
|
@@ -156,4 +161,4 @@ const Payment = { |
|
|
}
|
|
|
};
|
|
|
|
|
|
module.exports = Payment; |
|
|
\ No newline at end of file |
|
|
module.exports = Payment; |
...
|
...
|
|