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

# Cancel a Subscription

Use this endpoint to cancel an existing subscription. This action will prevent any future recurring payments associated with the subscription.

**Important Notes:**

* Cancellation may not result in a refund for the remaining subscription period. Please refer to your subscription terms for details on refunds.
* Ensure that you cancel the subscription before the next billing date to avoid any unwanted charges.
* You can use the [Get Subscription Status](https://docs.localpayment.com/reference/transaction-status-error-codes) endpoint to verify the cancellation.

This endpoint requires a valid `subscriptionId`. Once a subscription is canceled, it cannot be resumed. You would need to create a new subscription if you wish to reactivate the service.


## OpenAPI

````yaml openapi/localpayment.json PATCH /api/payin/subscriptions/{subscriptionId}/status
openapi: 3.1.0
info:
  version: '1.0'
  title: Localpayment
  contact:
    name: Support
    url: mailto:support@localpayment.com
servers:
  - url: https://api.stage.localpayment.com
    description: Stage
security:
  - token: []
paths:
  /api/payin/subscriptions/{subscriptionId}/status:
    patch:
      summary: Cancel a Subscription
      operationId: cancel-subscription
      parameters:
        - name: Authorization
          in: header
          description: >-
            Bearer access token for authentication. This token is obtained from
            the [Get Access Token](/reference/get-token) or [Refresh Access
            Token](/reference/refresh-token) endpoints.
          required: true
          schema:
            type: string
        - name: subscriptionId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                status:
                  const: CANCEL
                  description: Change the status to `CANCELLED`.
              required:
                - status
              x-examples:
                Example 1:
                  status: CANCELLED
            examples:
              CANCELLED:
                value:
                  status: CANCELLED
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  externalId:
                    type: string
                    description: >-
                      A unique identifier generated by your system to track the
                      transaction (alphanumeric and hyphens). We recommend using
                      UUID4 to ensure uniqueness.
                  subscriptionId:
                    type: string
                    description: Unique identifier for the subscription.
                  status:
                    type: object
                    title: status
                    description: Operation status.
                    properties:
                      code:
                        type: string
                        description: >-
                          [Status
                          code](/reference/transaction-status-error-codes).
                      description:
                        type: string
                        description: >-
                          [Status
                          description](/reference/transaction-status-error-codes).
                      detail:
                        type: string
                        description: Additional status information.
                  totalPayments:
                    type: integer
                    description: Total number of payments associated with the subscription.
                  pendingPayments:
                    type: integer
                    description: >-
                      Number of payments that are still pending for the
                      subscription.
                  creationDate:
                    type: string
                    description: >-
                      Date and time when the subscription was created. The
                      format should follow a valid date-time string (e.g., ISO
                      8601).
                  payments:
                    type: array
                    description: >-
                      Array of objects representing the payments associated with
                      the subscription.
                    items:
                      type: object
                  retries:
                    type: integer
                    description: >-
                      Number of retry attempts made for processing the
                      subscription payments.
                x-examples:
                  Example 1:
                    externalId: '1623451995'
                    subscriptionId: 498e4a08-13a8-405e-96a5-eccb44345ada
                    status:
                      code: '903'
                      description: CANCELLED
                      detail: The subscription was canceled - merchant request
                    totalPayments: 2
                    pendingPayments: 2
                    creationDate: '2021-06-11T22:53:15.622+00:00'
                    payments: []
                    retries: 0
              examples:
                903 - The subscription was canceled:
                  value:
                    externalId: '1623451995'
                    subscriptionId: 498e4a08-13a8-405e-96a5-eccb44345ada
                    status:
                      code: '903'
                      description: CANCELLED
                      detail: The subscription was canceled - merchant request
        '400':
          description: Bad Request.
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: object
                    title: status
                    description: Operation status.
                    properties:
                      code:
                        type: string
                        description: >-
                          [Status
                          code](/reference/transaction-status-error-codes).
                      description:
                        type: string
                        description: >-
                          [Status
                          description](/reference/transaction-status-error-codes).
                      detail:
                        type: string
                        description: Additional status information.
                x-examples:
                  Example 1:
                    status:
                      code: '400'
                      description: ERROR
                      detail: Invalid operation
              examples:
                400 - Invalid operation:
                  value:
                    status:
                      code: '400'
                      description: ERROR
                      detail: Invalid operation
        '401':
          description: Unauthorized.
          content:
            application/json:
              schema:
                type: object
                properties:
                  detail:
                    type: string
                    description: Additional information of the response.
                  code:
                    type: string
                    description: Status code.
                  messages:
                    type: array
                    description: Message list.
                    items:
                      type: object
                      properties:
                        token_class:
                          type: string
                          description: Token class.
                        token_type:
                          type: string
                          description: Token type.
                        message:
                          type: string
                          description: Message with additional information.
                x-examples:
                  Example 1:
                    detail: Given token not valid for any token type
                    code: token_not_valid
                    messages:
                      - token_class: AccessToken
                        token_type: access
                        message: Token is invalid or expired
              examples:
                401 - Token is invalid or expired:
                  value:
                    detail: Given token not valid for any token type
                    code: token_not_valid
                    messages:
                      - token_class: AccessToken
                        token_type: access
                        message: Token is invalid or expired
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: object
                    title: status
                    description: Operation status.
                    properties:
                      code:
                        type: string
                        description: >-
                          [Status
                          code](/reference/transaction-status-error-codes).
                      description:
                        type: string
                        description: >-
                          [Status
                          description](/reference/transaction-status-error-codes).
                      detail:
                        type: string
                        description: Additional status information.
                x-examples:
                  Example 1:
                    status:
                      code: '404'
                      description: ERROR
                      detail: Subscription not found
              examples:
                404 - Subscription not found:
                  value:
                    status:
                      code: '404'
                      description: ERROR
                      detail: Subscription not found
      security:
        - token: []
      servers:
        - url: https://api.stage.localpayment.com
          description: Stage
components:
  securitySchemes:
    token:
      type: http
      scheme: bearer

````

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