diff --git a/src/modules/market/views/CheckoutPage.vue b/src/modules/market/views/CheckoutPage.vue index 1a1b6f4..c9d17b4 100644 --- a/src/modules/market/views/CheckoutPage.vue +++ b/src/modules/market/views/CheckoutPage.vue @@ -272,6 +272,7 @@ import { ref, computed, onMounted } from 'vue' import { useRoute, useRouter } from 'vue-router' import { useMarketStore } from '@/stores/market' +import { injectService, SERVICE_TOKENS } from '@/core/di-container' import { Card, CardHeader, @@ -291,6 +292,7 @@ import { const route = useRoute() const router = useRouter() const marketStore = useMarketStore() +const authService = injectService(SERVICE_TOKENS.AUTH_SERVICE) as any // State const isLoading = ref(true) @@ -402,24 +404,61 @@ const placeOrder = async () => { error.value = null try { - // Mock order placement - await new Promise(resolve => setTimeout(resolve, 2000)) - - // In real app, would create Nostr order event and handle payment - console.log('Placing order:', { - stallId: stallId.value, - cart: checkoutCart.value, - shipping: selectedShippingZone.value, - contact: contactData.value, - paymentMethod: paymentMethod.value, - total: orderTotal.value - }) + // Ensure we have the required data + if (!checkoutCart.value) { + throw new Error('No checkout cart found') + } + if (!currentStall.value) { + throw new Error('Stall information not available') + } + if (!authService.isAuthenticated.value || !authService.user.value?.pubkey) { + throw new Error('You must be logged in to place an order') + } - // Clear the checkout cart - marketStore.clearCheckoutCart() + // Create the order using the market store's order placement functionality + const orderData = { + stallId: stallId.value, + buyerPubkey: authService.user.value?.pubkey || '', + sellerPubkey: currentStall.value.pubkey, + status: 'pending' as const, + items: checkoutCart.value.products.map(item => ({ + productId: item.product.id, + productName: item.product.name, + quantity: item.quantity, + price: item.product.price, + currency: item.product.currency + })), + contactInfo: { + address: contactData.value.address || undefined, + email: contactData.value.email || undefined, + message: contactData.value.message || undefined, + npub: contactData.value.npub || undefined + }, + shippingZone: selectedShippingZone.value || { + id: 'default', + name: 'Default Shipping', + cost: 0, + currency: checkoutCart.value.currency, + requiresPhysicalShipping: false + }, + paymentMethod: paymentMethod.value === 'ln' ? 'lightning' as const : 'btc_onchain' as const, + subtotal: orderSubtotal.value, + shippingCost: selectedShippingZone.value?.cost || 0, + total: orderTotal.value, + currency: checkoutCart.value.currency, + cartId: checkoutCart.value.id + } + + console.log('Creating order:', orderData) + // Create and place the order via the market store + const order = await marketStore.createAndPlaceOrder(orderData) + + console.log('Order placed successfully:', order) orderPlaced.value = true + } catch (err) { + console.error('Failed to place order:', err) error.value = err instanceof Error ? err.message : 'Failed to place order' } finally { isPlacingOrder.value = false