Debug: Add extensive logging to handle-order-paid
Added detailed logging to diagnose why consulting slots aren't being updated: - Log order details including consulting_slots count - Log whether order is detected as consulting order - Log slot update result and any errors This will help identify where the process is failing.
This commit is contained in:
@@ -51,13 +51,21 @@ serve(async (req: Request): Promise<Response> => {
|
||||
.single();
|
||||
|
||||
if (orderError || !order) {
|
||||
console.error("[HANDLE-PAID] Order not found:", order_id);
|
||||
console.error("[HANDLE-PAID] Order not found:", order_id, orderError);
|
||||
return new Response(
|
||||
JSON.stringify({ success: false, error: "Order not found" }),
|
||||
{ status: 404, headers: { ...corsHeaders, "Content-Type": "application/json" } }
|
||||
);
|
||||
}
|
||||
|
||||
console.log("[HANDLE-PAID] Order found:", JSON.stringify({
|
||||
id: order.id,
|
||||
payment_status: order.payment_status,
|
||||
order_items_count: order.order_items?.length || 0,
|
||||
consulting_slots_count: order.consulting_slots?.length || 0,
|
||||
consulting_slots: order.consulting_slots
|
||||
}));
|
||||
|
||||
const userEmail = order.profiles?.email || "";
|
||||
const userName = order.profiles?.full_name || "Pelanggan";
|
||||
const orderItems = order.order_items as Array<{
|
||||
@@ -76,16 +84,24 @@ serve(async (req: Request): Promise<Response> => {
|
||||
}>;
|
||||
const isConsultingOrder = consultingSlots && consultingSlots.length > 0;
|
||||
|
||||
console.log("[HANDLE-PAID] isConsultingOrder:", isConsultingOrder, "consultingSlots:", consultingSlots);
|
||||
|
||||
if (isConsultingOrder) {
|
||||
console.log("[HANDLE-PAID] Consulting order detected, processing slots");
|
||||
|
||||
// Update consulting slots status from pending_payment to confirmed
|
||||
await supabase
|
||||
const { error: updateError } = await supabase
|
||||
.from("consulting_slots")
|
||||
.update({ status: "confirmed" })
|
||||
.eq("order_id", order_id)
|
||||
.in("status", ["pending_payment"]);
|
||||
|
||||
console.log("[HANDLE-PAID] Slot update result:", { updateError, order_id });
|
||||
|
||||
if (updateError) {
|
||||
console.error("[HANDLE-PAID] Failed to update slots:", updateError);
|
||||
}
|
||||
|
||||
if (consultingSlots && consultingSlots.length > 0) {
|
||||
for (const slot of consultingSlots) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user