unionpay.js
1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* @author: xiaoxiao.hao<xiaoxiao.hao@yoho.cn>
* @date: 2017/3/23
*/
'use strict';
const ServiceAPI = global.yoho.ServiceAPI;
const helpers = global.yoho.helpers;
const PAY_URL = 'https://gateway.95516.com/gateway/api/frontTransReq.do';
const Unionpay = {
pay(user, order, info) {
return ServiceAPI.get('payment/unionpay_data', {
order_code: order.order_code,
payment_code: info.id,
uid: user.uid,
front_url: info.protocol + ':' + helpers.urlFormat('/shopping/pay/callback/unionpay')
}).then(result => {
if (result && result.code === 200 && result.data) {
return {
code: 200, // reqType是post方式,默认
data: Object.assign({reqType: PAY_URL}, result.data)
};
}
return {
code: 400,
message: result.message
};
});
},
notify(data) {
let orderCode = parseInt(data.orderId, 10);
// https://open.unionpay.com/ajweb/help/faq/list?id=234&level=0&from=0
if (!data.respCode || (data.respCode.indexOf('00') < 0 && data.respCode.indexOf('A6') < 0)) {
return {payResult: -1};
}
return {
bankName: '',
orderCode: orderCode,
payResult: 200,
totalFee: data.txnAmt * 0.01,
tradeNo: data.queryId,
bankBillNo: ''
};
}
};
module.exports = Unionpay;