refund_transaction
Refund a transaction by providing its ID and the refund amount in cents. Supports partial refunds for subscription billing.
Instructions
Refund a transaction. POST /transactions/{transactionId}/refund. AMOUNT IN CENTS: e.g. 250 = $2.50, 5500 = $55.00. Required: transactionId, amount (integer cents).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| transactionId | Yes | Transaction ID (required) | |
| amount | Yes | Refund amount in CENTS (e.g. 250 = $2.50, 5500 = $55.00). Integer, required. |
Implementation Reference
- The handler function that executes the refund_transaction tool logic. It parses args with Zod schema, extracts transactionId and amount, then calls transactionService.refundTransaction.
async function handler(client: Client, args: Record<string, unknown> | undefined) { const parsed = schema.safeParse(args); if (!parsed.success) { return errorResult(parsed.error.errors.map((e) => e.message).join("; ")); } const { transactionId, amount } = parsed.data; return handleToolCall(() => transactionService.refundTransaction(client, transactionId, amount) ); } - Zod validation schema for refund_transaction. Requires transactionId (string) and amount (integer in cents).
const schema = z.object({ transactionId: z.string().min(1, "transactionId is required"), amount: z.number().int().min(0, "amount is required (in CENTS, e.g. 250 = $2.50)"), }); - MCP tool definition/inputSchema for refund_transaction, describing name, description, and input JSON Schema properties.
const definition = { name: "refund_transaction", description: "Refund a transaction. POST /transactions/{transactionId}/refund. AMOUNT IN CENTS: e.g. 250 = $2.50, 5500 = $55.00. Required: transactionId, amount (integer cents).", inputSchema: { type: "object" as const, properties: { transactionId: { type: "string", description: "Transaction ID (required)" }, amount: { type: "number", description: "Refund amount in CENTS (e.g. 250 = $2.50, 5500 = $55.00). Integer, required.", }, }, required: ["transactionId", "amount"], }, }; - src/tools/transactions/index.ts:12-19 (registration)Registration of refundTransactionTool as part of the transaction tools array returned by registerTransactionTools().
export function registerTransactionTools(): Tool[] { return [ listTransactionsTool, getTransactionTool, refundTransactionTool, voidTransactionTool, ]; } - The actual API call helper: POST /transactions/{transactionId}/refund?amount={amountCents}. Amount is passed in cents.
/** POST /transactions/{transactionId}/refund?amount={amount}. amount in CENTS (e.g. 250 = $2.50). Required. */ export async function refundTransaction( client: Client, transactionId: string, amountCents: number ): Promise<unknown> { const search = new URLSearchParams(); search.append("amount", String(amountCents)); const q = search.toString(); return client.post<unknown>( `/transactions/${transactionId}/refund?${q}`, {} ); }