> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cryptoprocessing.us/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a refund

> Create a [manual refund](/payment-requests/refunds).

This API endpoint can only be used for payment requests initially created via the [/payments/v1/requests](https://docs.cryptoprocessing.us/api-reference/endpoints/payments.md) endpoint. For payment requests created via the portal, see [Create a manual refund](https://docs.cryptoprocessing.us/payment-requests/create-a-manual-refund.md).

The payment request must have the Paid status.

For every error this endpoint returns and what it means, see [API errors: Create a refund](https://docs.cryptoprocessing.us/api-reference/errors.md#create-a-refund).


## OpenAPI

````yaml POST /payments/v1/{payment_request_id}/refunds
openapi: 3.1.0
info:
  title: Merchant Backend V2
  version: '1.0'
  description: Documentation for merchant backend processing endpoints
servers:
  - url: https://app.cryptoprocessing.us/api
security:
  - xProcessingKey: []
tags:
  - name: Status
  - name: Balance
  - name: Currencies
  - name: Deposit addresses
  - name: Withdrawal
  - name: Exchange
  - name: Invoices
  - name: Transactions
  - name: Reporting
paths:
  /payments/v1/{payment_request_id}/refunds:
    post:
      tags:
        - Payment requests
      summary: Create a refund
      description: Create a [manual refund](/payment-requests/refunds).
      operationId: post-payments-refunds
      parameters:
        - $ref: '#/components/parameters/XProcessingSignatureHeader'
        - name: payment_request_id
          in: path
          required: true
          description: >-
            The [id](/api-reference/endpoints/payments#response-data-id) of the
            payment request.
          schema:
            type: string
            example: 019d511c-9fd2-7e71-b534-74e8abd855f1
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - amount
                - foreign_id
              properties:
                amount:
                  type: string
                  description: >
                    The amount to refund, in the payment request currency.


                    The amount must be not smaller than the [refund
                    fee](/payment-requests/fees) plus the [minimum withdrawal
                    amount](/confirmations-and-limits) and not greater than the
                    paid amount. If you have made a partial refund for this
                    payment earlier, the maximum amount of a new refund is
                    reduced accordingly.
                  example: '100'
                reason:
                  type: string
                  maxLength: 255
                  description: >-
                    A short description of why the payment is refunded. The
                    customer will see the reason in the email they receive.
                  example: Refund for order 0511
                foreign_id:
                  type: string
                  maxLength: 255
                  description: >-
                    Unique ID of the refund in your system. Must not contain
                    personal data, such as the customer's name or email address.
                  example: refund_123
            examples:
              Refund with a reason:
                value:
                  amount: '100'
                  reason: Refund for order 0511
                  foreign_id: refund_123
      responses:
        '200':
          description: '**OK**'
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    required:
                      - id
                      - status
                      - payment_request_id
                      - foreign_id
                      - amount
                      - currency
                      - refund_currency
                      - end_user_email
                    properties:
                      id:
                        type: string
                        description: The refund ID.
                        example: 019d5a2e-6c4b-7f13-9a85-3d7e1b20c4f8
                      status:
                        type: string
                        description: The refund status. Always `draft` for a new refund.
                        const: draft
                      payment_request_id:
                        type: string
                        description: >-
                          The
                          [id](/api-reference/endpoints/payments#response-data-id)
                          of the payment request.
                        example: 019d511c-9fd2-7e71-b534-74e8abd855f1
                      foreign_id:
                        type: string
                        description: The `foreign_id` from the request.
                        example: refund_123
                      amount:
                        type: string
                        description: The refund amount, in the payment request currency.
                        example: '100'
                      currency:
                        type: object
                        description: >-
                          The currency of the refund. Matches the
                          [currency](/api-reference/endpoints/payments#body-currency)
                          of the payment request.
                        properties:
                          iso:
                            type: string
                            description: >-
                              Currency code. See [API currency
                              codes](/api-reference/currency-codes).
                            example: USD
                          network_name:
                            type: string
                            description: >-
                              Blockchain network name. Present for
                              cryptocurrencies.
                      refund_currency:
                        type: object
                        description: >-
                          The cryptocurrency the customer gets the refund in.
                          Matches the payment request's
                          [payment_currency](/api-reference/endpoints/payments#response-data-payment-currency).
                        properties:
                          iso:
                            type: string
                            description: >-
                              Currency code. See [API currency
                              codes](/api-reference/currency-codes).
                            example: USDC
                          network_name:
                            type: string
                            description: >-
                              Blockchain network name. Present for
                              cryptocurrencies.
                            example: ethereum
                      reason:
                        type: string
                        description: >-
                          The `reason` from the request. Omitted if the request
                          didn't include one.
                        example: Refund for order 0511
                      end_user_email:
                        type: string
                        description: The `end_user_email` from the payment request.
                        example: chris.customer@example.com
              examples:
                Refund created:
                  value:
                    data:
                      id: 019d5a2e-6c4b-7f13-9a85-3d7e1b20c4f8
                      status: draft
                      payment_request_id: 019d511c-9fd2-7e71-b534-74e8abd855f1
                      foreign_id: refund_123
                      amount: '100'
                      currency:
                        iso: USD
                      refund_currency:
                        iso: USDC
                        network_name: ethereum
                      reason: Refund for order 0511
                      end_user_email: chris.customer@example.com
        '400':
          description: |
            **Bad Request**

            The request body isn't valid, or the `foreign_id` is already used.
          content:
            application/json:
              schema:
                type: object
                title: ErrorResponse
                required:
                  - error
                  - code
                properties:
                  error:
                    type: string
                    description: Human-readable error message.
                  code:
                    type:
                      - integer
                      - string
                    description: HTTP status code or error code.
              examples:
                Foreign ID already used:
                  value:
                    error: Refund with this foreign_id already exists.
                    code: 400
                Malformed JSON:
                  value:
                    error: Bad content format
                    code: bad_content_format
        '403':
          description: '**Forbidden**'
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: Human-readable error message.
                  code:
                    type:
                      - integer
                      - string
                    description: Error code.
                description: >-
                  Invalid or missing headers, the API key does not have access
                  to the endpoint, your merchant account is disabled, or manual
                  refunds are disabled for you. Refer to
                  [Errors](/api-reference/errors#general-errors) for
                  troubleshooting steps.
              examples:
                Bad signature header:
                  value:
                    error: Bad signature header
                    code: bad_header_signature
                API key does not have the required ability:
                  value:
                    error: The API key does not have access to this endpoint.
                    code: api_key_ability_required
                No signature header:
                  value:
                    error: No signature header
                    code: required_header_signature
                No key header:
                  value:
                    error: No key header
                    code: required_header_key
                Client is not enabled:
                  value:
                    error: Client is not enabled
                    code: client_disabled
                Manual refunds disabled:
                  value:
                    error: Manual refunds are disabled.
                    code: 403
        '404':
          description: |
            **Not Found**

            The payment request doesn't exist.
          content:
            application/json:
              schema:
                type: object
                title: ErrorResponse
                required:
                  - error
                  - code
                properties:
                  error:
                    type: string
                    description: Human-readable error message.
                  code:
                    type: integer
                    description: HTTP status code.
              examples:
                Payment request not found:
                  value:
                    error: Payment request not found.
                    code: 404
        '422':
          description: |
            **Unprocessable Entity**

            The request failed validation.
          content:
            application/json:
              schema:
                type: object
                title: ErrorResponse
                required:
                  - error
                  - code
                properties:
                  error:
                    type: string
                    description: Human-readable error message.
                  code:
                    type: integer
                    description: HTTP status code.
              examples:
                Payment request not paid:
                  value:
                    error: >-
                      Refund can only be created for payment requests with the
                      Paid status.
                    code: 422
                Refund period expired:
                  value:
                    error: The refund period for this payment request has expired.
                    code: 422
                Payment request not created via the API:
                  value:
                    error: >-
                      Refund is available only for payment requests created via
                      API.
                    code: 422
                Missing amount:
                  value:
                    error: The amount field is mandatory.
                    code: 422
                Nothing left to refund:
                  value:
                    error: No refundable amount available for this payment request.
                    code: 422
                Amount above the refundable amount:
                  value:
                    error: >-
                      The refund amount exceeds the available amount for this
                      payment request. The maximum refundable amount is
                      <amount>.
                    code: 422
                Amount below the minimum:
                  value:
                    error: The minimum refund amount is <amount> <currency>.
                    code: 422
                Too many decimal places:
                  value:
                    error: >-
                      The amount for <currency> cannot have more than <decimals>
                      decimal places.
                    code: 422
                Reason too long:
                  value:
                    error: The reason must be 255 characters or less.
                    code: 422
                Missing foreign_id:
                  value:
                    error: The foreign_id field is mandatory.
                    code: 422
                Foreign ID too long:
                  value:
                    error: The foreign_id must be 255 characters or less.
                    code: 422
                Refunds temporarily unavailable:
                  value:
                    error: >-
                      Refund creation is temporarily unavailable. Please try
                      again later.
                    code: 422
components:
  parameters:
    XProcessingSignatureHeader:
      name: X-Processing-Signature
      in: header
      required: true
      description: >-
        Hex-encoded HMAC-SHA512 signature of the request body, [generated using
        your secret key](/api-reference/authentication).
      schema:
        type: string
  securitySchemes:
    xProcessingKey:
      type: apiKey
      description: Your [API key](/merchant-administration/generate-and-activate-api-keys).
      in: header
      name: X-Processing-Key

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.