Authored by 姜枫

add pay method

... ... @@ -7,6 +7,9 @@
'use strict';
const PayData = require('../models/pay');
const OrderData = require('../models/order');
const PayHelpers = require('../helpers/pay');
const camelCase = global.yoho.camelCase;
const online = (req, res, next) => {
let orderCode = req.query.code;
... ... @@ -25,11 +28,32 @@ const online = (req, res, next) => {
};
const toPay = (req, res, next) => {
let orderCode = req.query.code;
let method = req.query.method;
let uid = req.user.uid;
OrderData.orderDetail(uid, orderCode).then(result => {
if (result && result.data) {
let order = camelCase(result.data);
return PayHelpers.pay(order, method);
} else {
return {
code: 400,
message: '获取订单失败'
};
}
}).then(result => {
res.json(result);
}).catch(next);
};
const callback = () => {
};
module.exports = {
online,
callback
callback,
toPay
};
... ...
/**
* 各种支付的入口
*
* @author: jiangfeng<jeff.jiang@yoho.cn>
* @date: 16/7/22
*/
const PayData = require('../models/pay');
const Alipay = require('./pay/alipay');
const Payment = {
pay(order, method) {
return PayData.getPaymentInfo(method).then(result => {
console.log(result);
if (method === 'Alipay') {
Alipay.pay(order);
}
});
}
};
module.exports = Payment;
... ...
/**
*
* @author: jiangfeng<jeff.jiang@yoho.cn>
* @date: 16/7/22
*/
const Alipay = {
pay(order, config) {
console.log(order, config);
}
};
module.exports = Alipay;
... ...
... ... @@ -12,6 +12,14 @@ const getPayProvider = () => {
});
};
const getPaymentInfo = (id) => {
return api.get('', {
method: 'web.SpaceOrders.getPaymentById',
id: id
});
};
module.exports = {
getPayProvider
getPayProvider,
getPaymentInfo
};
... ...
... ... @@ -25,7 +25,7 @@ const getOnlinePayProvider = () => {
.filter(i => _.includes(['Alipay', 'Wechatqrcode'], i.payCode))
.map(i => {
return {
id: i.payCode,
id: i.id,
name: i.payName,
img: i.payIcon,
selected: i.payCode === 'Alipay'
... ... @@ -71,7 +71,21 @@ const getPayInfo = (uid, code) => {
})();
};
/**
*
* @param id
*/
const getPaymentInfo = (id) => {
return co(function * () {
let payment = yield api.getPaymentInfo(id);
return payment;
})();
};
module.exports = {
getPayInfo
getPayInfo,
getPaymentInfo
};
... ...
... ... @@ -34,6 +34,8 @@ router.post('/order/submit', auth, order.orderSub);
// 支付
router.get('/pay/online', pay.online);
router.get('/pay/online/go', pay.toPay);
// 在线支持完成
router.get('/pay/online/success', finish.success);
... ...
... ... @@ -19,7 +19,7 @@ module.exports = {
},
cookieDomain: 'yohobuy.com',
domains: {
api: 'http://testapi.yoho.cn:28078/', // devapi.yoho.cn:58078 testapi.yoho.cn:28078 devapi.yoho.cn:58078
api: 'http://api.yoho.cn/', // devapi.yoho.cn:58078 testapi.yoho.cn:28078 devapi.yoho.cn:58078
service: 'http://testservice.yoho.cn:28077/', // testservice.yoho.cn:28077 devservice.yoho.cn:58077
search: 'http://192.168.102.216:8080/yohosearch/'
},
... ...