Fix consulting booking: bypass cart, go directly to payment
Consulting is a service, not a product. It doesn't have order_items. - Removed cart integration for consulting bookings - Now calls create-pakasir-payment edge function directly - Redirects to payment URL without going through checkout - Removed useCart dependency 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,6 @@ import { useEffect, useState, useMemo } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
import { useAuth } from '@/hooks/useAuth';
|
||||
import { useCart } from '@/contexts/CartContext';
|
||||
import { AppLayout } from '@/components/AppLayout';
|
||||
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card';
|
||||
import { Button } from '@/components/ui/button';
|
||||
@@ -51,7 +50,6 @@ interface Profile {
|
||||
export default function ConsultingBooking() {
|
||||
const { user, loading: authLoading } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
const { addItem } = useCart();
|
||||
|
||||
const [settings, setSettings] = useState<ConsultingSettings | null>(null);
|
||||
const [workhours, setWorkhours] = useState<Workhour[]>([]);
|
||||
@@ -228,17 +226,46 @@ export default function ConsultingBooking() {
|
||||
const { error: slotsError } = await supabase.from('consulting_slots').insert(slotsToInsert);
|
||||
if (slotsError) throw slotsError;
|
||||
|
||||
// Add to cart for Pakasir checkout
|
||||
addItem({
|
||||
id: `consulting-${order.id}`,
|
||||
title: `Konsultasi 1-on-1 (${totalBlocks} blok)`,
|
||||
// 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,
|
||||
sale_price: null,
|
||||
type: 'consulting',
|
||||
quantity: 1
|
||||
}],
|
||||
success_url: `${window.location.origin}/orders/${order.id}`,
|
||||
cancel_url: `${window.location.origin}/consulting`,
|
||||
};
|
||||
|
||||
// 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),
|
||||
});
|
||||
|
||||
toast({ title: 'Berhasil', description: 'Silakan lanjutkan ke pembayaran' });
|
||||
navigate('/checkout');
|
||||
if (!paymentResponse.ok) {
|
||||
throw new Error('Failed to create payment');
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user