Showing
4 changed files
with
179 additions
and
40 deletions
1 | /** | 1 | /** |
2 | - * 支付成功页 | 2 | + * 支付 |
3 | * @author: jing.li<jing.li@yoho.cn> | 3 | * @author: jing.li<jing.li@yoho.cn> |
4 | * @date: 2016/10/25 | 4 | * @date: 2016/10/25 |
5 | */ | 5 | */ |
@@ -9,6 +9,9 @@ | @@ -9,6 +9,9 @@ | ||
9 | const mRoot = '../models'; | 9 | const mRoot = '../models'; |
10 | const payModel = require(`${mRoot}/pay`); | 10 | const payModel = require(`${mRoot}/pay`); |
11 | const headerModel = require('../../../doraemon/models/header'); // 头部model | 11 | const headerModel = require('../../../doraemon/models/header'); // 头部model |
12 | +const co = require('bluebird').coroutine; | ||
13 | +const helpers = global.yoho.helpers; | ||
14 | +const AliServer = require('../../serverAPI/pay/alipay'); | ||
12 | 15 | ||
13 | /** | 16 | /** |
14 | * 支付中心 | 17 | * 支付中心 |
@@ -55,24 +58,82 @@ const payCenter = (req, res, next) => { | @@ -55,24 +58,82 @@ const payCenter = (req, res, next) => { | ||
55 | * 支付宝跳转页 | 58 | * 支付宝跳转页 |
56 | * @param req | 59 | * @param req |
57 | * @param res | 60 | * @param res |
58 | - * @param next | ||
59 | */ | 61 | */ |
60 | -const goAlipay = (req, res, next) => { | 62 | +const goAlipay = (req, res) => { |
61 | let orderCode = req.query.order_code; | 63 | let orderCode = req.query.order_code; |
62 | let uid = req.user.uid; | 64 | let uid = req.user.uid; |
63 | let sessionKey = req.session.TOKEN; | 65 | let sessionKey = req.session.TOKEN; |
66 | + let paymentType = req.query.payment_type; | ||
64 | 67 | ||
65 | if (!orderCode || !uid || !sessionKey) { | 68 | if (!orderCode || !uid || !sessionKey) { |
66 | res.redirect('/'); | 69 | res.redirect('/'); |
67 | } | 70 | } |
68 | 71 | ||
69 | - payModel.goAlipay({ | ||
70 | - orderCode: orderCode, | ||
71 | - uid: uid, | ||
72 | - sessionKey: sessionKey | ||
73 | - }).then(result => { | 72 | + co(function*() { |
73 | + let orderDetail = yield payModel.getOtherDetail({ | ||
74 | + uid: uid, | ||
75 | + orderCode: orderCode, | ||
76 | + sessionKey: sessionKey | ||
77 | + }); | ||
78 | + | ||
79 | + if (!orderDetail) { | ||
80 | + return res.json({ | ||
81 | + code: 400, | ||
82 | + msg: '没有找到该订单!' | ||
83 | + }); | ||
84 | + } | ||
74 | 85 | ||
75 | - }).catch(next); | 86 | + if (orderDetail.is_cancel === 'Y') { |
87 | + let url = helpers.urlFormat('/home/orders/detail', {order_code: orderCode}); | ||
88 | + | ||
89 | + return res.json({ | ||
90 | + code: 400, | ||
91 | + msg: '订单已经取消' | ||
92 | + }).redirect(url); | ||
93 | + } | ||
94 | + | ||
95 | + /* TODO 要不搞点儿日志? */ | ||
96 | + let prePayInfo = yield payModel.savePrePayInfo({ | ||
97 | + uid: uid, | ||
98 | + orderCode: orderCode, | ||
99 | + payment: paymentType | ||
100 | + }); | ||
101 | + | ||
102 | + let totalFee = orderDetail.payment_amount * 100; | ||
103 | + let payExpire = orderDetail.pay_expire; // TODO 需要特殊处理一下 | ||
104 | + | ||
105 | + let reqParams = { | ||
106 | + orderCode: orderCode, | ||
107 | + totalFee: totalFee, | ||
108 | + goodsName: '有货订单号:' + orderCode, | ||
109 | + orderTime: orderDetail.create_time, | ||
110 | + payExpire: payExpire | ||
111 | + }; | ||
112 | + | ||
113 | + let payRequestPars = AliServer.getPayRequestPars(reqParams); | ||
114 | + | ||
115 | + if (!payRequestPars) { | ||
116 | + return res.json({ | ||
117 | + code: 400, | ||
118 | + msg: '支付系统繁忙,请稍后再试' | ||
119 | + }); | ||
120 | + } | ||
121 | + | ||
122 | + let paymentRecod = yield payModel.updateOrderPayment({ | ||
123 | + orderCode: orderCode, | ||
124 | + payment: paymentType, | ||
125 | + uid: uid | ||
126 | + }); | ||
127 | + | ||
128 | + if (!paymentRecod) { | ||
129 | + return res.json({ | ||
130 | + code: 400, | ||
131 | + msg: '系统繁忙,请稍后再试' | ||
132 | + }); | ||
133 | + } | ||
134 | + | ||
135 | + return res.redirect(payRequestPars.pay_url + payRequestPars.pars); | ||
136 | + })(); | ||
76 | }; | 137 | }; |
77 | 138 | ||
78 | // 货到付款 | 139 | // 货到付款 |
@@ -84,6 +84,38 @@ const _getOthersBuy = (param) => { | @@ -84,6 +84,38 @@ const _getOthersBuy = (param) => { | ||
84 | }; | 84 | }; |
85 | 85 | ||
86 | /** | 86 | /** |
87 | + * 选择支付,校验时间间隔,插入数据 | ||
88 | + * @returns {*|Promise.<TResult>} | ||
89 | + * @private | ||
90 | + */ | ||
91 | +const savePrePayInfo = (params) => { | ||
92 | + return api.get('', { | ||
93 | + method: 'app.order.savePrePayInfo', | ||
94 | + uid: params.uid, | ||
95 | + orderCode: params.orderCode, | ||
96 | + payment: params.payment | ||
97 | + }, {code: 200}).then(result => { | ||
98 | + return result && result.data; | ||
99 | + }); | ||
100 | +}; | ||
101 | + | ||
102 | +/** | ||
103 | + * 更新订单的支付方式 | ||
104 | + * @param params | ||
105 | + * @returns {*|Promise.<TResult>} | ||
106 | + */ | ||
107 | +const updateOrderPayment = (params) => { | ||
108 | + return api.get('', { | ||
109 | + method: 'app.SpaceOrders.updateOrdersPaymentByCode', | ||
110 | + order_code: params.orderCode, | ||
111 | + payment: params.payment, | ||
112 | + uid: params.uid | ||
113 | + }, {code: 200}).then(result => { | ||
114 | + return result && result.data; | ||
115 | + }); | ||
116 | +}; | ||
117 | + | ||
118 | +/** | ||
87 | * 支付相关的数据处理函数 | 119 | * 支付相关的数据处理函数 |
88 | */ | 120 | */ |
89 | const payTool = { | 121 | const payTool = { |
@@ -156,21 +188,6 @@ const payCenter = (params) => { | @@ -156,21 +188,6 @@ const payCenter = (params) => { | ||
156 | }); | 188 | }); |
157 | }; | 189 | }; |
158 | 190 | ||
159 | -/** | ||
160 | - * 支付宝跳转页数据处理 | ||
161 | - * @param param | ||
162 | - * @returns {*|Promise.<TResult>} | ||
163 | - */ | ||
164 | -const goAlipay = (param) => { | ||
165 | - return _getOtherDetail({ | ||
166 | - uid: param.uid, | ||
167 | - orderCode: param.orderCode, | ||
168 | - sessionKey: param.sessionKey | ||
169 | - }).then(result => { | ||
170 | - return result; | ||
171 | - }); | ||
172 | -}; | ||
173 | - | ||
174 | // 货到付款 | 191 | // 货到付款 |
175 | const getPayCod = (param) => { | 192 | const getPayCod = (param) => { |
176 | return api.all([ | 193 | return api.all([ |
@@ -244,8 +261,10 @@ const getPayAli = (param) => { | @@ -244,8 +261,10 @@ const getPayAli = (param) => { | ||
244 | }; | 261 | }; |
245 | 262 | ||
246 | module.exports = { | 263 | module.exports = { |
264 | + getOtherDetail: _getOtherDetail, | ||
265 | + savePrePayInfo, | ||
266 | + updateOrderPayment, | ||
247 | payCenter, | 267 | payCenter, |
248 | - goAlipay, | ||
249 | getPayCod, | 268 | getPayCod, |
250 | getPayAli | 269 | getPayAli |
251 | }; | 270 | }; |
apps/serverAPI/pay/alipay.js
0 → 100644
1 | +/** | ||
2 | + * Created by yoho on 2016/12/26. | ||
3 | + */ | ||
4 | +'use strict'; | ||
5 | +const Config = global.yoho.config; | ||
6 | +const AlipayConfig = global.yoho.config.alipayConfig; | ||
7 | +const helpers = global.yoho.helpers; | ||
8 | +const _ = require('lodash'); | ||
9 | +const md5 = require('md5'); | ||
10 | + | ||
11 | +const getPayRequestPars = (params) => { | ||
12 | + let parameter = _.compact({ | ||
13 | + service: AlipayConfig.service, | ||
14 | + partner: AlipayConfig.partner, | ||
15 | + _input_charset: AlipayConfig.inputCharset, | ||
16 | + notify_url: Config.domains.service, // TODO 不确定 | ||
17 | + return_url: helpers.urlFormat(AlipayConfig.returnUrl), | ||
18 | + payment_type: AlipayConfig.paymentType, | ||
19 | + seller_id: AlipayConfig.partner, | ||
20 | + it_b_pay: new Date('Y-m-d H:i', params.payExpire), | ||
21 | + out_trade_no: params.orderCode, | ||
22 | + subject: params.goodsName, | ||
23 | + total_fee: params.totalFee / 100, | ||
24 | + show_url: helpers.urlFormat('/home/orderdetail', {order_code: params.orderCode}) | ||
25 | + }); | ||
26 | + let resultParam = ''; | ||
27 | + let resultSign = ''; | ||
28 | + | ||
29 | + _.forEach(parameter, (value, key) => { | ||
30 | + resultParam += key + '=' + encodeURIComponent(value) + '&'; | ||
31 | + resultSign += key + '=' + value + '&'; | ||
32 | + }); | ||
33 | + | ||
34 | + resultParam = _.trimEnd(resultParam, '&'); | ||
35 | + resultSign = _.trimEnd(resultSign, '&'); | ||
36 | + | ||
37 | + return { | ||
38 | + pay_url: AlipayConfig.payUrl, | ||
39 | + pars: resultParam + '&sign=' + md5(resultSign) + '&sign_type=' + AlipayConfig.signType | ||
40 | + }; | ||
41 | +}; | ||
42 | + | ||
43 | +module.exports = { | ||
44 | + getPayRequestPars | ||
45 | +}; |
@@ -16,21 +16,21 @@ module.exports = { | @@ -16,21 +16,21 @@ module.exports = { | ||
16 | siteUrl: '//m.yohobuy.com', | 16 | siteUrl: '//m.yohobuy.com', |
17 | assetUrl: '//127.0.0.1:5001', | 17 | assetUrl: '//127.0.0.1:5001', |
18 | domains: { | 18 | domains: { |
19 | - // api: 'http://api-test3.yohops.com:9999/', | ||
20 | - // service: 'http://service-test3.yohops.com:9999/', | ||
21 | - // liveApi: 'http://testapi.live.yohops.com:9999/', | ||
22 | - // singleApi: 'http://api-test3.yohops.com:9999/', | ||
23 | - // imSocket: 'ws://im.yohobuy.com:10240', | ||
24 | - // imCs: 'http://im.yohobuy.com/api', | ||
25 | - // imServer: 'http://im.yohobuy.com/server' | 19 | + api: 'http://api-test3.yohops.com:9999/', |
20 | + service: 'http://service-test3.yohops.com:9999/', | ||
21 | + liveApi: 'http://testapi.live.yohops.com:9999/', | ||
22 | + singleApi: 'http://api-test3.yohops.com:9999/', | ||
23 | + imSocket: 'ws://im.yohobuy.com:10240', | ||
24 | + imCs: 'http://im.yohobuy.com/api', | ||
25 | + imServer: 'http://im.yohobuy.com/server' | ||
26 | 26 | ||
27 | - api: 'http://api.yoho.cn/', | ||
28 | - service: 'http://service.yoho.cn/', | ||
29 | - liveApi: 'http://api.live.yoho.cn/', | ||
30 | - singleApi: 'http://single.yoho.cn/', | ||
31 | - imSocket: 'ws://imsocket.yohobuy.com:10000', | ||
32 | - imCs: 'http://imhttp.yohobuy.com/api', | ||
33 | - imServer: 'http://imhttp.yohobuy.com/server' | 27 | + // api: 'http://api.yoho.cn/', |
28 | + // service: 'http://service.yoho.cn/', | ||
29 | + // liveApi: 'http://api.live.yoho.cn/', | ||
30 | + // singleApi: 'http://single.yoho.cn/', | ||
31 | + // imSocket: 'ws://imsocket.yohobuy.com:10000', | ||
32 | + // imCs: 'http://imhttp.yohobuy.com/api', | ||
33 | + // imServer: 'http://imhttp.yohobuy.com/server' | ||
34 | }, | 34 | }, |
35 | subDomains: { | 35 | subDomains: { |
36 | host: '.m.yohobuy.com', | 36 | host: '.m.yohobuy.com', |
@@ -86,7 +86,21 @@ module.exports = { | @@ -86,7 +86,21 @@ module.exports = { | ||
86 | appSecret: 'ce21ae4a3f93852279175a167e54509b' | 86 | appSecret: 'ce21ae4a3f93852279175a167e54509b' |
87 | } | 87 | } |
88 | }, | 88 | }, |
89 | - zookeeperServer: '192.168.102.168:2188' | 89 | + zookeeperServer: '192.168.102.168:2188', |
90 | + alipayConfig: { | ||
91 | + payUrl: 'https://mapi.alipay.com/gateway.do?', | ||
92 | + service: 'alipay.wap.create.direct.pay.by.user', | ||
93 | + partner: '2088701661478015', | ||
94 | + inputCharset: 'utf-8', | ||
95 | + notifyUrl: 'payment/alipay_notify', | ||
96 | + returnUrl: '/shopping/pay/aliwapreturn', | ||
97 | + signType: 'MD5', | ||
98 | + paymentType: '1', | ||
99 | + alipayKey: 'kcxawi9bb07mzh0aq2wcirsf9znusobw', | ||
100 | + sellerMail: 'zfb@yoho.cn', | ||
101 | + merchantUrl: 'http://m.yohobuy.com/home/orders/detail?order_code=', | ||
102 | + cacert: 'cacert.pem' | ||
103 | + } | ||
90 | }; | 104 | }; |
91 | 105 | ||
92 | if (isProduction) { | 106 | if (isProduction) { |
-
Please register or login to post a comment