A refund tool in 60 lines
Build the tool support asks for most often: look up an order, refund part of it, and log who did it.
1 min read
On this page3 sections
Every support team ends up asking engineering for the same tool: find an order, refund some of it, and keep a record. Here’s the whole thing in Forgekit.
Set up
npm
npx forgekit init refunds && cd refunds && npm installbun
bunx forgekit init refunds && cd refunds && bun installpnpm
pnpm dlx forgekit init refunds && cd refunds && pnpm installThe action
import { defineAction } from "@forgekit/sdk";
import { z } from "zod";
export const refund = defineAction({
input: z.object({ orderId: z.string(), amountCents: z.number().int().positive() }),
access: { groups: ["support"] },
async run({ input, ctx, stripe, audit }) {
const result = await stripe.refunds.create({
payment_intent: input.orderId,
amount: input.amountCents,
});
await audit.log("refund", { by: ctx.user.email, ...input });
return result;
},
});
access.groups limits the action to your support group in Okta, and audit.log writes to the tool’s audit table, which shows up under Activity in the deployed tool.
The screen
The UI is a lookup field, an order table and a form bound to the action. The form fields come from the schema, so there’s nothing else to wire up.