All documentation
Refunds - cred.diy API documentation
Refunds
Reverse a credit purchase or transaction. The originally issued credits are clawed back and, for Stripe-backed purchases, an optional money refund is issued. Refunds are idempotent — each source transaction can be refunded only once. To retry a timed-out refund safely (including partial refunds), send an Idempotency-Key header: a retry with the same key returns the original refund.
Refund a Purchase
Identify what to refund with exactly one of purchase_id, stripe_payment_intent_id, transaction_id, or reference_id. Pass amount for a partial refund.
// Refund a purchase (claws back credits + optional Stripe money refund)
// Identify the source with ONE of: purchase_id, stripe_payment_intent_id,
// transaction_id, or reference_id. Refunds are idempotent.
const response = await fetch(
'https://eutdgemlrpvnxfkkpvlu.supabase.co/functions/v1/credits-api/refund',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': 'sk_live_your_api_key'
},
body: JSON.stringify({
purchase_id: 'pur_abc123',
// amount: 50, // optional — partial refund
// refund_payment: true, // optional — also refund the Stripe payment (default true)
reason: 'Customer requested refund'
})
}
);
const result = await response.json();
// {
// success: true,
// refund_transaction_id: 'tx_refund_123',
// refunded_credits: 100,
// partial: false,
// new_balance: 200,
// credits_clawed_back: true,
// payment_refunded: true,
// stripe_refund_id: 're_1Nv9...',
// source: 'purchase'
// }Refund API Endpoint
| Endpoint | Description |
|---|---|
| POST /refund | Reverse a purchase/transaction; optional Stripe money refund |
Common Errors
// 404 - No matching purchase/transaction found
{ "error": "Purchase not found" }
// 409 - This source was already refunded (idempotency guard)
{ "error": "Already refunded" }
// 400 - Requested amount is larger than the original
{ "error": "Refund exceeds original amount" }
// 402 - Stripe money refund failed; no credits were changed
{ "error": "Stripe refund failed", "stripe_error": "..." }Your first credit is one request away.
Create a project, copy an API key, and issue a credit from your server.
