//native
/**
* Cancel or Reverse Payout
* Cancel a pending payout, or reverse a paid one; either way the funds go back to the available balance. Payouts in transit, failed or already canceled are rejected.
*/
export async function main(auth: RT.Stripe, payout_id: string) {
const headers = {
Authorization: `Bearer ${auth.token}`,
Accept: "application/json",
"Stripe-Version": "2025-03-31.basil",
}
const current = await fetch(
`https://api.stripe.com/v1/payouts/${payout_id}`,
{ headers }
)
if (!current.ok) {
throw new Error(`${current.status} ${await current.text()}`)
}
const { status } = (await current.json()) as { status: string }
if (status !== "pending" && status !== "paid") {
throw new Error(
`Payout ${payout_id} is ${status}: only pending or paid payouts can be canceled or reversed`
)
}
const response = await fetch(
`https://api.stripe.com/v1/payouts/${payout_id}/${status === "paid" ? "reverse" : "cancel"}`,
{ method: "POST", headers }
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 3 hours ago
//native
type Stripe = {
token: string;
};
export async function main(stripe_con: Stripe, payout_id: string) {
const STRIPE_REVERSE_PAYOUT_URL = `https://api.stripe.com/v1/payouts/:${payout_id}/reverse`;
const token = stripe_con["token"];
const response = await fetch(STRIPE_REVERSE_PAYOUT_URL, {
method: "POST",
headers: {
Authorization: "Bearer " + token,
"Content-Type": "application/json",
},
});
return await response.json();
}
Submitted by hugo989 136 days ago