...
|
...
|
@@ -10,30 +10,55 @@ |
|
|
const PayData = require('../models/pay');
|
|
|
const OrderData = require('../models/order');
|
|
|
const Alipay = require('./pay/alipay');
|
|
|
const Alibank = require('./pay/alibank');
|
|
|
const Wechat = require('./pay/wechat');
|
|
|
const Promise = require('bluebird');
|
|
|
const co = Promise.coroutine;
|
|
|
const logger = global.yoho.logger;
|
|
|
|
|
|
const Payment = {
|
|
|
pay(user, order, method) {
|
|
|
pay(user, order, payType) {
|
|
|
return co(function*() {
|
|
|
let payInfo = yield PayData.getPaymentInfo(method);
|
|
|
let result = {
|
|
|
code: 400,
|
|
|
message: '获取支付方式信息失败'
|
|
|
};
|
|
|
let paymentPars = payType.split('_');
|
|
|
let payInfo;
|
|
|
let bankCode = '';
|
|
|
|
|
|
if (payInfo && payInfo.id === method) {
|
|
|
if (method === PayData.payments.alipay) {
|
|
|
if (paymentPars.length !== 2) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
let method = paymentPars[0] * 1;
|
|
|
|
|
|
if (method === PayData.payments.wechat) {
|
|
|
// 如果是微信支付,不需要调用获取支付方式详情接口
|
|
|
result = yield Wechat.pay(user, order, {id: PayData.payments.wechat});
|
|
|
} else {
|
|
|
payInfo = yield PayData.getPaymentInfo(method);
|
|
|
|
|
|
if (!payInfo.payParams) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
switch (payInfo.id) {
|
|
|
case PayData.payments.alipay:
|
|
|
result = Alipay.pay(user, order, payInfo);
|
|
|
} else if (method === PayData.payments.wechat) {
|
|
|
result = yield Wechat.pay(user, order, payInfo);
|
|
|
break;
|
|
|
case PayData.payments.alibank:
|
|
|
bankCode = paymentPars[1];
|
|
|
payInfo.bankCode = bankCode;
|
|
|
result = Alibank.pay(user, order, payInfo);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (result.code === 200) {
|
|
|
let updateInfo = yield Payment.beforePay(user, order, method);
|
|
|
let updateInfo = yield Payment.beforePay(user, order, method, bankCode);
|
|
|
|
|
|
if (updateInfo && updateInfo.code !== 200) {
|
|
|
return updateInfo;
|
...
|
...
|
@@ -44,7 +69,7 @@ const Payment = { |
|
|
})();
|
|
|
},
|
|
|
|
|
|
beforePay(user, order, method) {
|
|
|
beforePay(user, order, method, bankCode) {
|
|
|
return Promise.all([
|
|
|
OrderData.updateOrderPayment(order.orderCode, method, user.uid),
|
|
|
PayData.savePrePayInfo(order.orderCode, method, user.uid),
|
...
|
...
|
@@ -53,8 +78,6 @@ const Payment = { |
|
|
let paymentRecord = result[0];
|
|
|
let prePayResult = result[1];
|
|
|
let bankRecord = result[2];
|
|
|
let bankCode = ''; // 暂时写成'', 参考php代码 Payment.php:564
|
|
|
|
|
|
|
|
|
if (!paymentRecord || paymentRecord.code !== 200 || !prePayResult || prePayResult.code !== 200) {
|
|
|
let message = paymentRecord && paymentRecord.message ? paymentRecord.message : '系统繁忙,请稍后再试';
|
...
|
...
|
@@ -62,7 +85,6 @@ const Payment = { |
|
|
return {code: 400, message: message};
|
|
|
}
|
|
|
|
|
|
|
|
|
if (bankRecord && bankRecord.bankCode) {
|
|
|
return PayData.updateOrderPayBank(order.orderCode, method, bankCode);
|
|
|
} else {
|
...
|
...
|
@@ -86,8 +108,8 @@ const Payment = { |
|
|
|
|
|
if (payId === PayData.payments.alipay) {
|
|
|
payResult = Alipay.notify(query, payInfo);
|
|
|
} else if (payId === PayData.payments.wechat) {
|
|
|
payResult = Wechat.notify(query, payInfo);
|
|
|
} else if (payId === PayData.payments.alibank) {
|
|
|
payResult = Alibank.notify(query, payInfo);
|
|
|
}
|
|
|
|
|
|
payResult.bankName = payResult.bankName || payInfo.payName || '';
|
...
|
...
|
|