Refund a charge
Return all or part of a settled charge to the customer through POST /v1/refunds.
Return funds from a successful charge to the customer's original payment method
using POST /v1/refunds.
Unlike canceling a hold, which
releases funds that were only reserved, a refund moves settled funds and can
take several business days to appear on the customer's statement.
Requirements
Before you start, make sure you have:
- The
idof the successful charge (chrg_...). - Your API credentials. The examples use the sandbox (
https://api.sandbox.pay.com/v1) with ansk-pay-com-sandbox-key. - A unique
idempotency-keyheader for each request, and the same key when you retry.
Create a refund
Follow these steps to issue a full or partial refund and track its status.
- 1
Send the refund request
Call
POST /v1/refundswith the charge ID incharge. Omitamount_to_refundto refund the full remaining balance, or pass an integer in minor units (for example,5000for $50.00 USD) for a partial refund.Omit
amount_to_refundto return the entire remaining balance of the charge.POST https://api.sandbox.pay.com/v1/refunds{ "charge": "chrg_687103334154240000" } - 2
Check the refund status
A
201response returns the refund object. Inspect itsstatusfield:succeeded: The refund was accepted and funds are returning to the customer.pending: The payment method confirms refunds asynchronously. Wait for therefund.succeededorrefund.failedwebhook.
If the refund is declined (for example, because the card is closed or the refund window has passed), the API returns HTTP
400witherror.type: "payment_method_error",error.code: "card_declined",error.decline_code,error.message, anderror.refundset to the refund ID. - 3
Listen for webhooks
Subscribe to these webhook events and verify every signature before acting on them:
refund.succeeded: The refund succeeded, and the funds are being returned to the customer.refund.failed: The refund was declined. You can use this event to alert your support team for a manual review.charge.refunded: Fires on every successful full or partial refund.refundedbecomestruewhen the charge balance reaches zero.
Error handling
Common refund validation errors and how to resolve them:
| Scenario | Error message | Resolution |
|---|---|---|
| Refund exceeds remaining balance | Requested amount exceeded refundable, or no refundable amount left (HTTP 422) | Check the charge's amount_refunded field to see how much is still refundable. |
| Charge already fully refunded | Requested amount exceeded refundable, or no refundable amount left (HTTP 422) | The charge balance is zero. No further refunds are possible. |
| Unknown charge ID | Unable to find charge with id chrg_… (HTTP 404) | Verify charge contains a valid charge ID from your workspace. |
| Malformed charge ID | The charge provided is not a valid charge id (HTTP 400) | Pass the full chrg_... ID returned when the charge was created. |
Next steps
Related payment and webhook guides:
- Create a charge: Accept card and alternative payments through the API.
- Hold and capture: Cancel a hold before capture to avoid issuing a refund.
- Webhooks: Set up webhook endpoints and verify signatures.