Fix consulting payment: call Pakasir API directly from frontend
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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 = {
|
||||
// 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`;
|
||||
|
||||
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,
|
||||
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 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),
|
||||
api_key: PAKASIR_API_KEY,
|
||||
description: `Konsultasi 1-on-1 (${totalBlocks} blok)`,
|
||||
callback_url: PAKASIR_CALLBACK_URL,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!paymentResponse.ok) {
|
||||
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');
|
||||
}
|
||||
|
||||
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 (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;
|
||||
}
|
||||
} catch (error: any) {
|
||||
toast({ title: 'Error', description: error.message, variant: 'destructive' });
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user