From e6b1e02e5f4aad8e5bc23db44f7e47d29284b97d Mon Sep 17 00:00:00 2001 From: dwindown Date: Tue, 23 Dec 2025 17:21:01 +0700 Subject: [PATCH] Fix consulting payment: call Pakasir API directly from frontend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The create-pakasir-payment edge function doesn't exist. Instead, call Pakasir API directly from the frontend (same as Checkout page). Uses VITE_PAKASIR_PROJECT_SLUG and VITE_PAKASIR_API_KEY env vars. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- src/pages/ConsultingBooking.tsx | 67 +++++++++++++++------------------ 1 file changed, 30 insertions(+), 37 deletions(-) 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 {