Add Google Meet event creation to payment webhook
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 <noreply@anthropic.com>
This commit is contained in:
@@ -335,8 +335,74 @@ serve(async (req) => {
|
|||||||
console.log("[WEBHOOK] Consulting slots confirmed for order:", order.id);
|
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
|
// 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<string, string> = {
|
const shortcodeData: Record<string, string> = {
|
||||||
nama: userName,
|
nama: userName,
|
||||||
|
|||||||
Reference in New Issue
Block a user