Integrations · Agent framework
How to let Mastra issue Stripe refunds with manager approval
A Mastra tool that asks a person above your cap. createTool() wraps one fetch.
Auto-approve under $50
Small refunds that fit your rules go through at once.
Route the rest
A named approver gets a one-tap card on their phone.
Log everything
Who approved, why, the Stripe refund id. CSV for finance.
Setup: Mastra tool
- Sign up free, connect Stripe with a restricted key (test mode works) and pick a policy.
- Set COUNTERSIGN_KEY in your server environment.
- Add the tool to your agent. It returns status and a message to relay.
import { createTool } from '@mastra/core/tools';
import { z } from 'zod';
export const requestRefund = createTool({
id: 'request_refund',
description: 'Ask for a Stripe refund. Small ones that fit policy go through; others wait for a person. Relay "message".',
inputSchema: z.object({
charge_id: z.string(), amount_cents: z.number().int(), reason: z.string(), reasoning: z.string(),
ticket_url: z.string().url().optional(),
}),
execute: async ({ context: a }) => {
const r = await fetch('https://countersign.vibiz.app/api/v1/refunds/request', {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.COUNTERSIGN_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ charge_id: a.charge_id, amount: a.amount_cents, reason: a.reason,
agent_reasoning: a.reasoning, ticket_url: a.ticket_url, agent_name: 'mastra' }),
});
return r.json();
},
});Replace cs_YOUR_KEY; in the dashboard this snippet comes with your key filled in.
Questions
Does Mastra get access to my Stripe account?
No. Mastra gets a Countersign key that can only ask for refunds. Countersign holds a restricted Stripe key and refunds only after your policy or an approver says yes.
What does the agent get back?
status (approved_and_refunded, pending or denied), a message to relay to the customer, the rule that decided it, and a status_url for pending requests.
Who approves the big ones?
The approver for that amount tier gets an email with a one-tap approve card: customer, charge, refundable balance, earlier refunds, the agent's reasoning and the ticket link.