54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import { orderSchema } from "@/dto/order.dto";
|
|
import { requestWithSchema } from "@/services/api-client";
|
|
|
|
const USE_REMOTE_API = false;
|
|
|
|
function amountByPlan(plan: "free" | "pro" | "ultra") {
|
|
if (plan === "ultra") return 99;
|
|
if (plan === "pro") return 29;
|
|
return 0;
|
|
}
|
|
|
|
export async function createCheckoutOrder(plan: "free" | "pro" | "ultra", slug: string) {
|
|
if (!USE_REMOTE_API) {
|
|
const orderSeed = `${plan}-${slug}`.replace(/[^a-zA-Z0-9]/g, "").slice(0, 14).toUpperCase();
|
|
return orderSchema.parse({
|
|
id: `NOVA-${orderSeed || "DEMO0001"}`,
|
|
plan,
|
|
slug,
|
|
amount: amountByPlan(plan),
|
|
status: "pending",
|
|
createdAt: "2026-04-02T00:00:00.000Z",
|
|
});
|
|
}
|
|
|
|
return requestWithSchema({
|
|
endpoint: `/api/orders/create?plan=${plan}&slug=${encodeURIComponent(slug)}`,
|
|
schema: orderSchema,
|
|
init: { method: "POST" },
|
|
});
|
|
}
|
|
|
|
export async function getOrderById(input: {
|
|
id: string;
|
|
plan: "free" | "pro" | "ultra";
|
|
slug: string;
|
|
status: "pending" | "success" | "failed";
|
|
}) {
|
|
if (!USE_REMOTE_API) {
|
|
return orderSchema.parse({
|
|
id: input.id,
|
|
plan: input.plan,
|
|
slug: input.slug,
|
|
amount: amountByPlan(input.plan),
|
|
status: input.status,
|
|
createdAt: "2026-04-02T00:00:00.000Z",
|
|
});
|
|
}
|
|
|
|
return requestWithSchema({
|
|
endpoint: `/api/orders/${input.id}?status=${input.status}&plan=${input.plan}&slug=${encodeURIComponent(input.slug)}`,
|
|
schema: orderSchema,
|
|
});
|
|
}
|