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

# Refund a charge

> Refund all or part of a paid charge to the merchant's wallet. Requires the WRITE_CHARGES scope.

Refunds a paid charge, in full or in part, to the merchant's wallet. Your payout wallet gives back the same share of what it received. See [Refunds](https://docs.salesive.com/apps/payments.md#refunds).


## OpenAPI

````yaml apps-api/specs/billing.json POST /app-billing/charges/{id}/refunds
openapi: 3.1.0
info:
  title: 'Salesive Apps API: Billing'
  version: 1.0.0
  description: >-
    Charge the merchant a store is installed for, once or on a schedule. Every
    endpoint authenticates with an installed-app access token (prefix `app_`).
    Creating a charge or subscription never moves money: the store owner
    approves it in the dashboard first. Salesive keeps 5% of every payment and
    credits the rest to your payout store's wallet.
servers:
  - url: https://api.salesive.com/api/v1
    description: Production
security:
  - AppToken: []
paths:
  /app-billing/charges/{id}/refunds:
    post:
      tags:
        - Charges
      summary: Refund a charge
      description: >-
        Refunds all or part of a paid charge to the merchant's wallet. Leave out
        `amount` to refund whatever is left. Your payout wallet gives back the
        same share of what it was credited, and Salesive gives back the same
        share of its 5% fee. Your payout wallet must cover that share, or the
        refund fails with `402` and nothing moves. A card payment is refunded to
        the merchant's wallet, never to the card. A charge can be refunded up to
        10 times and never for more than it was. `idempotencyKey` is required: a
        retry with the same key returns the same refund with `200`. Requires
        `WRITE_CHARGES`. Authenticate with `Authorization: Bearer app_<token>`.
        The store is bound to the token server-side, never send a shop id.
      operationId: createRefund
      parameters:
        - $ref: '#/components/parameters/ChargeId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - idempotencyKey
              properties:
                amount:
                  type: number
                  description: In the charge currency. Leave out to refund the rest.
                reason:
                  type: string
                  maxLength: 200
                  description: Shown to the merchant.
                idempotencyKey:
                  type: string
                  maxLength: 120
            example:
              amount: 5
              reason: Charged twice for the same seats
              idempotencyKey: refund-A-1042
      responses:
        '200':
          description: A refund with this idempotencyKey already exists; it is returned.
        '201':
          description: The refund.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/EnvelopeBase'
                  - type: object
                    properties:
                      data:
                        $ref: '#/components/schemas/Refund'
        '400':
          description: >-
            Invalid body, or more than is left to refund (`REFUND_TOO_LARGE`,
            with `remaining`).
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          description: >-
            Your payout wallet cannot cover its share (`REFUND_FAILED`). Nothing
            moved.
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          description: >-
            The charge is not paid (`NOT_PAID`), its payout is still settling
            (`PAYOUT_SETTLING`, try again in a few minutes), or it was refunded
            10 times (`TOO_MANY_REFUNDS`).
components:
  parameters:
    ChargeId:
      name: id
      in: path
      required: true
      description: The charge id.
      schema:
        type: string
  schemas:
    EnvelopeBase:
      type: object
      description: >-
        Standard Salesive response envelope. The operation-specific payload is
        carried in `data`.
      required:
        - status
        - success
        - message
      properties:
        status:
          type: integer
          description: HTTP status code, echoed in the body.
        success:
          type: boolean
          description: Whether the request succeeded.
        message:
          type: string
          description: Human-readable result message.
    Refund:
      type: object
      description: Money from a paid charge going back to the merchant's wallet.
      properties:
        id:
          type: string
        reference:
          type: string
          description: Starts with `apr_`.
        chargeId:
          type: string
        status:
          type: string
          enum:
            - reserving
            - processing
            - completed
            - failed
          description: >-
            `completed` means the merchant's wallet was credited. `failed` means
            nothing moved; see `failureReason`.
        amount:
          type: number
          description: Refunded, in the charge currency.
        currency:
          type: string
          enum:
            - USD
            - NGN
        platformFeeReturned:
          type: number
          description: The share of Salesive's fee given back, in `currency`.
        netAmountReturned:
          type: number
          description: The share of your net amount taken back, in `currency`.
        merchantAmount:
          type:
            - number
            - 'null'
          description: What reached the merchant's wallet, in `merchantCurrency`.
        merchantCurrency:
          type:
            - string
            - 'null'
        reason:
          type:
            - string
            - 'null'
        by:
          type: string
          enum:
            - app
            - admin
        test:
          type: boolean
        failureReason:
          type:
            - string
            - 'null'
        createdAt:
          type: string
          format: date-time
        completedAt:
          type:
            - string
            - 'null'
          format: date-time
    Envelope:
      allOf:
        - $ref: '#/components/schemas/EnvelopeBase'
        - type: object
          properties:
            data:
              description: Operation-specific payload (object, array, or null).
  responses:
    Unauthorized:
      description: Missing or invalid app access token.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Envelope'
          example:
            status: 401
            success: false
            message: Authentication required
            data: null
    Forbidden:
      description: The app token is missing the OAuth scope required for this operation.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Envelope'
          example:
            status: 403
            success: false
            message: Insufficient scope
            data: null
    NotFound:
      description: >-
        The resource does not exist or does not belong to the installation's
        store.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Envelope'
          example:
            status: 404
            success: false
            message: Resource not found
            data: null
  securitySchemes:
    AppToken:
      type: http
      scheme: bearer
      description: >-
        Installed-app access token (prefix app_), issued by the OAuth install
        flow. The store is bound to the token server-side, never send a shop id.

````

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