Co-authored-by: wolfoftyreso-debug <250630591+wolfoftyreso-debug@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-07-12 13:38:33 +00:00
parent 0a87269136
commit 37bb419c0b
@@ -99,6 +99,25 @@ async function handleCheckoutCompleted(session: any, env: StripeEnv) {
if (email) { if (email) {
await ensureUser(email, session.metadata?.company); await ensureUser(email, session.metadata?.company);
} }
// Markera ordern som betald genom att matcha stripe_session_id i items[0].
const paid = session.payment_status === "paid" || session.status === "complete";
if (paid && session.id) {
const { data: rows, error: selErr } = await supabase
.from("orders")
.select("id, items, status")
.contains("items", [{ stripe_session_id: session.id }]);
if (selErr) console.error("orders select failed:", selErr);
if (rows?.length) {
for (const row of rows) {
if (row.status === "paid") continue;
await supabase
.from("orders")
.update({ status: "paid", updated_at: new Date().toISOString() })
.eq("id", row.id);
}
}
}
} }
Deno.serve(async (req) => { Deno.serve(async (req) => {