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

# Expire a Charge

> Programmatically expire an unpaid charge to cancel a pending checkout session or invalidate a payment link.

<Info>
  **Note:** When using the production environment at [moonpay.hel.io](http://app.hel.io), set your API endpoint to `api.hel.io/v1` and generate API keys there. For the development environment, use `api.dev.hel.io/v1` and generate API keys from [moonpay.dev.hel.io](http://app.dev.hel.io).
</Info>


## OpenAPI

````yaml POST /v1/charge/api-key/{token}/expire
openapi: 3.0.0
info:
  title: Helio Open API
  description: |-
    API schema and definitions for Helio API. <br/> 
          The API is using two types of Authentication, for dashboard endpoints we use <b>JSON Web Token (JWT)</b> that is generated by self custodial wallet signing a message from API.</br> 
          We also support authentication with <b>API Key and Secret</b> which can be generated on <a href='https://hel.io'>Helio dashboard</a>.
  version: 1.0.0
  contact: {}
servers:
  - description: Helio API (Mainnet)
    url: https://api.hel.io
  - description: Helio API (Devnet)
    url: https://api.dev.hel.io
security: []
tags:
  - name: Webhooks
  - name: Exports
  - name: Currencies
    description: >-
      Supported currencies endpoint, includes fiat and digital assets
      </br><i>Authentication: </i><b>None</b>
externalDocs:
  description: Helio product documentation
  url: https://docs.hel.io/
paths:
  /v1/charge/api-key/{token}/expire:
    post:
      tags:
        - Charge
      summary: Expire a Charge
      description: >-
        Merchants can programmatically expire an unpaid charge via the API. This
        is useful when you want to cancel a pending checkout session—for
        example, the order was cancelled, the customer abandoned the session, or
        you want to invalidate the payment link.


        The charge must not have a successful or pending transaction. The
        `token` path parameter is the charge token—the same value as in the
        charge URL path and the `token` field on the charge object.
      operationId: ChargeController_expireByApiKey
      parameters:
        - name: token
          in: path
          required: true
          description: >-
            The charge token (e.g. the segment at the end of
            `https://app.hel.io/charge/{token}`).
          schema:
            type: string
        - name: apiKey
          in: query
          required: true
          description: >-
            Your API key, which can be generated from the Helio Dashboard
            settings page.
          schema:
            type: string
      responses:
        '204':
          description: The charge was expired successfully. No response body.
        '400':
          description: >-
            The charge cannot be expired because it has a successful or pending
            transaction.
          content:
            application/json:
              examples:
                badRequest:
                  summary: Charge has active transaction
                  value:
                    message: >-
                      Cannot expire a charge that has a successful or pending
                      transaction
                    statusCode: 400
        '401':
          description: >-
            Invalid API key, or the API key is not allowed to expire this
            charge.
          content:
            application/json:
              examples:
                unauthorized:
                  summary: Invalid or missing API key
                  value:
                    message: Api key or token is invalid
                    code: 401
                notAllowed:
                  summary: Not allowed to expire this charge
                  value:
                    message: Not allowed to expire charge
                    statusCode: 401
        '404':
          description: No charge exists for the given token.
          content:
            application/json:
              examples:
                notFound:
                  summary: Charge not found
                  value:
                    message: >-
                      Charge not found for token
                      "00000000-0000-0000-0000-000000000000"
                    statusCode: 404
      security:
        - bearer: []
components:
  securitySchemes:
    bearer:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Authentication using JWT token

````