unionpay.js
1.6 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
52
53
54
55
56
57
58
59
/**
* @author: xiaoxiao.hao<xiaoxiao.hao@yoho.cn>
* @date: 2017/3/23
*/
'use strict';
const helpers = global.yoho.helpers;
const PAY_URL = 'https://gateway.95516.com/gateway/api/frontTransReq.do';
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
pay(user, order, info) {
let options = {
order_code: order.order_code,
payment_code: info.id,
uid: user.uid,
front_url: 'https:' + helpers.urlFormat('/shopping/newpay/callback/unionpay')
};
return this.get({
api: global.yoho.ServiceAPI,
url: 'payment/unionpay_data',
data: options
}).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: ''
};
}
};