|
|
@@ -19,8 +19,18 @@ function requestPayment(params) {
|
|
|
}));
|
|
|
}
|
|
|
|
|
|
+function prepareWithDeadline(work) {
|
|
|
+ let timer;
|
|
|
+ return Promise.race([
|
|
|
+ work,
|
|
|
+ new Promise((_, reject) => {
|
|
|
+ timer = setTimeout(() => reject({ code: 'timeout' }), 25000);
|
|
|
+ }),
|
|
|
+ ]).finally(() => clearTimeout(timer));
|
|
|
+}
|
|
|
+
|
|
|
Page({
|
|
|
- data: { title: '确认微信支付', amount: '', paying: false, valid: false, error: '' },
|
|
|
+ data: { title: '确认微信支付', amount: '', paying: false, statusText: '', valid: false, error: '' },
|
|
|
|
|
|
onLoad(options) {
|
|
|
const { orderId, kind } = options;
|
|
|
@@ -49,14 +59,15 @@ Page({
|
|
|
this.setData({ error: '请在小程序登录同一账号,然后返回订单重试。' });
|
|
|
return;
|
|
|
}
|
|
|
- this.setData({ paying: true, error: '' });
|
|
|
+ this.setData({ paying: true, statusText: '正在核对订单…', error: '' });
|
|
|
let phase = 'prepare';
|
|
|
try {
|
|
|
- const params = await Parse.Cloud.run('prepareYubanMiniPayment', {
|
|
|
- ...this.payment, loginCode: await loginCode(),
|
|
|
- });
|
|
|
+ const params = await prepareWithDeadline(loginCode().then(code => Parse.Cloud.run('prepareYubanMiniPayment', {
|
|
|
+ ...this.payment, loginCode: code,
|
|
|
+ })));
|
|
|
if (this.returned) return;
|
|
|
phase = 'cashier';
|
|
|
+ this.setData({ statusText: '正在打开微信收银台…' });
|
|
|
await requestPayment(params);
|
|
|
this.finish('submitted');
|
|
|
} catch (error) {
|
|
|
@@ -66,11 +77,13 @@ Page({
|
|
|
} else {
|
|
|
this.setData({ error: phase === 'cashier' ? '微信支付未完成,请返回核对订单。' :
|
|
|
error?.code === 209 ? '小程序微信身份与订单账号不一致,请重新登录。' :
|
|
|
- error?.code === 142 ? '订单或收银台参数无法确认,请返回核对。' : '暂时无法打开微信支付,请稍后重试。' });
|
|
|
+ error?.code === 142 ? '订单或收银台参数无法确认,请返回核对。' :
|
|
|
+ error?.code === 141 ? '小程序支付服务暂未接通,请稍后再试。' :
|
|
|
+ error?.code === 'timeout' ? '订单核对超时。请稍后重试同一订单。' : '暂时无法打开微信支付,请稍后重试。' });
|
|
|
}
|
|
|
}
|
|
|
} finally {
|
|
|
- if (!this.returned) this.setData({ paying: false });
|
|
|
+ if (!this.returned) this.setData({ paying: false, statusText: '' });
|
|
|
}
|
|
|
},
|
|
|
|