# Cancel subscription contract

> Cancel a subscription contract immediately, at the end of the current billing cycle, or on a specified date.

```yaml
openapi: 3.1.0
info:
  title: Cancel subscription contract
  version: 1.0.0
  description: Cancel a subscription contract immediately, at the end of the
    current billing cycle, or on a specified date.
paths:
  /v1/txn/sub/cancel:
    post:
      summary: Cancel subscription contract
      description: Cancel a subscription contract immediately, at the end of the
        current billing cycle, or on a specified date.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                merchantNo:
                  type: string
                  description: Merchant number assigned by Onerway. See
                    [Setup](/payments/get-started/setup#retrieve-your-credentials)
                    for how to obtain it.
                contractId:
                  type: string
                  description: Subscription contract number to cancel. It normally comes from the
                    initial subscription response, webhook, or [Query
                    subscription
                    details](/payments/api-reference/endpoints/query-subscription-details).
                expireMode:
                  type: string
                  description: How the subscription cancellation takes effect. When both
                    `expireMode` and `expireDate` are omitted, the subscription
                    is canceled at the end of the current billing cycle.
                  enum:
                    - "1"
                    - "2"
                    - "3"
                  x-enum-descriptions:
                    "1": Cancel immediately. The subscription cancellation notification is sent
                      immediately; Onerway-managed subscriptions also send an
                      email notification to the customer.
                    "2": Cancel at the end of the current billing cycle.
                    "3": Cancel on a specified date. Submit `expireDate`; the cancellation
                      notification is sent when the cancellation takes effect.
                expireDate:
                  type: string
                  description: Date when cancellation takes effect, in `yyyy-MM-dd` format.
                  x-onerway-required: conditional
                  x-onerway-condition:
                    - Required when `expireMode=3`, cancel on a specified date.
                sign:
                  type: string
                  description: Request signature string. See [Request
                    signing](/payments/get-started/request-signing) for how to
                    generate it.
              required:
                - merchantNo
                - contractId
                - sign
            examples:
              cancel-subscription-immediately:
                summary: Cancel a subscription immediately
                value:
                  contractId: sub_contract_demo_202606210001
                  expireMode: "1"
                  merchantNo: replace_with_merchant_no
                  sign: "{{SIGN}}"
      responses:
        "200":
          description: Response
          content:
            application/json:
              schema:
                type: object
                properties:
                  respCode:
                    type: string
                    description: "`20000` means the cancellation request was processed successfully.
                      Other values are error codes. See [Response
                      codes](/payments/api-reference/response-codes)."
                  respMsg:
                    type: string
                    description: Human-readable message for the response code.
                  data:
                    type: string
                    description: Subscription contract status after cancellation. The successful
                      cancellation example returns `3`.
                    enum:
                      - "0"
                      - "1"
                      - "2"
                      - "3"
                    x-enum-descriptions:
                      "0": Processing.
                      "1": Effective.
                      "2": Ineffective.
                      "3": Canceled.
```
