| 185 | }; |
| 186 | |
| 187 | const onlineTopUp = async () => { |
| 188 | if (amount === 0) { |
| 189 | await getAmount(); |
| 190 | } |
| 191 | if (topUpCount < minTopUp) { |
| 192 | showError('充值数量不能小于' + minTopUp); |
| 193 | return; |
| 194 | } |
| 195 | setConfirmLoading(true); |
| 196 | try { |
| 197 | const res = await API.post('/api/user/pay', { |
| 198 | amount: parseInt(topUpCount), |
| 199 | top_up_code: topUpCode, |
| 200 | payment_method: payWay, |
| 201 | }); |
| 202 | if (res !== undefined) { |
| 203 | const { message, data } = res.data; |
| 204 | if (message === 'success') { |
| 205 | let params = data; |
| 206 | let url = res.data.url; |
| 207 | let form = document.createElement('form'); |
| 208 | form.action = url; |
| 209 | form.method = 'POST'; |
| 210 | let isSafari = |
| 211 | navigator.userAgent.indexOf('Safari') > -1 && |
| 212 | navigator.userAgent.indexOf('Chrome') < 1; |
| 213 | if (!isSafari) { |
| 214 | form.target = '_blank'; |
| 215 | } |
| 216 | for (let key in params) { |
| 217 | let input = document.createElement('input'); |
| 218 | input.type = 'hidden'; |
| 219 | input.name = key; |
| 220 | input.value = params[key]; |
| 221 | form.appendChild(input); |
| 222 | } |
| 223 | document.body.appendChild(form); |
| 224 | form.submit(); |
| 225 | document.body.removeChild(form); |
| 226 | } else { |
| 227 | showError(data); |
| 228 | } |
| 229 | } else { |
| 230 | showError(res); |
| 231 | } |
| 232 | } catch (err) { |
| 233 | console.log(err); |
| 234 | showError(t('支付请求失败')); |
| 235 | } finally { |
| 236 | setOpen(false); |
| 237 | setConfirmLoading(false); |
| 238 | } |
| 239 | }; |
| 240 | |
| 241 | const stripePreTopUp = async () => { |
| 242 | if (!enableStripeTopUp) { |