Authored by 郝肖肖

merage pay

... ... @@ -23,6 +23,7 @@ const hbs = require('express-handlebars');
const multer = require('connect-multiparty');
const pkg = require('./package.json');
const yohoLib = require('yoho-node-lib');
const helpersHbs = require('./utils/helpers');
const app = express();
... ... @@ -43,7 +44,7 @@ app.engine('.hbs', hbs({
defaultLayout: 'layout',
layoutsDir: './doraemon/views',
partialsDir: './doraemon/views/partial',
helpers: global.yoho.helpers
helpers: Object.assign(global.yoho.helpers, helpersHbs)
}));
app.use(favicon(path.join(__dirname, '/public/favicon.ico')));
... ...
{{# classicBrands}}
<div class="brand-img-box {{#if right}}right{{/if}} {{#if bottomSpace}}mb10{{/if}}">
<div class="brand-img-box {{#if right}}right{{/if}} {{#if bottomSpace}}mb20{{/if}}">
{{# big}}
<a href="{{https url}}" target="_blank">
<img class="big-img" src="{{image src 565 340}}">
... ...
... ... @@ -3,7 +3,7 @@
<div class="msg-right">
<a class="msg-title" href="/editorial/{{id}}.html" target="_blank">{{title}}</a>
<a href="/editorial/{{id}}.html" target="_blank">
<img src="{{image src 640 430 1}}">
<img src="{{image src 640 430}}">
</a>
<div class="content">{{intro}}</div>
<div class="msg-app">
... ...
... ... @@ -9,10 +9,12 @@
const PayData = require('../models/pay');
const OrderData = require('../models/order');
const PayHelpers = require('../helpers/payment');
const paySign = require('../helpers/pay/sign');
const cleanHtml = require(`${global.utils}/cleanHtml`);
const camelCase = global.yoho.camelCase;
const helpers = global.yoho.helpers;
const _ = require('lodash');
const md5 = require('md5');
const integerTest = /^[0-9]*$/;
/**
... ... @@ -138,6 +140,7 @@ const weixinQr = (req, res, next) => {
}).then(order => {
res.display('weixin-pay', {
defaultHeader: false,
bcNavFocus: 3,
module: 'shopping',
page: 'wxpay',
title: '微信扫码支付页面',
... ... @@ -154,10 +157,18 @@ const weixinPayState = (req, res) => {
OrderData.orderDetail(uid, code).then(result => {
if (result && result.data && result.data.payment_status === 'Y') {
let payParams = {
orderCode: code,
totalFee: _.round(parseFloat(result.data.payment_amount), 2)
};
// payment_status: 'Y' <=> tradeStatus: 'Y'
res.json({
code: 200,
data: {
href: helpers.urlFormat('/me/order/detail', {orderCode: code})
href: helpers.urlFormat('/shopping/pay/callback/wechat', Object.assign(payParams, {
sign: md5(paySign.raw(Object.assign({tradeStatus: "Y"}, payParams)))
}))
}
});
} else {
... ...
... ... @@ -16,6 +16,8 @@ const Promise = require('bluebird');
const common = require('./pay/common');
const co = Promise.coroutine;
const logger = global.yoho.logger;
const md5 = require('md5');
const paySign = require('./pay/sign');
const Payment = {
pay(user, order, payType, protocol) {
... ... @@ -117,7 +119,7 @@ const Payment = {
});
},
afterPay(query, payId, user) {
_validate(query, payId, user) {
return co(function*() {
let payInfo = yield PayData.getPaymentInfo(payId);
let payResult = {};
... ... @@ -130,16 +132,16 @@ const Payment = {
payResult = Alibank.notify(query, payInfo);
}
payResult.bankName = payName = payResult.bankName || payInfo.payName || '';
payResult.bankCode = payResult.bankCode || payInfo.pay_code || '';
payResult.bankName = payName = (payResult.bankName || payInfo.payName || '');
payResult.bankCode = (payResult.bankCode || payInfo.pay_code || '');
//记录日志
// 记录日志
logger.info(`\r\n\r\n pay back confirmreq = ${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) {
... ... @@ -159,6 +161,30 @@ const Payment = {
return payData;
})();
},
afterPay(query, payId, user) {
let _this = this;
return co(function*() {
let payData = {code: 500, message: '支付失败'};
let sign = query.sign || '';
switch (payId) {
case PayData.payments.wechat: // 微信支付不须要验证,但前端必须校验sign
delete query.sign;
if (md5(paySign.raw(Object.assign({tradeStatus: 'Y'}, query))) === sign) {
payData = yield PayData.procOrderData(query, user.uid);
}
payData.payName = '微信';
break;
default:// 须要验证的支付方式
payData = _this._validate(query, payId, user);
break;
}
return payData;
})();
}
};
... ...
... ... @@ -21,7 +21,7 @@ const _ = require('lodash');
const payments = {
alipay: 33,
wechat: 36,
alibank: 42
alibank: 44
};
/**
... ... @@ -205,43 +205,43 @@ const procOrderData = (payResult, uid) => {
if (!orderCode) {
result.message = '未查到订单信息,订单状态更新失败!';
return result;
} else {
let orderInfo = yield OrderData.orderDetail(uid, orderCode);
}
if (orderInfo && orderInfo.data) {
let order = orderInfo.data;
let amount = order.payment_amount;
let orderInfo = yield OrderData.orderDetail(uid, orderCode);
if (order.is_cancel === 'Y') {
logger.warn('front pay success but order is cancel.', {payResult: payResult, order: order});
if (orderInfo && orderInfo.data) {
let order = orderInfo.data;
let amount = order.payment_amount;
payApi.sendMessage(order.mobile, 'error_sms', '支付成功,但订单已取消,订单号为' + orderCode);
return {code: 417, message: '支付成功,但订单已取消,需联系客服!'};
}
if (order.is_cancel === 'Y') {
logger.warn('front pay success but order is cancel.', {payResult: payResult, order: order});
if (order.payment_status === 'N') {
logger.warn('front pay success but may be notify fail');
}
payApi.sendMessage(order.mobile, 'error_sms', '支付成功,但订单已取消,订单号为' + orderCode);
return {code: 417, message: '支付成功,但订单已取消,需联系客服!'};
}
if (_.round(parseFloat(amount), 2) !== _.round(parseFloat(payResult.totalFee), 2)) {
logger.warn('front pay success but the amount is not same.', {payResult: payResult, order: order});
return {
code: 415,
message: '支付金额与订单金额不一致,订单状态更新失败!'
};
}
if (order.payment_status === 'N') {
logger.warn('front pay success but may be notify fail');
}
if (_.round(parseFloat(amount), 2) !== _.round(parseFloat(payResult.totalFee), 2)) {
logger.warn('front pay success but the amount is not same.', {payResult: payResult, order: order});
return {
code: 200,
message: '支付成功,请等待发货',
data: {
order: order
}
code: 415,
message: '支付金额与订单金额不一致,订单状态更新失败!'
};
} else {
result.message = '未查到订单信息,订单状态更新失败!';
}
return {
code: 200,
message: '支付成功,请等待发货',
data: {
order: order
}
};
} else {
result.message = '未查到订单信息,订单状态更新失败!';
}
return result;
... ...
<div class="cart-bc">
<ul class="breadcrumb">
<li class="level-1{{#isEqual bcNavFocus 1}} current{{/isEqual}}">
<li class="level-1{{#lte 1 bcNavFocus}} current{{/lte}}">
<a href="javascript:void(0)" >
我的购物袋
</a>
</li>
<li class="level-2{{#isEqual bcNavFocus 2}} current{{/isEqual}}">
<li class="level-2{{#lte 2 bcNavFocus}} current{{/lte}}">
<a href="javascript:void(0)" >
填写核对订单信息
</a>
</li>
<li class="level-3{{#isEqual bcNavFocus 3}} current{{/isEqual}} ie8-last-bug">
<li class="level-3{{#lte 3 bcNavFocus}} current{{/lte}} ie8-last-bug">
<a href="javascript:void(0)" >
成功提交订单
</a>
... ...
... ... @@ -7,6 +7,10 @@
margin-bottom: 10px;
}
&.mb20 {
margin-bottom: 20px;
}
&.right {
float: right;
}
... ...
... ... @@ -5,7 +5,7 @@
.msg-left {
position: relative;
float: left;
width: 200px;
width: 180px;
height: 30px;
margin-right: 90px;
line-height: 30px;
... ...
... ... @@ -22,6 +22,8 @@
width: 0;
height: 0;
top: 0;
height: 32px;
overflow: hidden;
}
&:after {
... ... @@ -53,6 +55,7 @@
width: 100%;
display: inline-block;
position: relative;
cursor: default;
}
&:after,
... ... @@ -62,6 +65,8 @@
width: 0;
height: 0;
top: 0;
height: 32px;
overflow: hidden;
}
&:after {
... ...
.pay-fail-page {
.pay-fail-group {
margin: 145px auto;
margin: 100px auto;
text-align: center;
.pay-fail-bg {
... ...
... ... @@ -160,8 +160,8 @@ $fontColor: #616161;
.qr-content-gruop {
width: 300px;
padding: 30px 670px 30px 0;
margin: 0 auto;
padding: 15px 670px 30px 0;
margin: 20px auto;
overflow: hidden;
background: resolve("shopping/w-p-phone.png") no-repeat top right;
}
... ...
/**
* 小于等于
* @param {[Number]} num1
* @param {[Number]} num2
* @param {[object]} options 上下文环境,一般不手动传
* @return {[boolen]}
*/
const lte = function(num1, num2, options) {
num1 = typeof num1 === 'number' ? num1 : parseFloat(num1, 10);
num2 = typeof num2 === 'number' ? num2 : parseFloat(num2, 10);
if (num1 <= num2) {
return options.fn(this);
}
return options.inverse(this);
};
module.exports = {
lte
};
... ...