Refund a payment
Refunds an existing payment. Requires an idempotency key to prevent duplicate refunds on retry.
Idempotency Key Benefits for Refunds
Refunds are critical financial operations where duplicates can cause serious issues. Using idempotency keys ensures:
- Prevent duplicate refunds: Even if a request times out or fails, retrying with the same key won’t issue multiple refunds
- Safe retries: Network failures or timeouts won’t risk creating multiple refunds
- Consistent response: Always get the same response for the same operation
Example Request (curl)
curl -X POST \
https://api.example.com/rest-api/v0/test-payment/pay_abc123xyz456/refund \
-H 'Content-Type: application/json' \
-H 'Client-Key: your-api-key' \
-H 'Client-Secret: your-api-secret' \
-H 'Idempotency-Key: refund_123456_unique_key'
Example Response (First Request)
{
"id": "ref_xyz789",
"paymentId": "pay_abc123xyz456",
"amount": 100.00,
"status": "succeeded",
"timestamp": "2023-07-01T14:30:00.000Z"
}
Example Response (Duplicate Request)
The exact same response will be returned for any duplicate request with the same idempotency key, without creating a new refund.
Idempotency Key Guidelines
- Use a unique key for each distinct refund operation
- Store keys client-side to ensure you can retry with the same key if needed
- Keys expire after 24 hours by default
Authorizations
Your secret API key. Keep this secure and never expose it in client-side code.
Headers
Unique key to ensure the refund request is idempotent. If a request with the same key is sent multiple times, only the first will be processed, and subsequent requests will return the same response.
"refund_123456_unique_key"
Path Parameters
Payment ID to refund
Response
Payment refunded successfully
Refund ID
"ref_12345abcdef"
Original payment ID
"pay_12345abcdef"
The amount refunded
100.5
Refund status
"succeeded"
Timestamp of the refund
"2023-07-01T12:00:00.000Z"
