pay order
This commit is contained in:
@@ -54,7 +54,7 @@ export const ShippingSection = ({ deliveryType, onDeliveryTypeChange }: Shipping
|
||||
onSuccess: () => {
|
||||
setTimeout(() => {
|
||||
setIsSelectedShipment(true);
|
||||
}, 500);
|
||||
}, 200);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { ChevronLeft } from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useCheckoutStore } from '../../store/Store';
|
||||
import { toast } from '@/components/Toast';
|
||||
import { useCreateOrder } from '../../hooks/useOrderData';
|
||||
import { useConfirmOrder, useCreateOrder } from '../../hooks/useOrderData';
|
||||
import { extractErrorMessage } from '@/lib/func';
|
||||
import { useParams } from 'next/navigation';
|
||||
import { useGetCartItems } from '@/app/[name]/(Dialogs)/cart/hooks/useCartData';
|
||||
@@ -26,6 +26,7 @@ export const SummarySection = ({ cartModal, onToggleCartModal, deliveryType }: S
|
||||
const { t } = useTranslation('parallels', { keyPrefix: 'OrderDetail' });
|
||||
const { isSelectedAddress, isSelectedShipment, isSelectedPayment } = useCheckoutStore();
|
||||
const { mutate: createOrder } = useCreateOrder();
|
||||
const { mutate: confirmOrder } = useConfirmOrder();
|
||||
const params = useParams();
|
||||
const name = params.name as string;
|
||||
const { isSuccess } = useGetProfile();
|
||||
@@ -68,13 +69,20 @@ export const SummarySection = ({ cartModal, onToggleCartModal, deliveryType }: S
|
||||
|
||||
createOrder(undefined, {
|
||||
onSuccess: (data) => {
|
||||
if (data?.data?.paymentUrl) {
|
||||
window.location.href = data?.data?.paymentUrl;
|
||||
toast('در حال ریدایرکت به صفحه پرداخت...', 'success');
|
||||
} else {
|
||||
window.location.href = `/${name}/verify/${data?.data?.order?.id}`;
|
||||
toast('سفارش با موفقیت ثبت شد', 'success');
|
||||
}
|
||||
confirmOrder(data?.data?.order?.id, {
|
||||
onSuccess: (payment) => {
|
||||
if (payment?.data?.paymentUrl) {
|
||||
window.location.href = payment?.data?.paymentUrl;
|
||||
toast('در حال ریدایرکت به صفحه پرداخت...', 'success');
|
||||
} else {
|
||||
window.location.href = `/${name}/verify/${data?.data?.order?.id}`;
|
||||
toast('سفارش با موفقیت ثبت شد', 'success');
|
||||
}
|
||||
},
|
||||
onError: (error) => {
|
||||
toast(extractErrorMessage(error), 'error');
|
||||
}
|
||||
});
|
||||
},
|
||||
onError: (error) => {
|
||||
toast(extractErrorMessage(error), 'error');
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
setTableNumber,
|
||||
getOrderDetail,
|
||||
cancelOrder,
|
||||
confirmOrder,
|
||||
} from "../service/OrderService";
|
||||
|
||||
export const useGetShipmentMethod = () => {
|
||||
@@ -92,3 +93,9 @@ export const useCancelOrder = () => {
|
||||
mutationFn: cancelOrder,
|
||||
});
|
||||
};
|
||||
|
||||
export const useConfirmOrder = () => {
|
||||
return useMutation({
|
||||
mutationFn: confirmOrder,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -72,3 +72,8 @@ export const cancelOrder = async (id: string) => {
|
||||
const { data } = await api.patch(`/public/orders/${id}/cancel`);
|
||||
return data;
|
||||
};
|
||||
|
||||
export const confirmOrder = async (id: string) => {
|
||||
const { data } = await api.get(`/public/payments/pay-order/${id}`);
|
||||
return data;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user