diff --git a/src/pages/ConsultingBooking.tsx b/src/pages/ConsultingBooking.tsx index d50a8f3..47cfa09 100644 --- a/src/pages/ConsultingBooking.tsx +++ b/src/pages/ConsultingBooking.tsx @@ -226,46 +226,39 @@ export default function ConsultingBooking() { const { error: slotsError } = await supabase.from('consulting_slots').insert(slotsToInsert); if (slotsError) throw slotsError; - // Generate Pakasir payment URL directly (no cart needed for consulting) - const pakasirOrderData = { - order_id: order.id, - amount: totalPrice, - customer_name: profile?.full_name || user.email, - customer_email: user.email, - items: [{ - id: order.id, - name: `Konsultasi 1-on-1 (${totalBlocks} blok)`, - price: totalPrice, - quantity: 1 - }], - success_url: `${window.location.origin}/orders/${order.id}`, - cancel_url: `${window.location.origin}/consulting`, - }; + // Call Pakasir API directly to create QRIS payment + const PAKASIR_PROJECT_SLUG = import.meta.env.VITE_PAKASIR_PROJECT_SLUG || ''; + const PAKASIR_API_KEY = import.meta.env.VITE_PAKASIR_API_KEY || ''; + const PAKASIR_CALLBACK_URL = `${import.meta.env.VITE_SUPABASE_URL}/functions/v1/pakasir-webhook`; - // Call your backend to create Pakasir payment - const paymentResponse = await fetch(`${import.meta.env.VITE_SUPABASE_URL}/functions/v1/create-pakasir-payment`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Authorization': `Bearer ${import.meta.env.VITE_SUPABASE_ANON_KEY}`, - }, - body: JSON.stringify(pakasirOrderData), - }); + try { + const response = await fetch(`https://app.pakasir.com/api/transactioncreate/qris`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + project: PAKASIR_PROJECT_SLUG, + order_id: order.id, + amount: totalPrice, + api_key: PAKASIR_API_KEY, + description: `Konsultasi 1-on-1 (${totalBlocks} blok)`, + callback_url: PAKASIR_CALLBACK_URL, + }), + }); - if (!paymentResponse.ok) { - throw new Error('Failed to create payment'); + const result = await response.json(); + + if (result.qr_string || result.qr) { + // QRIS available - redirect to Pakasir payment page + const pakasirPayUrl = `https://app.pakasir.com/pay/${PAKASIR_PROJECT_SLUG}/${totalPrice}?order_id=${order.id}`; + window.location.href = pakasirPayUrl; + } else { + throw new Error('Failed to create payment'); + } + } catch (pakasirError) { + // Fallback: redirect directly to Pakasir + const pakasirPayUrl = `https://app.pakasir.com/pay/${PAKASIR_PROJECT_SLUG}/${totalPrice}?order_id=${order.id}`; + window.location.href = pakasirPayUrl; } - - const paymentData = await paymentResponse.json(); - - // Update order with payment URL - await supabase - .from('orders') - .update({ payment_url: paymentData.payment_url }) - .eq('id', order.id); - - // Redirect to payment - window.location.href = paymentData.payment_url; } catch (error: any) { toast({ title: 'Error', description: error.message, variant: 'destructive' }); } finally {