chore: add AI-first discovery API and beta flow parity
Some checks failed
Deploy to 110 WOOO Server / deploy (push) Failing after 8s
Some checks failed
Deploy to 110 WOOO Server / deploy (push) Failing after 8s
This commit is contained in:
@@ -3,6 +3,13 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { TaskStatus, TaskDifficulty } from "@agent-bounty/contracts";
|
||||
import { redirect } from "next/navigation";
|
||||
import Stripe from "stripe";
|
||||
|
||||
const stripe = process.env.STRIPE_SECRET_KEY
|
||||
? new Stripe(process.env.STRIPE_SECRET_KEY, {
|
||||
apiVersion: "2026-05-27.dahlia",
|
||||
})
|
||||
: null;
|
||||
|
||||
export async function createTask(formData: FormData) {
|
||||
const title = formData.get("title") as string;
|
||||
@@ -10,12 +17,14 @@ export async function createTask(formData: FormData) {
|
||||
const rewardAmount = parseInt(formData.get("rewardAmount") as string, 10) * 100; // to cents
|
||||
const requiredStack = (formData.get("requiredStack") as string).split(",").map(s => s.trim());
|
||||
const testFileContent = formData.get("testFileContent") as string;
|
||||
const isPromoFree = rewardAmount <= 2000;
|
||||
const siteUrl = process.env.NEXT_PUBLIC_SITE_URL || "https://agent.wooo.work";
|
||||
|
||||
const task = await prisma.task.create({
|
||||
data: {
|
||||
title,
|
||||
description,
|
||||
status: TaskStatus.OPEN,
|
||||
status: TaskStatus.DRAFT,
|
||||
difficulty: TaskDifficulty.COMPONENT,
|
||||
scope_clarity_score: 1.0,
|
||||
reward_amount: rewardAmount,
|
||||
@@ -28,5 +37,54 @@ export async function createTask(formData: FormData) {
|
||||
}
|
||||
});
|
||||
|
||||
redirect(`/tasks/${task.id}`);
|
||||
if (isPromoFree) {
|
||||
await prisma.task.update({
|
||||
where: { id: task.id },
|
||||
data: {
|
||||
status: TaskStatus.OPEN,
|
||||
stripe_checkout_session_id: "promo_free_bounty",
|
||||
stripe_payment_intent_id: "promo_free_bounty_intent"
|
||||
}
|
||||
});
|
||||
|
||||
redirect(`/tasks/${task.id}`);
|
||||
}
|
||||
|
||||
if (!stripe) {
|
||||
throw new Error("Stripe is not configured");
|
||||
}
|
||||
|
||||
const session = await stripe.checkout.sessions.create({
|
||||
payment_method_types: ["card"],
|
||||
mode: "payment",
|
||||
line_items: [
|
||||
{
|
||||
price_data: {
|
||||
currency: "usd",
|
||||
product_data: {
|
||||
name: `VibeWork Task: ${title}`,
|
||||
description: "Auth-Hold. Funds will only be captured when task is judged PASS.",
|
||||
},
|
||||
unit_amount: rewardAmount,
|
||||
},
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
payment_intent_data: {
|
||||
capture_method: "manual"
|
||||
},
|
||||
success_url: `${siteUrl}/tasks/${task.id}?success=true`,
|
||||
cancel_url: `${siteUrl}/tasks/create`,
|
||||
});
|
||||
|
||||
await prisma.task.update({
|
||||
where: { id: task.id },
|
||||
data: { stripe_checkout_session_id: session.id }
|
||||
});
|
||||
|
||||
if (!session.url) {
|
||||
throw new Error("Stripe session URL is missing");
|
||||
}
|
||||
|
||||
redirect(session.url);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user