fix(orders,wallet): implement full-stack wallet deduction in PostgreSQL and sync charity donation total in user profile
This commit is contained in:
1 parent
51b2f811fa
commit
377ec7fb34
7 files changed
+76
-18
No files matched your search
@@ -114,19 +114,15 @@ export default function CheckoutPage() {
|
||||
items: [...items],
|
||||
total: totalAmount,
|
||||
charityDonation: charityDonation,
|
||||
paymentMethod: paymentMethod,
|
||||
isRefill: isSubscribed,
|
||||
petId: activePet?.id,
|
||||
shippingAddress: shippingAddressStr
|
||||
});
|
||||
|
||||
// 3. Update user charity total
|
||||
if (charityDonation > 0) {
|
||||
useUserStore.setState((state) => ({
|
||||
profile: {
|
||||
...state.profile,
|
||||
charityDonationTotal: (state.profile.charityDonationTotal || 0) + charityDonation
|
||||
}
|
||||
}));
|
||||
}
|
||||
// Re-fetch user profile from backend to sync PostgreSQL wallet balance and charity donation total
|
||||
const { fetchProfile } = useUserStore.getState();
|
||||
await fetchProfile();
|
||||
|
||||
// 4. Update pet consumptions and charity contributions for active pet
|
||||
if (activePet) {
|
||||
|
||||
@@ -41,6 +41,7 @@ export class OrderService {
|
||||
couponCode?: string;
|
||||
prescriptionUrl?: string;
|
||||
charityDonation?: number;
|
||||
paymentMethod?: string;
|
||||
isRefill?: boolean;
|
||||
refillIntervalDays?: number;
|
||||
shippingAddress?: string;
|
||||
|
||||
@@ -21,6 +21,8 @@ interface Order {
|
||||
items: CartItem[];
|
||||
total: number;
|
||||
charityDonation?: number;
|
||||
paymentMethod?: string;
|
||||
isRefill?: boolean;
|
||||
status: 'processing' | 'shipped' | 'delivered';
|
||||
petId?: string;
|
||||
shippingAddress?: string;
|
||||
@@ -39,7 +41,7 @@ interface CartStore {
|
||||
toggleSubscription: () => void;
|
||||
setCharityDonation: (amount: number) => void;
|
||||
applyCoupon: (code: string) => Promise<boolean>;
|
||||
addOrder: (order: Omit<Order, 'id' | 'date' | 'status' | 'trackingNumber'>) => Promise<string>;
|
||||
addOrder: (orderData: Omit<Order, 'id' | 'date' | 'status' | 'trackingNumber'>) => Promise<string>;
|
||||
clearCart: () => void;
|
||||
removeCoupon: () => void;
|
||||
setOrders: (orders: any[]) => void;
|
||||
@@ -104,6 +106,12 @@ export const useCartStore = create<CartStore>()(
|
||||
addOrder: async (orderData) => {
|
||||
const payload = {
|
||||
petId: orderData.petId,
|
||||
couponCode: get().coupon?.code,
|
||||
charityDonation: orderData.charityDonation,
|
||||
paymentMethod: orderData.paymentMethod,
|
||||
isRefill: orderData.isRefill || get().isSubscribed,
|
||||
refillIntervalDays: 60,
|
||||
shippingAddress: orderData.shippingAddress,
|
||||
items: orderData.items.map(i => ({
|
||||
productId: i.product.id,
|
||||
quantity: i.quantity
|
||||
|
||||
Reference in new issue
Block a user