Skip to content

Create a Refund ​

Refund all or part of a transaction.

Required scope (OAuth only): create-refund

Parameters ​

ParameterTypeDescription
transaction_idstring requiredThe unique identifier of the transaction to refund.
amountnumber requiredThe amount to refund, in the transaction's own currency and minor units.
reasonstring requiredAccepted values: duplicate, fraudulent, requested-by-customer.
notestring optionalAn optional note about the refund.

Returns ​

Returns the created refund object if the request was successful.

Request ​

Endpoint: https://youcanpay.com/api/v2/refundsMethod: POST

bash
$ curl --location --request POST 'https://youcanpay.com/api/v2/refunds' \
  --form 'transaction_id="10e7691c-14a2-4936-833b-ec154c817ce9"' \
  --form 'amount="6000"' \
  --form 'reason="requested-by-customer"' \
  --form 'note="Customer changed their mind"' \
  --header 'Accept: application/json' \
  -u 'YOUR_PRIVATE_KEY:'

Response ​

json
{
  "object": "v2.refund",
  "id": "83cd9f6d-481a-49c4-9cc1-954c065e6063",
  "transaction_id": "10e7691c-14a2-4936-833b-ec154c817ce9",
  "amount": {
    "amount": "60.00",
    "currency": "MAD",
    "localized": "MAD 60.00"
  },
  "status": "pending",
  "is_processed": false,
  "reason": "requested-by-customer",
  "note": "Customer changed their mind",
  "processed_at": "2024-01-29 15:15:12"
}

Errors ​

ErrorDescription
Transaction not foundThe transaction_id doesn't match any transaction on your account.
Fully refundedThe transaction has already been fully refunded.
Exceeds available balanceThe requested amount is greater than what's available to refund.
Not refundableThe transaction is a CashPlus transaction, has already been paid out, or is otherwise not eligible for refund.