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 { useNavigate } from 'react-router-dom';
|
||||||
import { supabase } from '@/integrations/supabase/client';
|
import { supabase } from '@/integrations/supabase/client';
|
||||||
import { useAuth } from '@/hooks/useAuth';
|
import { useAuth } from '@/hooks/useAuth';
|
||||||
import { useCart } from '@/contexts/CartContext';
|
|
||||||
import { AppLayout } from '@/components/AppLayout';
|
import { AppLayout } from '@/components/AppLayout';
|
||||||
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card';
|
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
@@ -51,7 +50,6 @@ interface Profile {
|
|||||||
export default function ConsultingBooking() {
|
export default function ConsultingBooking() {
|
||||||
const { user, loading: authLoading } = useAuth();
|
const { user, loading: authLoading } = useAuth();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { addItem } = useCart();
|
|
||||||
|
|
||||||
const [settings, setSettings] = useState<ConsultingSettings | null>(null);
|
const [settings, setSettings] = useState<ConsultingSettings | null>(null);
|
||||||
const [workhours, setWorkhours] = useState<Workhour[]>([]);
|
const [workhours, setWorkhours] = useState<Workhour[]>([]);
|
||||||
@@ -228,17 +226,46 @@ export default function ConsultingBooking() {
|
|||||||
const { error: slotsError } = await supabase.from('consulting_slots').insert(slotsToInsert);
|
const { error: slotsError } = await supabase.from('consulting_slots').insert(slotsToInsert);
|
||||||
if (slotsError) throw slotsError;
|
if (slotsError) throw slotsError;
|
||||||
|
|
||||||
// Add to cart for Pakasir checkout
|
// Generate Pakasir payment URL directly (no cart needed for consulting)
|
||||||
addItem({
|
const pakasirOrderData = {
|
||||||
id: `consulting-${order.id}`,
|
order_id: order.id,
|
||||||
title: `Konsultasi 1-on-1 (${totalBlocks} blok)`,
|
amount: totalPrice,
|
||||||
price: totalPrice,
|
customer_name: profile?.full_name || user.email,
|
||||||
sale_price: null,
|
customer_email: user.email,
|
||||||
type: 'consulting',
|
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 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' });
|
if (!paymentResponse.ok) {
|
||||||
navigate('/checkout');
|
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) {
|
} catch (error: any) {
|
||||||
toast({ title: 'Error', description: error.message, variant: 'destructive' });
|
toast({ title: 'Error', description: error.message, variant: 'destructive' });
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user