From ce531c8d4624be03af7924484b4602a1405e04a7 Mon Sep 17 00:00:00 2001 From: dwindown Date: Tue, 23 Dec 2025 16:41:22 +0700 Subject: [PATCH] Add Google Meet event creation to payment webhook MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When order is paid, automatically create Google Meet events for all consulting slots. The meet_link is saved to consulting_slots table and included in notifications. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- supabase/functions/pakasir-webhook/index.ts | 70 ++++++++++++++++++++- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/supabase/functions/pakasir-webhook/index.ts b/supabase/functions/pakasir-webhook/index.ts index a757f1b..cc745a7 100644 --- a/supabase/functions/pakasir-webhook/index.ts +++ b/supabase/functions/pakasir-webhook/index.ts @@ -335,9 +335,75 @@ serve(async (req) => { console.log("[WEBHOOK] Consulting slots confirmed for order:", order.id); } + // Create Google Meet events for each consulting slot + for (const slot of consultingSlots) { + try { + console.log("[WEBHOOK] Creating Google Meet event for slot:", slot.id); + + const { data: settings } = await supabase + .from("platform_settings") + .select("integration_google_calendar_id") + .single(); + + if (!settings?.integration_google_calendar_id) { + console.log("[WEBHOOK] Google Calendar not configured, skipping Meet creation"); + continue; + } + + // Get product info for the topic + const { data: orderItems } = await supabase + .from("order_items") + .select("product_id, products(name)") + .eq("order_id", order.id) + .limit(1); + + const topic = orderItems?.[0]?.products?.name || "Konsultasi 1-on-1"; + + const meetResponse = await fetch( + `${Deno.env.get("SUPABASE_URL")}/functions/v1/create-google-meet-event`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + "Authorization": `Bearer ${Deno.env.get("SUPABASE_ANON_KEY")}`, + }, + body: JSON.stringify({ + slot_id: slot.id, + date: slot.date, + start_time: slot.start_time, + end_time: slot.end_time, + client_name: userName, + client_email: userEmail, + topic: topic, + }), + } + ); + + if (meetResponse.ok) { + const meetData = await meetResponse.json(); + if (meetData.success) { + console.log("[WEBHOOK] Google Meet event created:", meetData.meet_link); + } else { + console.error("[WEBHOOK] Failed to create Meet event:", meetData.message); + } + } else { + console.error("[WEBHOOK] Meet creation API error:", meetResponse.status); + } + } catch (error) { + console.error("[WEBHOOK] Error creating Google Meet event:", error); + // Don't fail the webhook if Meet creation fails + } + } + + // Refresh slots to get updated meet_link + const { data: updatedSlots } = await supabase + .from("consulting_slots") + .select("*") + .eq("order_id", order.id); + // Format consulting slot details for notification - const slots = consultingSlots as Array<{ date: string; start_time: string; end_time: string; meet_link?: string }>; - + const slots = (updatedSlots || consultingSlots) as Array<{ date: string; start_time: string; end_time: string; meet_link?: string }>; + const shortcodeData: Record = { nama: userName, email: userEmail,