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

# Refund a charge

> Refund a cleared charge on a sandbox card.

Refunds a cleared charge. As on a live card, the refund arrives as a new transaction with a negative amount, so your code has to handle one.


## OpenAPI

````yaml openapi.json POST /api/v2/cards/{card_id}/test_transactions/{transaction_id}/refund
openapi: 3.1.0
info:
  title: Agentcard API
  version: 2.0.0
  description: >-
    The Agentcard v2 API — connect your users and verify their identity from
    your own backend. Every call is authenticated with a platform access token
    minted from your `client_id` + `client_secret`.
servers:
  - url: https://api.agentcard.sh
    description: >-
      There is one base URL. Sandbox vs production is decided by the client
      credential you use, never by the host.
security:
  - platformToken: []
tags:
  - name: Authentication
    description: >-
      Exchange your client credentials for a platform access token, and
      introspect what a token acts as.
  - name: Connect
    description: >-
      Connect a user to your platform: send a one-time code, verify it, record
      consent, and keep the connection alive.
  - name: Identity verification
    description: >-
      Verify a connected user's identity: upload their ID, submit any extra
      fields we ask for, then show a short face scan.
paths:
  /api/v2/cards/{card_id}/test_transactions/{transaction_id}/refund:
    post:
      tags:
        - Cards
      summary: Refund a charge
      description: >-
        Sandbox only. Refunds a cleared transaction, for all of it or part. As
        on a live card, the refund arrives as a new transaction with a negative
        amount, and sends `transaction.cleared`. The original transaction
        doesn't change.
      operationId: cardTestRefund
      parameters:
        - name: card_id
          in: path
          required: true
          schema:
            type: string
        - name: transaction_id
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              properties:
                amount_cents:
                  type: integer
                  minimum: 1
                  description: Defaults to the full charge.
      responses:
        '201':
          description: The new refund transaction.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TestTransaction'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          description: >-
            `sandbox_only`: you sent a production credential. Real merchants
            charge live cards.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: >-
            `card_not_found` or `transaction_not_found`: no such card, or no
            simulated transaction with that id on it.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: >-
            `invalid_transaction_state`: the transaction isn't in a state this
            call accepts.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - platformToken: []
components:
  schemas:
    TestTransaction:
      type: object
      required:
        - object
        - id
        - card_id
        - amount_cents
        - merchant
        - status
        - simulated
        - events
        - card
      properties:
        object:
          type: string
          const: test_transaction
        id:
          type: string
        card_id:
          type: string
        amount_cents:
          type: integer
          description: Negative on a refund.
        merchant:
          type: string
        mcc:
          type: string
        status:
          type: string
          enum:
            - authorized
            - cleared
            - declined
            - voided
            - refunded
        decline_reason:
          type: string
        original_transaction_id:
          type: string
          description: On a refund, the transaction it refunds.
        simulated:
          type: boolean
          const: true
        events:
          type: array
          items:
            type: string
          description: The webhook events this call sent.
        card:
          $ref: '#/components/schemas/Card'
    Error:
      type: object
      description: Every v2 error uses the same envelope.
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              description: A stable, machine-readable string (snake_case). Branch on this.
            message:
              type: string
              description: A human-readable explanation, safe to log.
            docs:
              type: string
              description: A link back to the reference.
            field_errors:
              type: object
              additionalProperties:
                type: string
              description: Only on `invalid_fields` — names each field to fix.
            warnings:
              type: array
              items:
                type: string
              description: >-
                Only on document upload errors — actionable feedback safe to
                show the user.
    Card:
      type: object
      required:
        - object
        - id
        - status
        - spend_limit_cents
        - balance_cents
        - last4
        - expiry
        - type
        - created_at
      properties:
        object:
          type: string
          description: Always `card`.
          enum:
            - card
        id:
          type: string
          description: The card's id.
        status:
          type: string
          description: >-
            `creating`, `open`, `in_use`, `paused`, `pausing`, `closing`, or
            `closed`.
        type:
          type: string
          description: '`single_use` or `multi_use`.'
        spend_limit_cents:
          type: integer
          description: What the card can spend in all.
        balance_cents:
          type: integer
          description: What's left to spend.
        last4:
          type: string
          description: The last four digits.
        expiry:
          type: string
          description: '`MM/YY`.'
        user_id:
          type:
            - string
            - 'null'
          description: The user the card is for.
        cardholder_name:
          type: string
          description: The name the card was issued in, for the payment form.
        billing_address:
          type: string
          description: The billing address, for the payment form.
        funds_source:
          type: string
          description: 'On a new card: what funded it.'
        transfer_id:
          type: string
          description: 'On a company-funded new card: the transfer that funded it.'
        closed_reason:
          type: string
          description: 'Only when `closed`: `used`, `canceled`, `expired`, `declined`.'
        card_expires_at:
          type: string
          description: When a `multi_use` card closes itself.
          format: date-time
        created_at:
          type: string
          description: When it was issued.
          format: date-time
  responses:
    Unauthorized:
      description: >-
        `unauthorized` — the platform access token is missing or expired.
        Exchange your client credentials for a fresh one.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    platformToken:
      type: http
      scheme: bearer
      description: >-
        A platform access token. Get one on the **Create an access token**
        endpoint by exchanging your `client_id` + `client_secret`, then send it
        as `Authorization: Bearer <token>`. Tokens live one hour.

````

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