mirror of
https://github.com/perfect-panel/ppanel-web.git
synced 2026-02-17 05:41:10 -05:00
🐛 fix(payment): Refactor purchaseCheckout usage and remove redundant code
This commit is contained in:
parent
35f92c9329
commit
a5e2079ddc
@ -49,12 +49,15 @@ export default function Page() {
|
|||||||
|
|
||||||
const { data: payment } = useQuery({
|
const { data: payment } = useQuery({
|
||||||
enabled: !!orderNo && data?.status === 1,
|
enabled: !!orderNo && data?.status === 1,
|
||||||
queryKey: ['checkoutOrder', orderNo],
|
queryKey: ['purchaseCheckout', orderNo],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const { data } = await purchaseCheckout({
|
const { data } = await purchaseCheckout({
|
||||||
orderNo: orderNo!,
|
orderNo: orderNo!,
|
||||||
returnUrl: window.location.href,
|
returnUrl: window.location.href,
|
||||||
});
|
});
|
||||||
|
if (data.data?.type === 'link' && data.data.checkout_url) {
|
||||||
|
window.location.href = data.data.checkout_url;
|
||||||
|
}
|
||||||
return data?.data;
|
return data?.data;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import DurationSelector from '@/components/subscribe/duration-selector';
|
|||||||
import PaymentMethods from '@/components/subscribe/payment-methods';
|
import PaymentMethods from '@/components/subscribe/payment-methods';
|
||||||
import useGlobalStore from '@/config/use-global';
|
import useGlobalStore from '@/config/use-global';
|
||||||
import { preCreateOrder, purchase } from '@/services/user/order';
|
import { preCreateOrder, purchase } from '@/services/user/order';
|
||||||
import { purchaseCheckout } from '@/services/user/portal';
|
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { Button } from '@workspace/ui/components/button';
|
import { Button } from '@workspace/ui/components/button';
|
||||||
import { Card, CardContent } from '@workspace/ui/components/card';
|
import { Card, CardContent } from '@workspace/ui/components/card';
|
||||||
@ -70,20 +69,11 @@ export default function Purchase({ subscribe, setSubscribe }: Readonly<PurchaseP
|
|||||||
const response = await purchase(params as API.PurchaseOrderRequest);
|
const response = await purchase(params as API.PurchaseOrderRequest);
|
||||||
const orderNo = response.data.data?.order_no;
|
const orderNo = response.data.data?.order_no;
|
||||||
if (orderNo) {
|
if (orderNo) {
|
||||||
const { data } = await purchaseCheckout({
|
|
||||||
orderNo,
|
|
||||||
returnUrl: `${window.location.origin}/payment?order_no=${orderNo}`,
|
|
||||||
});
|
|
||||||
const type = data.data?.type;
|
|
||||||
const checkout_url = data.data?.checkout_url;
|
|
||||||
if (type === 'link') {
|
|
||||||
window.location.href = checkout_url!;
|
|
||||||
}
|
|
||||||
getUserInfo();
|
getUserInfo();
|
||||||
router.push(`/payment?order_no=${orderNo}`);
|
router.push(`/payment?order_no=${orderNo}`);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
/* empty */
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, [params, router, getUserInfo]);
|
}, [params, router, getUserInfo]);
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
import useGlobalStore from '@/config/use-global';
|
import useGlobalStore from '@/config/use-global';
|
||||||
import { recharge } from '@/services/user/order';
|
import { recharge } from '@/services/user/order';
|
||||||
import { getAvailablePaymentMethods } from '@/services/user/payment';
|
import { getAvailablePaymentMethods } from '@/services/user/payment';
|
||||||
import { purchaseCheckout } from '@/services/user/portal';
|
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { Button, ButtonProps } from '@workspace/ui/components/button';
|
import { Button, ButtonProps } from '@workspace/ui/components/button';
|
||||||
import {
|
import {
|
||||||
@ -134,15 +133,6 @@ export default function Recharge(props: Readonly<ButtonProps>) {
|
|||||||
const response = await recharge(params);
|
const response = await recharge(params);
|
||||||
const orderNo = response.data.data?.order_no;
|
const orderNo = response.data.data?.order_no;
|
||||||
if (orderNo) {
|
if (orderNo) {
|
||||||
const { data } = await purchaseCheckout({
|
|
||||||
orderNo,
|
|
||||||
returnUrl: `${window.location.origin}/payment?order_no=${orderNo}`,
|
|
||||||
});
|
|
||||||
const type = data.data?.type;
|
|
||||||
const checkout_url = data.data?.checkout_url;
|
|
||||||
if (type === 'link') {
|
|
||||||
window.location.href = checkout_url!;
|
|
||||||
}
|
|
||||||
router.push(`/payment?order_no=${orderNo}`);
|
router.push(`/payment?order_no=${orderNo}`);
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import DurationSelector from '@/components/subscribe/duration-selector';
|
|||||||
import PaymentMethods from '@/components/subscribe/payment-methods';
|
import PaymentMethods from '@/components/subscribe/payment-methods';
|
||||||
import useGlobalStore from '@/config/use-global';
|
import useGlobalStore from '@/config/use-global';
|
||||||
import { preCreateOrder, renewal } from '@/services/user/order';
|
import { preCreateOrder, renewal } from '@/services/user/order';
|
||||||
import { purchaseCheckout } from '@/services/user/portal';
|
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { Button } from '@workspace/ui/components/button';
|
import { Button } from '@workspace/ui/components/button';
|
||||||
import { Card, CardContent } from '@workspace/ui/components/card';
|
import { Card, CardContent } from '@workspace/ui/components/card';
|
||||||
@ -78,20 +77,11 @@ export default function Renewal({ id, subscribe }: Readonly<RenewalProps>) {
|
|||||||
const response = await renewal(params as API.RenewalOrderRequest);
|
const response = await renewal(params as API.RenewalOrderRequest);
|
||||||
const orderNo = response.data.data?.order_no;
|
const orderNo = response.data.data?.order_no;
|
||||||
if (orderNo) {
|
if (orderNo) {
|
||||||
const { data } = await purchaseCheckout({
|
|
||||||
orderNo,
|
|
||||||
returnUrl: `${window.location.origin}/payment?order_no=${orderNo}`,
|
|
||||||
});
|
|
||||||
const type = data.data?.type;
|
|
||||||
const checkout_url = data.data?.checkout_url;
|
|
||||||
if (type === 'link') {
|
|
||||||
window.location.href = checkout_url!;
|
|
||||||
}
|
|
||||||
getUserInfo();
|
getUserInfo();
|
||||||
router.push(`/payment?order_no=${orderNo}`);
|
router.push(`/payment?order_no=${orderNo}`);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
/* empty */
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, [params, router, getUserInfo]);
|
}, [params, router, getUserInfo]);
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
import { Display } from '@/components/display';
|
import { Display } from '@/components/display';
|
||||||
import useGlobalStore from '@/config/use-global';
|
import useGlobalStore from '@/config/use-global';
|
||||||
import { resetTraffic } from '@/services/user/order';
|
import { resetTraffic } from '@/services/user/order';
|
||||||
import { purchaseCheckout } from '@/services/user/portal';
|
|
||||||
import { Button } from '@workspace/ui/components/button';
|
import { Button } from '@workspace/ui/components/button';
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
@ -85,15 +84,6 @@ export default function ResetTraffic({ id, replacement }: Readonly<ResetTrafficP
|
|||||||
const response = await resetTraffic(params);
|
const response = await resetTraffic(params);
|
||||||
const orderNo = response.data.data?.order_no;
|
const orderNo = response.data.data?.order_no;
|
||||||
if (orderNo) {
|
if (orderNo) {
|
||||||
const { data } = await purchaseCheckout({
|
|
||||||
orderNo,
|
|
||||||
returnUrl: `${window.location.origin}/payment?order_no=${orderNo}`,
|
|
||||||
});
|
|
||||||
const type = data.data?.type;
|
|
||||||
const checkout_url = data.data?.checkout_url;
|
|
||||||
if (type === 'link') {
|
|
||||||
window.location.href = checkout_url!;
|
|
||||||
}
|
|
||||||
getUserInfo();
|
getUserInfo();
|
||||||
router.push(`/payment?order_no=${orderNo}`);
|
router.push(`/payment?order_no=${orderNo}`);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user