diff --git a/supabase/functions/pakasir-webhook/index.ts b/supabase/functions/pakasir-webhook/index.ts index 98a6602..7277891 100644 --- a/supabase/functions/pakasir-webhook/index.ts +++ b/supabase/functions/pakasir-webhook/index.ts @@ -86,7 +86,7 @@ serve(async (req) => { }); } - // Update order status - this will trigger the database trigger + // Update order status const { error: updateError } = await supabase .from("orders") .update({ @@ -109,7 +109,30 @@ serve(async (req) => { }); } - console.log("[WEBHOOK] Order updated to paid:", order.id, "- Trigger will handle the rest"); + console.log("[WEBHOOK] Order updated to paid:", order.id, "- Calling handle-order-paid"); + + // Call handle-order-paid edge function directly to process the order + try { + const handlePaidUrl = `${SUPABASE_URL}/functions/v1/handle-order-paid`; + await fetch(handlePaidUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${PAKASIR_WEBHOOK_SECRET || 'anonymous'}`, + }, + body: JSON.stringify({ + order_id: order.id, + user_id: order.user_id, + total_amount: order.total_amount, + payment_method: payload.payment_method || "unknown", + payment_provider: "pakasir", + }), + }); + console.log("[WEBHOOK] Called handle-order-paid successfully"); + } catch (error) { + console.error("[WEBHOOK] Failed to call handle-order-paid:", error); + // Don't fail the webhook response if handle-order-paid fails + } return new Response(JSON.stringify({ success: true, order_id: order.id }), { status: 200,