diff --git a/src/components/dashboard/CreditsPage.tsx b/src/components/dashboard/CreditsPage.tsx
index 7ffe847..f35e19a 100644
--- a/src/components/dashboard/CreditsPage.tsx
+++ b/src/components/dashboard/CreditsPage.tsx
@@ -72,6 +72,8 @@ type CheckoutState = {
orderId: string | null;
step: "form" | "processing" | "success" | "error";
error: string;
+ couponCode: string;
+ couponApplied: boolean;
};
async function apiFetch(path: string, opts?: RequestInit) {
@@ -116,6 +118,8 @@ export default function CreditsPage(props: Props) {
orderId: null,
step: "form",
error: "",
+ couponCode: "",
+ couponApplied: false,
});
const isProfessional = () => PROFESSIONAL_ROLE_SET.has(props.roleKey);
const prefix = () => ROLE_PREFIXES[props.roleKey];
@@ -298,24 +302,28 @@ export default function CreditsPage(props: Props) {
onMount(loadAllData);
const openCheckout = (pkg: Package) => {
- setCheckout({ package: pkg, aiCreditPackage: null, orderId: null, step: "form", error: "" });
+ setCheckout({ package: pkg, aiCreditPackage: null, orderId: null, step: "form", error: "", couponCode: "", couponApplied: false });
};
const openAiCreditCheckout = (pkg: AiCreditPackage) => {
- setCheckout({ package: null, aiCreditPackage: pkg, orderId: null, step: "form", error: "" });
+ setCheckout({ package: null, aiCreditPackage: pkg, orderId: null, step: "form", error: "", couponCode: "", couponApplied: false });
};
const closeCheckout = () => {
- setCheckout({ package: null, aiCreditPackage: null, orderId: null, step: "form", error: "" });
+ setCheckout({ package: null, aiCreditPackage: null, orderId: null, step: "form", error: "", couponCode: "", couponApplied: false });
};
const processAiCreditPayment = async (aiPkg: AiCreditPackage) => {
setCheckout((c) => ({ ...c, step: "processing", error: "" }));
try {
+ const coupon = checkout().couponCode.trim();
const orderRes = await apiFetch("/api/ai-credits/order", {
method: "POST",
- body: JSON.stringify({ package_id: aiPkg.id }),
+ body: JSON.stringify({
+ package_id: aiPkg.id,
+ ...(coupon ? { coupon_code: coupon } : {}),
+ }),
});
const orderData = await orderRes.json().catch(() => ({}));
@@ -682,6 +690,59 @@ export default function CreditsPage(props: Props) {
+ {/* Coupon code — only for AI credit purchases */}
+
+ ✓ Coupon will be applied at checkout
+