Skip to content

Refunds ​

Refund payments received through Payment Links or UPL. A refund works like a payment link in reverse. You create a refund, which gives you a refund link whose recipient is the original payer. The agent then pays that link over x402 (usually with a mandate), and the funds go back to the payer.

All management endpoints require Authorization: Bearer <agent-jwt>.

Refund flow overview ​

Agent                          FluxA API
  |-- POST /refunds/initiate --->|
  |<-- refundUrl (plr_…) --------|
  |-- GET refundUrl ------------>|
  |<-- 402 (payTo = payer) ------|
  |-- sign (x402V3Payment) ----->|
  |-- GET refundUrl + X-Payment->|
  |<-- 200 { refund.txHash } ----|
  1. Initiate. Call POST /api/payment-links/refunds/initiate with the original paymentId. The refund starts as pending and you get a refundUrl that's valid for 24 hours.
  2. Get the 402. GET the refundUrl. The 402 response has payTo set to the original payer's address.
  3. Pay. Sign the payment (for example with x402V3Payment and a USDC mandate) and send it in the X-Payment header.
  4. Done. The refund becomes settled.

TIP

In a refund link, payTo is the original payer. That is the key difference from a normal payment link.

Refund status ​

statusMeaning
pendingCreated and waiting for you to pay the refund link. refundUrl is set only in this state.
processingA refund payment was submitted and is being confirmed. Don't pay again.
settledThe refund was paid to the original payer. refundTxHash is set.
failedThe refund didn't go through.
expiredThe refund link expired before it was paid.
cancelledYou cancelled the refund.

Treat any other value as processing.


Initiate refund ​

POST/api/payment-links/refunds/initiateBearer agent-jwt
bash
curl -X POST https://walletapi.fluxapay.xyz/api/payment-links/refunds/initiate \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $JWT_TOKEN" \
  -d '{
    "paymentId": 43,
    "amount": "1000000",
    "reason": "Customer requested refund"
  }'

Request fields ​

FieldTypeRequiredDescription
paymentIdnumberYesID of the original payment: id from Received payments or Get payments for a link.
amountstringNoRefund amount in atomic units. Leave it out for a full refund of what's still refundable.
reasonstringNoReason for the refund. It's shown in the refund link's description.

Response (201) ​

json
{
  "refundId": "plr_abc123xyz456",
  "refundUrl": "https://walletapi.fluxapay.xyz/refundlink/plr_abc123xyz456",
  "paymentId": 43,
  "amount": "1000000",
  "currency": "USDC",
  "network": "base",
  "refundFrom": "0xLinkOwnerAddress",
  "refundTo": "0xOriginalPayerAddress",
  "refundType": "full",
  "reason": "Customer requested refund",
  "status": "pending",
  "expiresAt": "2026-10-28T12:00:00.000Z",
  "createdAt": "2026-10-27T12:00:00.000Z"
}

Error responses ​

StatusBodyWhen
400{ "error": "paymentId is required ..." }paymentId is missing or invalid.
400{ "error", "code": "credits_refund_unsupported" }Credits payments can't be refunded.
400{ "error": "Only settled payments can be refunded" }The original payment hasn't completed.
400{ "error": "Cannot refund: original payer address is unknown" }The payer can't be identified.
400{ "error": "Refund amount exceeds remaining refundable amount", "originalAmount", "totalRefunded", "remainingRefundable", "requestedAmount" }Over-refund.
404{ "error": "Payment not found or does not belong to you" }Unknown payment, or a payment this agent didn't receive.
409{ "error": "An active refund already exists for this payment", "existingRefundId", "existingStatus", "existingAmount" }Each payment can have only one open refund at a time. Finish or cancel it first.

Example over-refund body:

json
{
  "error": "Refund amount exceeds remaining refundable amount",
  "originalAmount": "5000000",
  "totalRefunded": "3000000",
  "remainingRefundable": "2000000",
  "requestedAmount": "3000000"
}

GET/refundlink/:refundId

This is a public endpoint and needs no authentication. Paying this URL sends the funds back to the original payer.

Step 1: Get the refund payment requirements ​

bash
curl -i https://walletapi.fluxapay.xyz/refundlink/plr_abc123xyz456

Response (402 Payment Required):

json
{
  "error": "Payment Required",
  "x402Version": 1,
  "accepts": [
    {
      "scheme": "exact",
      "network": "eip155:8453",
      "maxAmountRequired": "1000000",
      "resource": "/refundlink/plr_abc123xyz456",
      "description": "Refund: Customer requested refund",
      "mimeType": "application/json",
      "outputSchema": {},
      "payTo": "0xOriginalPayerAddress",
      "maxTimeoutSeconds": 60,
      "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
      "extra": { "name": "USD Coin", "version": "2" }
    }
  ]
}

Step 2: Submit the refund payment ​

Sign the payment, for example by passing these fields to x402V3Payment with a mandate. Then retry the same GET with the result in the X-Payment header (Payment-Signature is also accepted).

bash
curl -i https://walletapi.fluxapay.xyz/refundlink/plr_abc123xyz456 \
  -H "X-Payment: $X_PAYMENT_B64"

Outcomes ​

StatusBodyWhat to do
200{ "status": "success", "refund": { "refundId", "txHash", "amount", "currency", "refundTo" } }Done. The receipt is also in the X-Payment-Response header.
202{ "error": "Refund settlement result is unknown", "status": "processing" }The refund is being confirmed. Don't pay again. Poll Get refund detail.
402{ "error": "Refund payment failed", "reason": "..." }The payment was rejected. The refund stays pending. Sign a new payment and retry. Use reason for logs only.
404{ "error": "Refund link not found" }Unknown refund.
410{ "error": "...", "status": "settled" | "processing" | "failed" | "expired" | "cancelled" }The refund can no longer be paid.

Example 200:

json
{
  "status": "success",
  "refund": {
    "refundId": "plr_abc123xyz456",
    "txHash": "0xRefundTxHash...",
    "amount": "1000000",
    "currency": "USDC",
    "refundTo": "0xOriginalPayerAddress"
  }
}

List refunds ​

GET/api/payment-links/refundsBearer agent-jwt

List refunds created by this agent, newest first.

bash
curl "https://walletapi.fluxapay.xyz/api/payment-links/refunds?limit=20&offset=0" \
  -H "Authorization: Bearer $JWT_TOKEN"
ParamTypeDefaultDescription
limitnumber20Maximum number of results (up to 100).
offsetnumber0Pagination offset.

Response (200) ​

json
{
  "refunds": [
    {
      "refundId": "plr_abc123xyz456",
      "refundUrl": null,
      "paymentId": 43,
      "linkId": "pl_abc123",
      "sourceType": "payment_link",
      "amount": "1000000",
      "currency": "USDC",
      "network": "base",
      "refundFrom": "0xLinkOwnerAddress",
      "refundTo": "0xOriginalPayerAddress",
      "status": "settled",
      "refundTxHash": "0xRefundTxHash...",
      "refundType": "full",
      "reason": "Customer requested refund",
      "originalAmount": "1000000",
      "originalTxHash": "0xOriginalTxHash...",
      "agentName": "My Agent",
      "expiresAt": "2026-10-28T12:00:00.000Z",
      "createdAt": "2026-10-27T12:00:00.000Z"
    }
  ]
}

Response fields ​

FieldTypeDescription
refundIdstringRefund ID (plr_…).
refundUrlstring | nullRefund link. Set only while pending.
paymentIdnumberID of the original payment.
linkIdstring | nullPayment Link ID, or null for UPL payments.
sourceTypestringpayment_link or unify_payment_link.
amountstringRefund amount in atomic units.
currency / networkstringCurrency and network.
refundFromstringYour receiving address, which the original payment went to.
refundTostringRefund recipient (the original payer).
statusstringSee Refund status.
refundTxHashstring | nullOn-chain refund transaction hash.
refundTypestringfull or partial.
reasonstring | nullRefund reason.
originalAmountstringAmount of the original payment.
originalTxHashstring | nullTransaction hash of the original payment.
agentNamestring | nullName of the agent that started the refund.
expiresAtstringWhen the refund link expires (ISO 8601).
createdAtstringWhen the refund was created (ISO 8601).

Get refund detail ​

GET/api/payment-links/refunds/:refundIdBearer agent-jwt
bash
curl https://walletapi.fluxapay.xyz/api/payment-links/refunds/plr_abc123xyz456 \
  -H "Authorization: Bearer $JWT_TOKEN"

Response (200): the same shape as one entry in the list response. Returns 404 if the refund doesn't exist or wasn't created by this agent.


Cancel refund ​

POST/api/payment-links/refunds/:refundId/cancelBearer agent-jwt

Cancel a refund that hasn't been paid yet. Only pending refunds can be cancelled.

bash
curl -X POST https://walletapi.fluxapay.xyz/api/payment-links/refunds/plr_abc123xyz456/cancel \
  -H "Authorization: Bearer $JWT_TOKEN"

Response (200):

json
{
  "success": true,
  "refundId": "plr_abc123xyz456",
  "status": "cancelled",
  "updatedAt": "2026-10-27T12:05:00.000Z"
}
StatusBodyWhen
404{ "error": "Refund not found" }Unknown refund.
409{ "error": "Only pending refunds can be cancelled", "status": "..." }The refund is no longer pending.
409{ "error": "Refund has already expired", "status": "expired" }The refund link expired.
409{ "error": "Refund can no longer be cancelled", "status": "..." }A payment for the refund arrived while you were cancelling.

Released under the MIT License.