/refund
Initiate full or partial refunds on orders that were charged through FlexFactor.
Looking forPOST /v1/orders/{id}/refund?This page documents
POST /v1/refund, which names the order in the request body. The earlier request model, which names the order in the URL, is documented in Path-based request model at the bottom of this page.
Use /refund to return all or part of a captured charge to the cardholder. To release an order before it is captured, use /void or /cancel instead.
Prerequisites to invoke this API:
- Authenticate and send the bearer token for this call.
Idempotency
idempotencyKey(a GUID, in the JSON body) is required onPOST /v1/refund. A request without it returns400. Send a new key for each refund and reuse it only on retries — within the 24-hour replay window FlexFactor returns the original response instead of issuing a second credit, and a reused key carrying a different payload is rejected as a409conflict. See the Idempotency reference (§3.4) for the full replay-window, response-code, and retry behavior.Several partial refunds against one order are legitimate. Give each one its own key. A second refund under a new key is a new refund, not a retry.
Retrying a failed refund with the same key. A refund the processor declined is not stored against the key, so a retry with the same key runs the refund again. A refund that failed for an unexpected reason (
errorscontainsREFUND_FAILED) is stored, and a retry with the same key replays theFAILEDresponse without running the refund again, because the processor might already have credited the cardholder. Before issuing that refund again under a new key, confirm withGET /v1/orders/{id}thatrefundsAmountdoes not already include it.After a
400. A400that an order rule or an amount rule returns is also stored and replayed. After you correct the request, send a new key.On the path-based
POST /v1/orders/{id}/refundthe key is optional — see Path-based request model.
Request
Details
| HTTP Method | POST |
| Endpoint - Sandbox | https://api-sandbox.flexfactor.io/v1/refund |
| Endpoint - Production | https://api.flexfactor.io/v1/refund |
| Authentication | Bearer Token |
The URL carries no order ID. You identify the order in the request body.
Body
orderId | Guid | Conditional — send exactly one of orderId and orderExternalId | The FlexFactor orderId returned by /evaluate, GET /v1/orders/{id}, a webhook, or the SFTP batch. |
orderExternalId | String | Conditional — send exactly one of orderId and orderExternalId | Your own order ID: the orderId you sent in the original /evaluate request. Use it when you do not store the FlexFactor orderId. If several of your orders share this ID, the refund applies to the most recently created one. |
amount | Integer | Required | Amount to refund, in cents, for example 2500 for $25.00. A request without amount refunds nothing: it returns HTTP 200 with status: FAILED. |
idempotencyKey | Guid | Required | Send a new GUID for each refund and reuse it only on retries. It replays the original response within the 24h window and detects reused-key conflicts. See Idempotency. |
refundMessage | String | Optional | Additional message you want to send with the request, for example "Customer request". |
isConsumerRequestedRefund | Boolean | Optional | true when the cardholder requested the refund. |
Send exactly one order identifier per request. A request that carries both orderId and orderExternalId, or neither, returns 400.
Full and partial refunds
Full and partial refunds use the same request. amount is the amount to return to the cardholder, in cents, which matches /capture and /void. An amount equal to the captured amount is a full refund; a lower amount is a partial refund. You can issue several partial refunds against one order.
- There is no
currencyfield. The refund is applied in the currency of the original order. - Send a new
idempotencyKeywith each refund and reuse it only on retries (see the Idempotency callout at the top of this page). After a full refund, a further refund under a new key is rejected, because nothing remains to refund. - After a refund, the order stays
completed— a refund does not move it toreturned.GET /v1/orders/{id}reports the refunded total inrefundsAmount(dollars), and theorder.refundedwebhook fires withEventData.Amountin cents. See the state model in Workflows §3.5.
If the refund amount exceeds the remaining refundable balance, the request fails validation and returns HTTP 400.
Try it right now:
- Check out the /refund Reference.
- Check out our Postman Collection
Response
The refund response uses the common FlexFactor envelope, but on this endpoint status carries the refund outcome (SUCCESS or FAILED) rather than a transaction status such as APPROVED. Read success and status; result and statusCode are never populated on this endpoint and are always null. The envelope and the transaction state model are defined in Workflows §3.5.
status | string | Refund outcome: SUCCESS | FAILED. Key your refund logic on this field. |
success | boolean | true when errors is empty, that is, when the refund succeeded. |
result | string | Always null on this endpoint. Do not use it. |
responseCode | string | Processor response code. When FlexFactor rejects the refund before it reaches the processor, a FlexFactor code from 2001 to 3002 instead, for example 2001 (invalid refund amount) or 2004 (too many refund attempts). Optional |
responseMessage | string | Message that belongs to responseCode. Optional |
transactionId | guid | Identifier of the refund transaction. Set on success; null on failure. |
statusCode | string | Always null on this endpoint. It is not the HTTP status code. Do not use it. |
errors | array of objects | Error details for a failed refund; empty on success. Each item is serialized positionally: item1 message, item2 key, item3 error code, item4 friendly flag (boolean). An unexpected failure carries REFUND_FAILED. |
customProperties | object | Additional custom properties for the API request Optional |
HTTP status codes
A failed refund normally returns HTTP200A refund the processor declined, and a refund that failed for an unexpected reason, both return HTTP
200withstatus: FAILEDandsuccess: false, so that you can inspect the body and retry if appropriate. Checksuccessandstatuson every200; do not treat the HTTP code alone as the outcome.
| Situation | HTTP | Body |
|---|---|---|
| Refund succeeded | 200 | status: SUCCESS, success: true |
| Processor declined or returned a failure | 200 | status: FAILED, success: false, responseCode, responseMessage, errors |
FlexFactor rejected the refund before it reached the processor, for example because the request has no amount | 200 | status: FAILED, success: false, a FlexFactor code in responseCode |
| Unexpected error (for example a gateway or transport failure) | 200 | status: FAILED, success: false, errors contains REFUND_FAILED |
| The request, the order, or the amount failed a validation rule — see Validation errors | 400 | Problem details; errors maps a key to its messages |
| Invalid or expired bearer token | 401 | — |
No order matches orderId or orderExternalId, or the order belongs to another merchant | 404 | Problem details; the body can be empty |
Same idempotencyKey reused with a different body, or the first request is still running | 409 | Problem details — see Idempotency §3.4 |
An earlier attempt with the same idempotencyKey failed with an unknown outcome | 500 | Problem details |
| An internal error occurred | 500 | The plain text Refund call failed |
| Duplicate-request check temporarily unavailable | 503 | Problem details, with a Retry-After header; safe to retry |
For the error key and the message of each 400 on this endpoint, see Error Messages: /refund.
Validation errors
A 400 names the cause in the errors object of the problem details. <x.xx> and <y.yy> stand for amounts in dollars.
| Key | Message | Cause |
|---|---|---|
IdempotencyKey | An idempotency key is required. | The request carries no idempotencyKey |
OrderId | Provide exactly one of orderId or orderExternalId. | The request carries both identifiers, or neither |
General | Amount to refund (<x.xx>) is greater than maximum refund amount in (<y.yy>)) | amount is greater than the remaining refundable balance. An order with no captured funds has a maximum of 0.00 |
General | Available balance (<x.xx>) is less than discounts amount (<y.yy>) | The balance of the order is lower than the discount applied to it |
General | Refunds via API or Portal are disabled for this merchant | Refunds are not enabled for your account |
Updating the status orderAfter receiving a successful response from /refund, you need to update this order in your CRM with the corresponding status.
Payload examples
Request
curl --request POST \
--url https://api-sandbox.flexfactor.io/v1/refund \
--header 'Authorization: Bearer {the token returned by /oauth2}' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '
{
"orderId": "{orderId_returned_by_/evaluate}",
"amount": 9900, //in cents — equal to the captured amount
"refundMessage": "Customer request",
"idempotencyKey": "{generate_a_GUID_and_reuse_it_on_retries}"
}
'curl --request POST \
--url https://api-sandbox.flexfactor.io/v1/refund \
--header 'Authorization: Bearer {the token returned by /oauth2}' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '
{
"orderId": "{orderId_returned_by_/evaluate}",
"amount": 2500, //in cents — lower than the captured amount
"refundMessage": "Partial return",
"idempotencyKey": "{generate_a_GUID_and_reuse_it_on_retries}"
}
'curl --request POST \
--url https://api-sandbox.flexfactor.io/v1/refund \
--header 'Authorization: Bearer {the token returned by /oauth2}' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '
{
"orderExternalId": "{orderId_you_sent_to_/evaluate}",
"amount": 9900, //in cents — equal to the captured amount
"refundMessage": "Customer request",
"idempotencyKey": "{generate_a_GUID_and_reuse_it_on_retries}"
}
'Response
{
"status": "SUCCESS",
"success": true,
"result": null,
"responseCode": null,
"responseMessage": null,
"transactionId": "{{$guid}}",
"statusCode": null,
"errors": [],
"customProperties": {}
}{
"status": "FAILED",
"success": false,
"result": null,
"responseCode": "{processor response code}",
"responseMessage": "{processor response message}",
"transactionId": null,
"statusCode": null,
"errors": [
{ "item1": "{failure reason}", "item2": "{error key}", "item3": "{error code}", "item4": true }
],
"customProperties": {}
}Path-based request model
This request model will be deprecated
POST /v1/orders/{id}/refundremains available, and an integration that uses it does not need to change today. FlexFactor plans to deprecate it in favor ofPOST /v1/refund. No retirement date is set; the Changelog records the deprecation when it is scheduled. Build new integrations onPOST /v1/refund.
The path-based request model names the order in the URL instead of the request body. The refund behavior and the response are the same as on POST /v1/refund; the differences are in the table.
POST /v1/refund | POST /v1/orders/{id}/refund | |
|---|---|---|
| Where the order is named | Request body: orderId or orderExternalId | URL: the FlexFactor orderId as {id} |
| Refund by your own order ID | Supported, with orderExternalId | Not supported |
| Amount fields | amount (cents) | amount (cents), or the deprecated amountToRefund (dollars) |
idempotencyKey | Required | Optional — recommended |
| Response body | Refund envelope | Same refund envelope |
Path-based request details
| HTTP Method | POST |
| Endpoint - Sandbox | https://api-sandbox.flexfactor.io/v1/orders/{id}/refund |
| Endpoint - Production | https://api.flexfactor.io/v1/orders/{id}/refund |
{id} | The FlexFactor orderId returned by /evaluate, GET /v1/orders/{id}, a webhook, or the SFTP batch. |
| Authentication | Bearer Token |
Path-based request body
amount | Integer | Required, unless you send amountToRefund | Amount to refund, in cents, for example 2500 for $25.00. Do not send it together with amountToRefund. A request with neither amount field refunds nothing: it returns HTTP 200 with status: FAILED. |
amountToRefund | Decimal | Deprecated | Amount to refund, in dollars, for example 25.00. Still accepted on this endpoint; POST /v1/refund does not accept it. |
refundMessage | String | Optional | Additional message you want to send with the request, for example "Customer request". |
idempotencyKey | Guid | Optional — recommended | Send a new GUID for each refund and reuse it only on retries. See Idempotency. |
isConsumerRequestedRefund | Boolean | Optional | true when the cardholder requested the refund. |
The request body carries no order identifier. The route accepts only a GUID as {id}. A value that is not a GUID returns HTTP 404 with an empty body. A GUID that matches no order returns HTTP 200 with status: FAILED and REFUND_FAILED in errors.
A request without an idempotencyKey is processed, but nothing is stored and no response is replayed. If you repeat a full refund without a key, the cardholder is not credited twice: the second request is rejected, with 400 or with 200 and status: FAILED, because nothing remains to refund. The rejection does not tell you whether the first request succeeded, so confirm with GET /v1/orders/{id}.
Path-based response
The response body is the same as on POST /v1/refund — see Response. The HTTP status codes are also the same, except for the cases in the table. These rows do not apply to this endpoint: the 404 for an unknown order, the 400 for a missing idempotencyKey or order identifier, and the plain-text 500.
| Situation | HTTP | Body |
|---|---|---|
{id} is a GUID that matches no order | 200 | Refund envelope with status: FAILED and REFUND_FAILED in errors |
{id} is not a GUID | 404 | Empty |
| Error raised before the refund ran | 400 | Refund envelope with status: FAILED |
For the error key and the message of each 400 on the path-based endpoint, see Error Messages: /refund.
Path-based payload example
curl --request POST \
--url https://api-sandbox.flexfactor.io/v1/orders/{id}/refund \
--header 'Authorization: Bearer {the token returned by /oauth2}' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '
{
"amount": 2500, //in cents — lower than the captured amount
"refundMessage": "Partial return",
"idempotencyKey": "{generate_a_GUID_and_reuse_it_on_retries}"
}
'- Check out the /v1/orders/{id}/refund Reference.
Migrate to POST /v1/refund
- Change the URL from
/v1/orders/{id}/refundto/v1/refund. - Move the FlexFactor order ID from the URL into the request body as
orderId. - If you send
amountToRefund(dollars), multiply the value by 100 and send the result asamount:amountToRefund: 25.00becomesamount: 2500. - Send an
idempotencyKeyon every request.POST /v1/refundreturns400without one. - Keep every other field and your response handling unchanged.
GET /v1/orders/{id}still reportsrefundsAmountin dollars.
Updated 4 days ago

