-
Notifications
You must be signed in to change notification settings - Fork 176
/
qpay_pub.js
47 lines (43 loc) · 1.26 KB
/
qpay_pub.js
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
var callbacks = require('../callbacks');
var utils = require('../utils');
var stash = require('../stash');
var hasOwn = {}.hasOwnProperty;
/*global mqq*/
module.exports = {
SRC_URL: 'https://open.mobile.qq.com/sdk/qqapi.js?_bid=152',
ID: 'mqq_api',
handleCharge: function (charge) {
var credential = charge.credential[charge.channel];
if (!hasOwn.call(credential, 'token_id')) {
callbacks.innerCallback('fail',
callbacks.error('invalid_credential', 'missing_token_id'));
return;
}
stash.tokenId = credential.token_id;
utils.loadUrlJs(this.ID, this.SRC_URL, this.callpay);
},
callpay: function () {
if (typeof mqq != 'undefined') {
if (mqq.QQVersion == 0) {
callbacks.innerCallback('fail',
callbacks.error('Not in the QQ client'));
delete stash.tokenId;
return;
}
mqq.tenpay.pay({
tokenId: stash.tokenId
}, function (result) {
if (result.resultCode == 0) {
callbacks.innerCallback('success');
} else {
callbacks.innerCallback('fail',
callbacks.error(result.retmsg));
}
});
} else {
callbacks.innerCallback('fail',
callbacks.error('network_err'));
}
delete stash.tokenId;
}
};