From 22e443cf7bf54f9dee283c0a6c1626dab6994cc7 Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Mon, 15 Jun 2026 12:18:25 +0330 Subject: [PATCH] payment with card to card --- src/pages/orders/Details.tsx | 24 +- src/pages/orders/components/OrderActions.tsx | 19 +- src/pages/orders/components/PaymentInfo.tsx | 295 ++++++++---------- .../components/PaymentVerificationBox.tsx | 67 ++++ src/pages/orders/hooks/useOrderData.ts | 4 +- src/pages/orders/service/OrderService.ts | 4 +- src/pages/orders/types/Types.ts | 8 +- 7 files changed, 221 insertions(+), 200 deletions(-) create mode 100644 src/pages/orders/components/PaymentVerificationBox.tsx diff --git a/src/pages/orders/Details.tsx b/src/pages/orders/Details.tsx index 21cf632..6abce8c 100644 --- a/src/pages/orders/Details.tsx +++ b/src/pages/orders/Details.tsx @@ -1,7 +1,7 @@ import { type FC, useState } from 'react' import { useGetOrderById, - useVerifyCashPayment, + useVerifyPayment, useChangeOrderStatus, useRefundPayment } from './hooks/useOrderData' @@ -14,6 +14,7 @@ import ModalConfrim from '@/components/ModalConfrim' import CustomerInfo from './components/CustomerInfo' import OrderItemsDetails from './components/OrderItemsDetails' import PaymentInfo from './components/PaymentInfo' +import PaymentVerificationBox from './components/PaymentVerificationBox' import OrderActions from './components/OrderActions' import { toast } from 'react-toastify' import { extractErrorMessage } from '@/config/func' @@ -22,7 +23,7 @@ import { printOrderReceipt } from './print/orderReceiptPrint' const OrderDetails: FC = () => { const { id } = useParams() const { data: orderData, isLoading } = useGetOrderById(id!) - const { mutate: verifyCashPayment, isPending: isVerifyingPayment } = useVerifyCashPayment() + const { mutate: verifyPayment, isPending: isVerifyingPayment } = useVerifyPayment() const { mutate: changeOrderStatus, isPending: isChangingStatus } = useChangeOrderStatus() const { mutate: refundPayment, isPending: isRefunding } = useRefundPayment() @@ -89,6 +90,7 @@ const OrderDetails: FC = () => { // منطق نمایش دکمه‌ها const isCashPayment = order.paymentMethod?.method === PaymentMethodEnum.Cash + const isCreditCardPayment = order.paymentMethod?.method === PaymentMethodEnum.CreditCard const isPendingPayment = order.status === OrderStatus.PENDING_PAYMENT const isOrderPaid = order.status === OrderStatus.PAID const isPreparing = order.status === OrderStatus.PREPARING @@ -102,9 +104,7 @@ const OrderDetails: FC = () => { const isDineInOrCarDelivery = order.deliveryMethod?.method === DeliveryMethodEnum.DineIn || order.deliveryMethod?.method === DeliveryMethodEnum.DeliveryCar const isCustomerPickup = order.deliveryMethod?.method === DeliveryMethodEnum.CustomerPickup - // نمایش دکمه تایید پرداخت نقدی - // وقتی روش پرداخت نقدی است و وضعیت پرداخت Pending باشد - const showVerifyCashPaymentButton = isCashPayment && isPaymentPending + const showVerifyPaymentBox = (isCashPayment || isCreditCardPayment) && isPaymentPending && !isCanceled // نمایش دکمه ارسال به آشپزخانه // برای pendingPayment با پرداخت نقدی یا برای paid @@ -114,10 +114,10 @@ const OrderDetails: FC = () => { // همیشه نمایش داده می‌شود مگر اینکه سفارش قبلاً کنسل شده باشد const showCancelButton = !isCanceled - const handleVerifyCashPayment = () => { + const handleVerifyPayment = () => { const paymentId = order.paymentId || order.payments?.[0]?.id if (paymentId) { - verifyCashPayment(paymentId, { + verifyPayment(paymentId, { onSuccess: () => { // Success handled by query invalidation }, @@ -232,9 +232,15 @@ const OrderDetails: FC = () => { getPaymentStatusTextColor={getPaymentStatusTextColor} getPaymentStatusText={getPaymentStatusText} /> + {showVerifyPaymentBox && ( + + )} { isDineInOrCarDelivery={isDineInOrCarDelivery} isCustomerPickup={isCustomerPickup} isCanceled={isCanceled} - isVerifyingPayment={isVerifyingPayment} isChangingStatus={isChangingStatus} - onVerifyCashPayment={handleVerifyCashPayment} onSendToKitchen={handleSendToKitchen} onDeliverToCourier={handleDeliverToCourier} onDeliverToWaiter={handleDeliverToWaiter} diff --git a/src/pages/orders/components/OrderActions.tsx b/src/pages/orders/components/OrderActions.tsx index 4d63575..d6970a1 100644 --- a/src/pages/orders/components/OrderActions.tsx +++ b/src/pages/orders/components/OrderActions.tsx @@ -3,7 +3,6 @@ import { type FC, useState, useEffect } from 'react' interface OrderActionsProps { onPrint: () => void - showVerifyCashPaymentButton: boolean showSendToKitchenButton: boolean showCancelButton: boolean isPreparing: boolean @@ -11,9 +10,7 @@ interface OrderActionsProps { isDineInOrCarDelivery: boolean isCustomerPickup: boolean isCanceled: boolean - isVerifyingPayment: boolean isChangingStatus: boolean - onVerifyCashPayment: () => void onSendToKitchen: () => void onDeliverToCourier: () => void onDeliverToWaiter: () => void @@ -23,7 +20,6 @@ interface OrderActionsProps { const OrderActions: FC = ({ onPrint, - showVerifyCashPaymentButton, showSendToKitchenButton, showCancelButton, isPreparing, @@ -31,9 +27,7 @@ const OrderActions: FC = ({ isDineInOrCarDelivery, isCustomerPickup, isCanceled, - isVerifyingPayment, isChangingStatus, - onVerifyCashPayment, onSendToKitchen, onDeliverToCourier, onDeliverToWaiter, @@ -43,10 +37,10 @@ const OrderActions: FC = ({ const [loadingAction, setLoadingAction] = useState(null) useEffect(() => { - if (!isChangingStatus && !isVerifyingPayment) { + if (!isChangingStatus) { setLoadingAction(null) } - }, [isChangingStatus, isVerifyingPayment]) + }, [isChangingStatus]) const handleSendToKitchen = () => { setLoadingAction('sendToKitchen') @@ -81,15 +75,6 @@ const OrderActions: FC = ({ className='bg-slate-700 hover:bg-slate-800' /> - {!isCanceled && showVerifyCashPaymentButton && ( -