pingpp-js 2.3.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/alipay_in_weixin/pay.htm +1 -1
- package/dist/pingpp.js +2 -2
- package/gulpfile.js +12 -15
- package/mods.js.tmpl +22 -0
- package/package.json +4 -3
- package/release.md +109 -0
- package/src/agreement.js +2 -2
- package/src/callbacks.js +33 -8
- package/src/channels/yeepay_wap.js +1 -1
- package/src/main.js +196 -0
- package/src/mods.js +27 -6
- package/src/transfer_channels/wx_pub.js +77 -0
- package/src/transfer_elements.js +45 -0
- package/src/version.js +1 -1
- package/src/withdrawal_channels/wx_pub.js +77 -0
- package/src/withdrawal_elements.js +50 -0
- package/test/test.js +54 -3
- package/dist/pingpp.js.map +0 -1
- package/src/channels/pab_pc.js +0 -12
package/src/main.js
CHANGED
|
@@ -15,6 +15,8 @@ var PingppError = require('./errors').Error;
|
|
|
15
15
|
var mods = require('./mods');
|
|
16
16
|
var stash = require('./stash');
|
|
17
17
|
var payment_elements = require('./payment_elements');
|
|
18
|
+
var transfer_elements = require('./transfer_elements');
|
|
19
|
+
var withdrawal_elements = require('./withdrawal_elements');
|
|
18
20
|
|
|
19
21
|
PingppSDK.prototype.createPayment = function (
|
|
20
22
|
chargeJSON, callback, signature, debug
|
|
@@ -144,3 +146,197 @@ PingppSDK.prototype.signAgreement = function (agreement, callback) {
|
|
|
144
146
|
|
|
145
147
|
return module.signAgreement(agreement);
|
|
146
148
|
};
|
|
149
|
+
|
|
150
|
+
PingppSDK.prototype.createTransfer = function (transfer, callback) {
|
|
151
|
+
if (typeof callback === "function") {
|
|
152
|
+
callbacks.userTransferCallback = callback;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
try {
|
|
156
|
+
transfer_elements.init(transfer);
|
|
157
|
+
} catch (e) {
|
|
158
|
+
if (e instanceof PingppError) {
|
|
159
|
+
callbacks.innerTransferCallback(
|
|
160
|
+
"fail",
|
|
161
|
+
callbacks.error(e.message, e.extra),
|
|
162
|
+
);
|
|
163
|
+
return;
|
|
164
|
+
} else {
|
|
165
|
+
throw e;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (!hasOwn.call(transfer_elements, "id")) {
|
|
170
|
+
callbacks.innerTransferCallback(
|
|
171
|
+
"fail",
|
|
172
|
+
callbacks.error("invalid_transfer", "no_transfer_id"),
|
|
173
|
+
);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (!hasOwn.call(transfer_elements, "channel")) {
|
|
178
|
+
callbacks.innerTransferCallback(
|
|
179
|
+
"fail",
|
|
180
|
+
callbacks.error("invalid_transfer", "no_channel"),
|
|
181
|
+
);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (hasOwn.call(transfer_elements, "app")) {
|
|
186
|
+
if (typeof transfer_elements.app === "string") {
|
|
187
|
+
stash.app_id = transfer_elements.app;
|
|
188
|
+
} else if (
|
|
189
|
+
typeof transfer_elements.app === "object" &&
|
|
190
|
+
typeof transfer_elements.app.id === "string"
|
|
191
|
+
) {
|
|
192
|
+
stash.app_id = transfer_elements.app.id;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const channel = transfer_elements.channel;
|
|
197
|
+
if (!hasOwn.call(transfer_elements, "extra")) {
|
|
198
|
+
callbacks.innerTransferCallback(
|
|
199
|
+
"fail",
|
|
200
|
+
callbacks.error("invalid_transfer", "no_credential"),
|
|
201
|
+
);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (transfer_elements.status === "paid") {
|
|
205
|
+
callbacks.innerTransferCallback("success");
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (!transfer_elements.extra) {
|
|
210
|
+
callbacks.innerTransferCallback(
|
|
211
|
+
"fail",
|
|
212
|
+
callbacks.error("invalid_credential", "credential_is_undefined"),
|
|
213
|
+
);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (!hasOwn.call(transfer_elements, "livemode")) {
|
|
218
|
+
callbacks.innerTransferCallback(
|
|
219
|
+
"fail",
|
|
220
|
+
callbacks.error("invalid_transfer", "no_livemode_field"),
|
|
221
|
+
);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const channelModule = mods.getTransferChannelModule(channel);
|
|
225
|
+
if (typeof channelModule === "undefined") {
|
|
226
|
+
console.error('transfer channel module "' + channel + '" is undefined');
|
|
227
|
+
callbacks.innerTransferCallback(
|
|
228
|
+
"fail",
|
|
229
|
+
callbacks.error(
|
|
230
|
+
"invalid_channel",
|
|
231
|
+
'transfer channel module "' + channel + '" is undefined',
|
|
232
|
+
),
|
|
233
|
+
);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
if (transfer_elements.livemode === false) {
|
|
237
|
+
callbacks.innerTransferCallback(
|
|
238
|
+
"fail",
|
|
239
|
+
callbacks.error("invalid_transfer", "testmode_not_supported"),
|
|
240
|
+
);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
channelModule.handleTransfer(transfer_elements);
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
PingppSDK.prototype.createWithdrawal = function (withdrawal, callback) {
|
|
248
|
+
if (typeof callback === "function") {
|
|
249
|
+
callbacks.userWithdrawalCallback = callback;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
try {
|
|
253
|
+
withdrawal_elements.init(withdrawal);
|
|
254
|
+
} catch (e) {
|
|
255
|
+
if (e instanceof PingppError) {
|
|
256
|
+
callbacks.innerWithdrawalCallback(
|
|
257
|
+
"fail",
|
|
258
|
+
callbacks.error(e.message, e.extra),
|
|
259
|
+
);
|
|
260
|
+
return;
|
|
261
|
+
} else {
|
|
262
|
+
throw e;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (!hasOwn.call(withdrawal_elements, "id")) {
|
|
267
|
+
callbacks.innerWithdrawalCallback(
|
|
268
|
+
"fail",
|
|
269
|
+
callbacks.error("invalid_withdrawal", "no_withdrawal_id"),
|
|
270
|
+
);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (!hasOwn.call(withdrawal_elements, "channel")) {
|
|
275
|
+
callbacks.innerWithdrawalCallback(
|
|
276
|
+
"fail",
|
|
277
|
+
callbacks.error("invalid_withdrawal", "no_channel"),
|
|
278
|
+
);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (hasOwn.call(withdrawal_elements, "app")) {
|
|
283
|
+
if (typeof withdrawal_elements.app === "string") {
|
|
284
|
+
stash.app_id = withdrawal_elements.app;
|
|
285
|
+
} else if (
|
|
286
|
+
typeof withdrawal_elements.app === "object" &&
|
|
287
|
+
typeof withdrawal_elements.app.id === "string"
|
|
288
|
+
) {
|
|
289
|
+
stash.app_id = withdrawal_elements.app.id;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const channel = withdrawal_elements.channel;
|
|
294
|
+
if (!hasOwn.call(withdrawal_elements, "extra")) {
|
|
295
|
+
callbacks.innerWithdrawalCallback(
|
|
296
|
+
"fail",
|
|
297
|
+
callbacks.error("invalid_withdrawal", "no_credential"),
|
|
298
|
+
);
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
if (withdrawal_elements.status === "succeeded") {
|
|
302
|
+
callbacks.innerWithdrawalCallback("success");
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (!withdrawal_elements.extra) {
|
|
307
|
+
callbacks.innerWithdrawalCallback(
|
|
308
|
+
"fail",
|
|
309
|
+
callbacks.error("invalid_credential", "credential_is_undefined"),
|
|
310
|
+
);
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (!hasOwn.call(withdrawal_elements, "livemode")) {
|
|
315
|
+
callbacks.innerWithdrawalCallback(
|
|
316
|
+
"fail",
|
|
317
|
+
callbacks.error("invalid_withdrawal", "no_livemode_field"),
|
|
318
|
+
);
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
const channelModule = mods.getWithdrawalChannelModule(channel);
|
|
322
|
+
if (typeof channelModule === "undefined") {
|
|
323
|
+
console.error('withdrawal channel module "' + channel + '" is undefined');
|
|
324
|
+
callbacks.innerWithdrawalCallback(
|
|
325
|
+
"fail",
|
|
326
|
+
callbacks.error(
|
|
327
|
+
"invalid_channel",
|
|
328
|
+
'withdrawal channel module "' + channel + '" is undefined',
|
|
329
|
+
),
|
|
330
|
+
);
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
if (withdrawal_elements.livemode === false) {
|
|
334
|
+
callbacks.innerWithdrawalCallback(
|
|
335
|
+
"fail",
|
|
336
|
+
callbacks.error("invalid_withdrawal", "testmode_not_supported"),
|
|
337
|
+
);
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
channelModule.handleWithdrawal(withdrawal_elements);
|
|
342
|
+
};
|
package/src/mods.js
CHANGED
|
@@ -3,10 +3,10 @@ var mods = {};
|
|
|
3
3
|
module.exports = mods;
|
|
4
4
|
|
|
5
5
|
mods.channels = {
|
|
6
|
-
alipay: require('./channels/alipay'),
|
|
7
|
-
alipay_lite: require('./channels/alipay_lite'),
|
|
8
6
|
abc_pay: require('./channels/abc_pay'),
|
|
9
7
|
abc_pub: require('./channels/abc_pub'),
|
|
8
|
+
alipay: require('./channels/alipay'),
|
|
9
|
+
alipay_lite: require('./channels/alipay_lite'),
|
|
10
10
|
alipay_pc_direct: require('./channels/alipay_pc_direct'),
|
|
11
11
|
alipay_qr: require('./channels/alipay_qr'),
|
|
12
12
|
alipay_qr_lakala: require('./channels/alipay_qr_lakala'),
|
|
@@ -31,7 +31,6 @@ mods.channels = {
|
|
|
31
31
|
jdpay_wap: require('./channels/jdpay_wap'),
|
|
32
32
|
nucc_b2b_lakala: require('./channels/nucc_b2b_lakala'),
|
|
33
33
|
nucc_b2c_lakala: require('./channels/nucc_b2c_lakala'),
|
|
34
|
-
pab_pc: require('./channels/pab_pc'),
|
|
35
34
|
paypal: require('./channels/paypal'),
|
|
36
35
|
qpay_pub: require('./channels/qpay_pub'),
|
|
37
36
|
upacp_b2b: require('./channels/upacp_b2b'),
|
|
@@ -43,10 +42,10 @@ mods.channels = {
|
|
|
43
42
|
wx_pub_pab: require('./channels/wx_pub_pab'),
|
|
44
43
|
wx_wap: require('./channels/wx_wap'),
|
|
45
44
|
yeepay_wap: require('./channels/yeepay_wap'),
|
|
46
|
-
yeepay_wx_pub: require('./channels/yeepay_wx_pub'),
|
|
47
|
-
yeepay_wx_pub_ofl: require('./channels/yeepay_wx_pub'),
|
|
48
45
|
yeepay_wx_lite: require('./channels/yeepay_wx_lite'),
|
|
49
|
-
yeepay_wx_lite_ofl: require('./channels/yeepay_wx_lite_ofl')
|
|
46
|
+
yeepay_wx_lite_ofl: require('./channels/yeepay_wx_lite_ofl'),
|
|
47
|
+
yeepay_wx_pub: require('./channels/yeepay_wx_pub'),
|
|
48
|
+
yeepay_wx_pub_ofl: require('./channels/yeepay_wx_pub_ofl')
|
|
50
49
|
};
|
|
51
50
|
|
|
52
51
|
mods.extras = {
|
|
@@ -54,6 +53,14 @@ mods.extras = {
|
|
|
54
53
|
agreement: require('./agreement')
|
|
55
54
|
};
|
|
56
55
|
|
|
56
|
+
mods.transferChannels = {
|
|
57
|
+
wx_pub: require('./transfer_channels/wx_pub'),
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
mods.withdrawalChannels = {
|
|
61
|
+
wx_pub: require('./withdrawal_channels/wx_pub'),
|
|
62
|
+
}
|
|
63
|
+
|
|
57
64
|
mods.getChannelModule = function(channel) {
|
|
58
65
|
if (hasOwn.call(mods.channels, channel)) {
|
|
59
66
|
return mods.channels[channel];
|
|
@@ -61,6 +68,20 @@ mods.getChannelModule = function(channel) {
|
|
|
61
68
|
return undefined;
|
|
62
69
|
};
|
|
63
70
|
|
|
71
|
+
mods.getTransferChannelModule = function(channel) {
|
|
72
|
+
if (hasOwn.call(mods.transferChannels, channel)) {
|
|
73
|
+
return mods.transferChannels[channel];
|
|
74
|
+
}
|
|
75
|
+
return undefined;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
mods.getWithdrawalChannelModule = function(channel) {
|
|
79
|
+
if (hasOwn.call(mods.withdrawalChannels, channel)) {
|
|
80
|
+
return mods.withdrawalChannels[channel];
|
|
81
|
+
}
|
|
82
|
+
return undefined;
|
|
83
|
+
};
|
|
84
|
+
|
|
64
85
|
mods.getExtraModule = function(name) {
|
|
65
86
|
if (hasOwn.call(mods.extras, name)) {
|
|
66
87
|
return mods.extras[name];
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
var callbacks = require('../callbacks');
|
|
2
|
+
var stash = require('../stash');
|
|
3
|
+
var mods = require('../mods');
|
|
4
|
+
var hasOwn = {}.hasOwnProperty;
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
handleTransfer: function(transfer) {
|
|
8
|
+
const credential = {};
|
|
9
|
+
const fields = [
|
|
10
|
+
'appId', 'mchId', 'package'
|
|
11
|
+
];
|
|
12
|
+
for (let k = 0; k < fields.length; k++) {
|
|
13
|
+
if (!hasOwn.call(transfer.extra, fields[k])) {
|
|
14
|
+
callbacks.innerTransferCallback('fail', callbacks.error('invalid_credential', 'missing_field_' + fields[k]));
|
|
15
|
+
console.error(fields[k]);
|
|
16
|
+
return;
|
|
17
|
+
} else {
|
|
18
|
+
credential[fields[k]] = transfer.extra[fields[k]];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
stash.jsApiParameters = credential;
|
|
22
|
+
this.callTransfer();
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
callTransfer: function() {
|
|
26
|
+
const self = this;
|
|
27
|
+
const wx_jssdk = mods.getExtraModule('wx_jssdk');
|
|
28
|
+
if (typeof wx_jssdk !== 'undefined' && wx_jssdk.jssdkEnabled()) {
|
|
29
|
+
wx_jssdk.callpay();
|
|
30
|
+
} else if (typeof WeixinJSBridge === 'undefined') {
|
|
31
|
+
const eventCallback = function () {
|
|
32
|
+
self.jsApiCall();
|
|
33
|
+
};
|
|
34
|
+
if (typeof document === 'undefined') {
|
|
35
|
+
callbacks.innerTransferCallback(
|
|
36
|
+
"fail",
|
|
37
|
+
callbacks.error(
|
|
38
|
+
"invalid_environment",
|
|
39
|
+
"document_is_undefined",
|
|
40
|
+
),
|
|
41
|
+
);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (document.addEventListener) {
|
|
45
|
+
document.addEventListener('WeixinJSBridgeReady',
|
|
46
|
+
eventCallback, false);
|
|
47
|
+
} else if (document.attachEvent) {
|
|
48
|
+
document.attachEvent('WeixinJSBridgeReady', eventCallback);
|
|
49
|
+
document.attachEvent('onWeixinJSBridgeReady', eventCallback);
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
this.jsApiCall();
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
jsApiCall: function() {
|
|
57
|
+
if (hasOwn.call(stash, 'jsApiParameters')) {
|
|
58
|
+
WeixinJSBridge.invoke(
|
|
59
|
+
'requestMerchantTransfer',
|
|
60
|
+
stash.jsApiParameters,
|
|
61
|
+
function(res) {
|
|
62
|
+
delete stash.jsApiParameters;
|
|
63
|
+
if (res.err_msg === 'requestMerchantTransfer:ok') {
|
|
64
|
+
callbacks.innerTransferCallback("success");
|
|
65
|
+
} else if (res.err_msg === 'requestMerchantTransfer:cancel') {
|
|
66
|
+
callbacks.innerTransferCallback("cancel");
|
|
67
|
+
} else {
|
|
68
|
+
callbacks.innerTransferCallback(
|
|
69
|
+
"fail",
|
|
70
|
+
callbacks.error("wx_result_fail", res.err_msg),
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var PingppError = require('./errors').Error;
|
|
2
|
+
var hasOwn = {}.hasOwnProperty;
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
id: null,
|
|
6
|
+
channel: null,
|
|
7
|
+
app: null,
|
|
8
|
+
extra: null,
|
|
9
|
+
livemode: null,
|
|
10
|
+
order_no: null,
|
|
11
|
+
time_expire: null,
|
|
12
|
+
status: null,
|
|
13
|
+
|
|
14
|
+
init: function (params) {
|
|
15
|
+
let transfer;
|
|
16
|
+
if (typeof params === 'string') {
|
|
17
|
+
try {
|
|
18
|
+
transfer = JSON.parse(params);
|
|
19
|
+
} catch (err) {
|
|
20
|
+
throw new PingppError('json_decode_fail', err);
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
transfer = params;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (typeof transfer === 'undefined') {
|
|
27
|
+
throw new PingppError('json_decode_fail');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
for (var key in this) {
|
|
31
|
+
if (hasOwn.call(transfer, key)) {
|
|
32
|
+
this[key] = transfer[key];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return this;
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
clear: function () {
|
|
39
|
+
for (var key in this) {
|
|
40
|
+
if (typeof this[key] !== 'function') {
|
|
41
|
+
this[key] = null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
package/src/version.js
CHANGED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
var callbacks = require('../callbacks');
|
|
2
|
+
var stash = require('../stash');
|
|
3
|
+
var mods = require('../mods');
|
|
4
|
+
var hasOwn = {}.hasOwnProperty;
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
handleWithdrawal: function(withdrawal) {
|
|
8
|
+
const credential = {};
|
|
9
|
+
const fields = [
|
|
10
|
+
'appId', 'mchId', 'package'
|
|
11
|
+
];
|
|
12
|
+
for (let k = 0; k < fields.length; k++) {
|
|
13
|
+
if (!hasOwn.call(withdrawal.extra, fields[k])) {
|
|
14
|
+
callbacks.innerWithdrawalCallback('fail', callbacks.error('invalid_credential', 'missing_field_' + fields[k]));
|
|
15
|
+
console.error(fields[k]);
|
|
16
|
+
return;
|
|
17
|
+
} else {
|
|
18
|
+
credential[fields[k]] = withdrawal.extra[fields[k]];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
stash.jsApiParameters = credential;
|
|
22
|
+
this.callWithdrawal();
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
callWithdrawal: function() {
|
|
26
|
+
const self = this;
|
|
27
|
+
const wx_jssdk = mods.getExtraModule('wx_jssdk');
|
|
28
|
+
if (typeof wx_jssdk !== 'undefined' && wx_jssdk.jssdkEnabled()) {
|
|
29
|
+
wx_jssdk.callpay();
|
|
30
|
+
} else if (typeof WeixinJSBridge === 'undefined') {
|
|
31
|
+
const eventCallback = function () {
|
|
32
|
+
self.jsApiCall();
|
|
33
|
+
};
|
|
34
|
+
if (typeof document === 'undefined') {
|
|
35
|
+
callbacks.innerWithdrawalCallback(
|
|
36
|
+
"fail",
|
|
37
|
+
callbacks.error(
|
|
38
|
+
"invalid_environment",
|
|
39
|
+
"document_is_undefined",
|
|
40
|
+
),
|
|
41
|
+
);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (document.addEventListener) {
|
|
45
|
+
document.addEventListener('WeixinJSBridgeReady',
|
|
46
|
+
eventCallback, false);
|
|
47
|
+
} else if (document.attachEvent) {
|
|
48
|
+
document.attachEvent('WeixinJSBridgeReady', eventCallback);
|
|
49
|
+
document.attachEvent('onWeixinJSBridgeReady', eventCallback);
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
this.jsApiCall();
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
jsApiCall: function() {
|
|
57
|
+
if (hasOwn.call(stash, 'jsApiParameters')) {
|
|
58
|
+
WeixinJSBridge.invoke(
|
|
59
|
+
'requestMerchantTransfer',
|
|
60
|
+
stash.jsApiParameters,
|
|
61
|
+
function(res) {
|
|
62
|
+
delete stash.jsApiParameters;
|
|
63
|
+
if (res.err_msg === 'requestMerchantTransfer:ok') {
|
|
64
|
+
callbacks.innerWithdrawalCallback("success");
|
|
65
|
+
} else if (res.err_msg === 'requestMerchantTransfer:cancel') {
|
|
66
|
+
callbacks.innerWithdrawalCallback("cancel");
|
|
67
|
+
} else {
|
|
68
|
+
callbacks.innerWithdrawalCallback(
|
|
69
|
+
"fail",
|
|
70
|
+
callbacks.error("wx_result_fail", res.err_msg),
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
var PingppError = require('./errors').Error;
|
|
2
|
+
var hasOwn = {}.hasOwnProperty;
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
id: null,
|
|
6
|
+
object: null,
|
|
7
|
+
channel: null,
|
|
8
|
+
app: null,
|
|
9
|
+
extra: null,
|
|
10
|
+
livemode: null,
|
|
11
|
+
order_no: null,
|
|
12
|
+
status: null,
|
|
13
|
+
amount: null,
|
|
14
|
+
description: null,
|
|
15
|
+
failure_msg: null,
|
|
16
|
+
time_canceled: null,
|
|
17
|
+
time_succeeded: null,
|
|
18
|
+
|
|
19
|
+
init: function (params) {
|
|
20
|
+
var withdrawal;
|
|
21
|
+
if (typeof params === 'string') {
|
|
22
|
+
try {
|
|
23
|
+
withdrawal = JSON.parse(params);
|
|
24
|
+
} catch (err) {
|
|
25
|
+
throw new PingppError('json_decode_fail', err);
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
withdrawal = params;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (typeof withdrawal === 'undefined') {
|
|
32
|
+
throw new PingppError('json_decode_fail');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
for (var key in this) {
|
|
36
|
+
if (hasOwn.call(withdrawal, key)) {
|
|
37
|
+
this[key] = withdrawal[key];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return this;
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
clear: function () {
|
|
44
|
+
for (var key in this) {
|
|
45
|
+
if (typeof this[key] !== 'function') {
|
|
46
|
+
this[key] = null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
package/test/test.js
CHANGED
|
@@ -5,17 +5,68 @@ module.exports = {
|
|
|
5
5
|
pingpp: undefined,
|
|
6
6
|
|
|
7
7
|
run: function() {
|
|
8
|
-
|
|
8
|
+
const version = require('../package.json').version;
|
|
9
9
|
this.pingpp = require('../src/main.js');
|
|
10
|
-
if (version
|
|
10
|
+
if (version !== this.pingpp.version) {
|
|
11
11
|
console.error('Version number does not match.');
|
|
12
12
|
} else {
|
|
13
|
-
console.log(
|
|
13
|
+
console.log(`Version: ${this.pingpp.version}`);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
this.testCharge();
|
|
17
17
|
this.testChargeCcbWap();
|
|
18
18
|
this.testAgreement();
|
|
19
|
+
this.testTransfer();
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
testTransfer: function () {
|
|
23
|
+
console.log('running transfer test...');
|
|
24
|
+
|
|
25
|
+
const transfer = {
|
|
26
|
+
"id": "tr_131250327649096837120006",
|
|
27
|
+
"object": "transfer",
|
|
28
|
+
"type": "b2c",
|
|
29
|
+
"created": 1743068187,
|
|
30
|
+
"time_transferred": null,
|
|
31
|
+
"livemode": true,
|
|
32
|
+
"status": "wait_user_confirm",
|
|
33
|
+
"app": "app_1Gqj58ynP0mHeX1q",
|
|
34
|
+
"channel": "wx_pub",
|
|
35
|
+
"order_no": "912111743068187",
|
|
36
|
+
"batch_no": null,
|
|
37
|
+
"amount": 10,
|
|
38
|
+
"amount_settle": 10,
|
|
39
|
+
"currency": "cny",
|
|
40
|
+
"recipient": "otdLiw0bx_HJUALDp_dzAAjp7BCA",
|
|
41
|
+
"description": "转账测试",
|
|
42
|
+
"transaction_no": "1330000139344692503270012303775666",
|
|
43
|
+
"failure_msg": null,
|
|
44
|
+
"extra": {
|
|
45
|
+
"scene_id": "1005",
|
|
46
|
+
"product_code": "fund-app",
|
|
47
|
+
"scene_report_info": [
|
|
48
|
+
{
|
|
49
|
+
"info_type": "岗位类型",
|
|
50
|
+
"info_content": "测试"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"info_type": "报酬说明",
|
|
54
|
+
"info_content": "测试"
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
"package": "ABBQO+oYAAABAAAAAADBGUx8UBAabcdHHhzlZxAAAADnGabcZahT9IkJjn90+abcRXA0BwkohpO9+F1BLQuBl2pCXphJtQK18bS/ShfGsIUmr1UTByVyMKCC/0/aUmIbP9y7Q8s7qutM1gFiMDRKQbtU2ks=",
|
|
58
|
+
"mchId": "1250015000",
|
|
59
|
+
"appId": "wx9cfac8008001600"
|
|
60
|
+
},
|
|
61
|
+
"metadata": {}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const ret = this.pingpp.createTransfer(transfer, (result, error) => {
|
|
65
|
+
console.log(result);
|
|
66
|
+
console.log(error);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
console.log(ret);
|
|
19
70
|
},
|
|
20
71
|
|
|
21
72
|
testCharge: function () {
|