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

# Cancel  Subscription

> This API is used to cancel an **`ACTIVE`** or **`PAUSED`** subscription. Canceling a subscription works differently for the Prepaid and Postpaid billing cycles. If **`cancelAtEnd`** is used, the subscription will remain in **`ACTIVE`** state until the end of the billing cycle. At the end of the billing cycle, the subscription will be auto-canceled, and no new invoice will be raised. If **`cancelNow`** is used, it will change the status from **`ACTIVE`** to **`CANCELLED`** then only.

For `Prepaid`, **`cancelNow`** will not revert the amount paid at the start of the cycle but will issue adjustment credits for that customer, which can be used in the future for any subscription payments. Therefore, it is recommended to use **`cancelAtEnd`** to cancel a **`ACTIVE`** subscription.

For `Postpaid`, **`cancelNow`** and **`cancelAtEnd`** can be used. If **`cancelNow`** is used, it will raise a pro-rate-based invoice and will try to debit the amount using the auto-debit mandate if available.

In the subscription analytics, this is considered as if the user has requested to drop out of the subscription.



## OpenAPI

````yaml /api-reference/subscriptions/subs.json post /subscription/v1.0/cancelSubscription
openapi: 3.0.3
info:
  title: Subscription API
  description: API for creating and managing subscription sessions and payments.
  version: 1.0.0
servers:
  - url: https://sandbox-api.transactbridge.com
    description: Sandbox Environment
  - url: https://api.transactbridge.com
    description: Production Environment
security:
  - ApiKeyAuth: []
    SignatureAuth: []
paths:
  /subscription/v1.0/cancelSubscription:
    post:
      tags:
        - Subscription
      summary: Cancel  Subscription
      description: >-
        This API is used to cancel an **`ACTIVE`** or **`PAUSED`** subscription.
        Canceling a subscription works differently for the Prepaid and Postpaid
        billing cycles. If **`cancelAtEnd`** is used, the subscription will
        remain in **`ACTIVE`** state until the end of the billing cycle. At the
        end of the billing cycle, the subscription will be auto-canceled, and no
        new invoice will be raised. If **`cancelNow`** is used, it will change
        the status from **`ACTIVE`** to **`CANCELLED`** then only.


        For `Prepaid`, **`cancelNow`** will not revert the amount paid at the
        start of the cycle but will issue adjustment credits for that customer,
        which can be used in the future for any subscription payments.
        Therefore, it is recommended to use **`cancelAtEnd`** to cancel a
        **`ACTIVE`** subscription.


        For `Postpaid`, **`cancelNow`** and **`cancelAtEnd`** can be used. If
        **`cancelNow`** is used, it will raise a pro-rate-based invoice and will
        try to debit the amount using the auto-debit mandate if available.


        In the subscription analytics, this is considered as if the user has
        requested to drop out of the subscription.
      operationId: cancelSubscription
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - subscriptionId
              properties:
                subscriptionId:
                  type: string
                  format: MongoId
                  description: >-
                    Subscription Id of the subscription for which update is
                    needed.
                cancelAtEnd:
                  type: boolean
                  description: >-
                    Subscriptions will be canceled at the end of the cycle. If
                    **`cancelAtEnd`** is used to cancel a subscription. In
                    response to this API, the subscription remains in the
                    **`ACTIVE`** state and **`cancelAtEnd`** the parameter is
                    changed to **`true`**.Mandatory if cancelNow is not passed
                cancelNow:
                  type: boolean
                  description: >-
                    Subscriptions will be canceled immediately.Manadatory if
                    cancelAtEnd is not passed
              anyOf:
                - required:
                    - cancelAtEnd
                - required:
                    - cancelNow
      responses:
        '200':
          description: Cancel subscription.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/cancelSubscription'
components:
  schemas:
    cancelSubscription:
      type: object
      properties:
        status:
          type: string
          description: The response from the API
        sub_status:
          type: string
          description: Used for internal purposes only
        data:
          type: object
          description: Contains the updated subscription details.
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: Merchant API Key
    SignatureAuth:
      type: apiKey
      in: header
      name: x-signature
      description: Generated request signature

````

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