-
+
setFormData({...formData, zipCode: e.target.value})}
diff --git a/frontend/application/components/CheckoutPage.tsx b/frontend/application/components/CheckoutPage.tsx
index a037e0e1..1c2ee978 100644
--- a/frontend/application/components/CheckoutPage.tsx
+++ b/frontend/application/components/CheckoutPage.tsx
@@ -74,23 +74,19 @@ export default function CheckoutPage() {
const handleFinalize = async () => {
const totalAmount = getTotal();
-
- if (paymentMethod === 'wallet' && profile.walletBalance < totalAmount) {
- toast.error("اعتبار کیف پول شما کافی نیست. لطفاً ابتدا آن را شارژ کنید یا روش پرداخت دیگری انتخاب کنید.");
- return;
- }
-
setLoading(true);
const activePet = getActivePet();
try {
- // 1. If using wallet, deduct balance and add purchase transaction
- if (paymentMethod === 'wallet') {
- const newBalance = profile.walletBalance - totalAmount;
+ // 1. If using wallet, deduct available balance (up to totalAmount)
+ let walletDeducted = 0;
+ if (paymentMethod === 'wallet' && profile.walletBalance > 0) {
+ walletDeducted = Math.min(profile.walletBalance, totalAmount);
+ const newBalance = profile.walletBalance - walletDeducted;
const newTransaction = {
id: `TR-${Math.floor(Math.random() * 90000) + 10000}`,
type: 'purchase' as const,
- amount: totalAmount,
+ amount: walletDeducted,
date: new Date().toISOString(),
status: 'success' as const
};
@@ -104,11 +100,17 @@ export default function CheckoutPage() {
}
// 2. Register the order in the backend
+ const selectedAddr = profile.addresses?.find(a => a.id === selectedAddressId);
+ const shippingAddressStr = selectedAddr
+ ? `${selectedAddr.province}، ${selectedAddr.city}، ${selectedAddr.detail} (گیرنده: ${selectedAddr.receptorName} - ${toPersian(selectedAddr.phone)})`
+ : manualAddress || undefined;
+
const orderId = await addOrder({
items: [...items],
total: totalAmount,
charityDonation: charityDonation,
- petId: activePet?.id
+ petId: activePet?.id,
+ shippingAddress: shippingAddressStr
});
// 3. Update user charity total
@@ -121,7 +123,7 @@ export default function CheckoutPage() {
}));
}
- // 4. Update pet consumptions for the refill logic
+ // 4. Update pet consumptions and charity contributions for active pet
if (activePet) {
const newConsumptions = [...(activePet.consumptions || [])];
@@ -139,12 +141,14 @@ export default function CheckoutPage() {
}
});
- updatePet(activePet.id, { consumptions: newConsumptions });
+ updatePet(activePet.id, {
+ consumptions: newConsumptions
+ });
}
clearCart();
- toast.success("سفارش شما با موفقیت ثبت شد و به پرونده سلامت همدمتان اضافه شد!");
- router.push('/dashboard');
+ toast.success("سفارش شما با موفقیت ثبت شد!");
+ router.push(`/checkout/success/${orderId}`);
} catch (err: any) {
toast.error(err.message || "خطا در ثبت سفارش. لطفاً مجدداً تلاش کنید.");
} finally {
@@ -310,23 +314,26 @@ export default function CheckoutPage() {
{[
- { id: 'online', label: 'پرداخت آنلاین', desc: 'کارتهای بانکی', icon:
},
- { id: 'wallet', label: 'اعتبار حساب', desc: 'شارژ شده اختصاصی', icon:
},
+ { id: 'online', label: 'پرداخت آنلاین', desc: 'کارتهای بانکی عضو شتاب', icon:
},
+ {
+ id: 'wallet',
+ label: 'اعتبار حساب (کیف پول)',
+ desc: `موجودی: ${toPersian((profile.walletBalance || 0).toLocaleString())} تومان`,
+ icon:
+ },
{ id: 'cod', label: 'پرداخت در محل', desc: 'فقط تهران', icon:
}
].map((pay) => (
{
- setPaymentMethod(pay.id);
- }}
+ onClick={() => setPaymentMethod(pay.id)}
className={cn("p-4 sm:p-6 rounded-2xl sm:rounded-3xl border-2 cursor-pointer transition-all group flex sm:flex-col items-center sm:items-start gap-4 sm:gap-0", paymentMethod === pay.id ? "border-canina-blue bg-canina-blue/5" : "border-medical-gray-100 hover:border-canina-blue")}
>
{pay.icon}
-
-
{pay.label}
-
{pay.desc}
+
+
{pay.label}
+
{pay.desc}
))}
diff --git a/frontend/application/components/OrderDetailsModal.tsx b/frontend/application/components/OrderDetailsModal.tsx
index e4c30c8f..12d69114 100644
--- a/frontend/application/components/OrderDetailsModal.tsx
+++ b/frontend/application/components/OrderDetailsModal.tsx
@@ -218,7 +218,7 @@ export default function OrderDetailsModal({ isOpen, onClose, order }: OrderDetai
اطلاعات ارسال
- تهران، خیابان ولیعصر، بالاتر از میدان ونک، بنبست آفتاب، پلاک ۱۲، واحد ۳
+ {order.shippingAddress || "آدرس ثبتی کاربر در حساب کاربری"}
@@ -228,15 +228,17 @@ export default function OrderDetailsModal({ isOpen, onClose, order }: OrderDetai
- جمع ناخالص
- {toPersian(order.total.toLocaleString())} تومان
-
-
- تخفیف هوشمند
- {toPersian("۰")} تومان
+ مبلغ محصولات
+ {toPersian(((order.total || 0) - (order.charityDonation || 0)).toLocaleString())} تومان
+ {order.charityDonation > 0 && (
+
+ کمک اهدایی (ردپای مهربانی)
+ {toPersian(order.charityDonation.toLocaleString())} تومان
+
+ )}
- مبلغ نهایی
+ مبلغ نهایی پرداخت شده
{toPersian(order.total.toLocaleString())} تومان
diff --git a/frontend/application/components/UserDashboard.tsx b/frontend/application/components/UserDashboard.tsx
index d9bc55d9..33ae3706 100644
--- a/frontend/application/components/UserDashboard.tsx
+++ b/frontend/application/components/UserDashboard.tsx
@@ -601,9 +601,10 @@ export default function UserDashboard() {
diff --git a/frontend/application/lib/store/cartStore.ts b/frontend/application/lib/store/cartStore.ts
index 3be857af..d609d93c 100644
--- a/frontend/application/lib/store/cartStore.ts
+++ b/frontend/application/lib/store/cartStore.ts
@@ -23,6 +23,7 @@ interface Order {
charityDonation?: number;
status: 'processing' | 'shipped' | 'delivered';
petId?: string;
+ shippingAddress?: string;
trackingNumber: string;
}