/refund

Initiate full or partial refunds on orders that were charged through FlexFactor.

📌

Looking for POST /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:

📘

Idempotency

idempotencyKey (a GUID, in the JSON body) is required on POST /v1/refund. A request without it returns 400. 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 a 409 conflict. 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 (errors contains REFUND_FAILED) is stored, and a retry with the same key replays the FAILED response without running the refund again, because the processor might already have credited the cardholder. Before issuing that refund again under a new key, confirm with GET /v1/orders/{id} that refundsAmount does not already include it.

After a 400. A 400 that 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}/refund the key is optional — see Path-based request model.


Request

Details

HTTP MethodPOST
Endpoint - Sandboxhttps://api-sandbox.flexfactor.io/v1/refund
Endpoint - Productionhttps://api.flexfactor.io/v1/refund
AuthenticationBearer Token

The URL carries no order ID. You identify the order in the request body.

Body

orderIdGuidConditional — send exactly one of orderId and orderExternalIdThe FlexFactor orderId returned by /evaluate, GET /v1/orders/{id}, a webhook, or the SFTP batch.
orderExternalIdStringConditional — send exactly one of orderId and orderExternalIdYour 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.
amountIntegerRequiredAmount to refund, in cents, for example 2500 for $25.00. A request without amount refunds nothing: it returns HTTP 200 with status: FAILED.
idempotencyKeyGuidRequiredSend 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.
refundMessageStringOptionalAdditional message you want to send with the request, for example "Customer request".
isConsumerRequestedRefundBooleanOptionaltrue 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 currency field. The refund is applied in the currency of the original order.
  • Send a new idempotencyKey with 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 to returned. GET /v1/orders/{id} reports the refunded total in refundsAmount (dollars), and the order.refunded webhook fires with EventData.Amount in 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:


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.

statusstringRefund outcome: SUCCESS | FAILED. Key your refund logic on this field.
successbooleantrue when errors is empty, that is, when the refund succeeded.
resultstringAlways null on this endpoint. Do not use it.
responseCodestringProcessor 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
responseMessagestringMessage that belongs to responseCode. Optional
transactionIdguidIdentifier of the refund transaction. Set on success; null on failure.
statusCodestringAlways null on this endpoint. It is not the HTTP status code. Do not use it.
errorsarray of objectsError 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.
customPropertiesobjectAdditional custom properties for the API request Optional

HTTP status codes

❗️

A failed refund normally returns HTTP 200

A refund the processor declined, and a refund that failed for an unexpected reason, both return HTTP 200 with status: FAILED and success: false, so that you can inspect the body and retry if appropriate. Check success and status on every 200; do not treat the HTTP code alone as the outcome.

SituationHTTPBody
Refund succeeded200status: SUCCESS, success: true
Processor declined or returned a failure200status: FAILED, success: false, responseCode, responseMessage, errors
FlexFactor rejected the refund before it reached the processor, for example because the request has no amount200status: FAILED, success: false, a FlexFactor code in responseCode
Unexpected error (for example a gateway or transport failure)200status: FAILED, success: false, errors contains REFUND_FAILED
The request, the order, or the amount failed a validation rule — see Validation errors400Problem details; errors maps a key to its messages
Invalid or expired bearer token401—
No order matches orderId or orderExternalId, or the order belongs to another merchant404Problem details; the body can be empty
Same idempotencyKey reused with a different body, or the first request is still running409Problem details — see Idempotency §3.4
An earlier attempt with the same idempotencyKey failed with an unknown outcome500Problem details
An internal error occurred500The plain text Refund call failed
Duplicate-request check temporarily unavailable503Problem 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.

KeyMessageCause
IdempotencyKeyAn idempotency key is required.The request carries no idempotencyKey
OrderIdProvide exactly one of orderId or orderExternalId.The request carries both identifiers, or neither
GeneralAmount 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
GeneralAvailable balance (<x.xx>) is less than discounts amount (<y.yy>)The balance of the order is lower than the discount applied to it
GeneralRefunds via API or Portal are disabled for this merchantRefunds are not enabled for your account

❕

Updating the status order

After 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}/refund remains available, and an integration that uses it does not need to change today. FlexFactor plans to deprecate it in favor of POST /v1/refund. No retirement date is set; the Changelog records the deprecation when it is scheduled. Build new integrations on POST /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/refundPOST /v1/orders/{id}/refund
Where the order is namedRequest body: orderId or orderExternalIdURL: the FlexFactor orderId as {id}
Refund by your own order IDSupported, with orderExternalIdNot supported
Amount fieldsamount (cents)amount (cents), or the deprecated amountToRefund (dollars)
idempotencyKeyRequiredOptional — recommended
Response bodyRefund envelopeSame refund envelope

Path-based request details

HTTP MethodPOST
Endpoint - Sandboxhttps://api-sandbox.flexfactor.io/v1/orders/{id}/refund
Endpoint - Productionhttps://api.flexfactor.io/v1/orders/{id}/refund
{id}The FlexFactor orderId returned by /evaluate, GET /v1/orders/{id}, a webhook, or the SFTP batch.
AuthenticationBearer Token

Path-based request body

amountIntegerRequired, unless you send amountToRefundAmount 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.
amountToRefundDecimalDeprecatedAmount to refund, in dollars, for example 25.00. Still accepted on this endpoint; POST /v1/refund does not accept it.
refundMessageStringOptionalAdditional message you want to send with the request, for example "Customer request".
idempotencyKeyGuidOptional — recommendedSend a new GUID for each refund and reuse it only on retries. See Idempotency.
isConsumerRequestedRefundBooleanOptionaltrue 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.

SituationHTTPBody
{id} is a GUID that matches no order200Refund envelope with status: FAILED and REFUND_FAILED in errors
{id} is not a GUID404Empty
Error raised before the refund ran400Refund 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}"
}
'

Migrate to POST /v1/refund

  1. Change the URL from /v1/orders/{id}/refund to /v1/refund.
  2. Move the FlexFactor order ID from the URL into the request body as orderId.
  3. If you send amountToRefund (dollars), multiply the value by 100 and send the result as amount: amountToRefund: 25.00 becomes amount: 2500.
  4. Send an idempotencyKey on every request. POST /v1/refund returns 400 without one.
  5. Keep every other field and your response handling unchanged. GET /v1/orders/{id} still reports refundsAmount in dollars.

Did this page help you?