diff --git a/controller/topup_stripe.go b/controller/topup_stripe.go
index 12ca2e4c..c7aa3875 100644
--- a/controller/topup_stripe.go
+++ b/controller/topup_stripe.go
@@ -28,7 +28,6 @@ var stripeAdaptor = &StripeAdaptor{}
type StripePayRequest struct {
Amount int64 `json:"amount"`
PaymentMethod string `json:"payment_method"`
- TopUpCode string `json:"top_up_code"`
}
type StripeAdaptor struct {
diff --git a/web/src/pages/TopUp/index.js b/web/src/pages/TopUp/index.js
index dc986077..929f82ca 100644
--- a/web/src/pages/TopUp/index.js
+++ b/web/src/pages/TopUp/index.js
@@ -59,6 +59,13 @@ const TopUp = () => {
statusState?.status?.enable_online_topup || false,
);
const [priceRatio, setPriceRatio] = useState(statusState?.status?.price || 1);
+
+ const [stripeAmount, setStripeAmount] = useState(0.0);
+ const [stripeMinTopUp, setStripeMinTopUp] = useState(statusState?.status?.stripe_min_topup || 1);
+ const [stripeTopUpCount, setStripeTopUpCount] = useState(statusState?.status?.stripe_min_topup || 1);
+ const [enableStripeTopUp, setEnableStripeTopUp] = useState(statusState?.status?.enable_stripe_topup || false);
+ const [stripeOpen, setStripeOpen] = useState(false);
+
const [userQuota, setUserQuota] = useState(0);
const [isSubmitting, setIsSubmitting] = useState(false);
const [open, setOpen] = useState(false);
@@ -231,6 +238,65 @@ const TopUp = () => {
}
};
+ const stripePreTopUp = async () => {
+ if (!enableStripeTopUp) {
+ showError(t('管理员未开启在线充值!'));
+ return;
+ }
+ setPayWay('stripe')
+ setPaymentLoading(true);
+ try {
+ await getStripeAmount();
+ if (stripeTopUpCount < stripeMinTopUp) {
+ showError(t('充值数量不能小于') + stripeMinTopUp);
+ return;
+ }
+ setStripeOpen(true);
+ } catch (error) {
+ showError(t('获取金额失败'));
+ } finally {
+ setPayWay('')
+ setPaymentLoading(false);
+ }
+ };
+
+ const onlineStripeTopUp = async () => {
+ if (stripeAmount === 0) {
+ await getStripeAmount();
+ }
+ if (stripeTopUpCount < stripeMinTopUp) {
+ showError(t('充值数量不能小于') + stripeMinTopUp);
+ return;
+ }
+ setConfirmLoading(true);
+ try {
+ const res = await API.post('/api/user/stripe/pay', {
+ amount: parseInt(stripeTopUpCount),
+ payment_method: 'stripe',
+ });
+ if (res !== undefined) {
+ const { message, data } = res.data;
+ if (message === 'success') {
+ processStripeCallback(data)
+ } else {
+ showError(data);
+ }
+ } else {
+ showError(res);
+ }
+ } catch (err) {
+ console.log(err);
+ showError(t('支付请求失败'));
+ } finally {
+ setStripeOpen(false);
+ setConfirmLoading(false);
+ }
+ }
+
+ const processStripeCallback = (data) => {
+ location.href = data.pay_link;
+ };
+
const getUserQuota = async () => {
setUserDataLoading(true);
let res = await API.get(`/api/user/self`);
@@ -327,6 +393,10 @@ const TopUp = () => {
setTopUpLink(statusState.status.top_up_link || '');
setEnableOnlineTopUp(statusState.status.enable_online_topup || false);
setPriceRatio(statusState.status.price || 1);
+
+ setStripeMinTopUp(statusState.status.stripe_min_topup || 1);
+ setStripeTopUpCount(statusState.status.stripe_min_topup || 1);
+ setEnableStripeTopUp(statusState.status.enable_stripe_topup || false);
}
}, [statusState?.status]);
@@ -334,6 +404,10 @@ const TopUp = () => {
return amount + ' ' + t('元');
};
+ const renderStripeAmount = () => {
+ return stripeAmount + ' ' + t('元');
+ };
+
const getAmount = async (value) => {
if (value === undefined) {
value = topUpCount;
@@ -361,10 +435,40 @@ const TopUp = () => {
setAmountLoading(false);
};
+ const getStripeAmount = async (value) => {
+ if (value === undefined) {
+ value = stripeTopUpCount
+ }
+ try {
+ const res = await API.post('/api/user/stripe/amount', {
+ amount: parseFloat(value),
+ });
+ if (res !== undefined) {
+ const { message, data } = res.data;
+ // showInfo(message);
+ if (message === 'success') {
+ setStripeAmount(parseFloat(data))
+ } else {
+ setStripeAmount( 0)
+ Toast.error({ content: '错误:' + data, id: 'getAmount' });
+ }
+ } else {
+ showError(res);
+ }
+ } catch (err) {
+ console.log(err);
+ } finally {
+ }
+ }
+
const handleCancel = () => {
setOpen(false);
};
+ const handleStripeCancel = () => {
+ setStripeOpen(false);
+ };
+
const handleTransferCancel = () => {
setOpenTransfer(false);
};
@@ -374,6 +478,9 @@ const TopUp = () => {
setTopUpCount(preset.value);
setSelectedPreset(preset.value);
setAmount(preset.value * priceRatio);
+
+ setStripeTopUpCount(preset.value);
+ setStripeAmount(preset.value);
};
// 格式化大数字显示
@@ -496,6 +603,25 @@ const TopUp = () => {
+
+ {t('充值数量')}:{stripeTopUpCount}
+
+ {t('实付金额')}:{renderStripeAmount()}
+ {t('是否确认充值?')}