---
agentTools:
  projectIndex: https://docs.mundipagg.com/llms.txt
---

# Cancelar assinatura

Com o verbo HTTP DELETE, através do identificador da assinatura (`subscription_id`) é possível cancelar a assinatura.

# OpenAPI definition

```json
{
  "openapi": "3.1.0",
  "info": {
    "title": "Mundipagg API",
    "version": "1"
  },
  "servers": [
    {
      "url": "https://api.mundipagg.com/core/v1"
    }
  ],
  "components": {
    "securitySchemes": {
      "sec0": {
        "type": "http",
        "scheme": "basic"
      }
    }
  },
  "security": [
    {
      "sec0": []
    }
  ],
  "paths": {
    "/subscriptions/{subscription_id}": {
      "delete": {
        "summary": "Cancelar assinatura",
        "description": "Com o verbo HTTP DELETE, através do identificador da assinatura (`subscription_id`) é possível cancelar a assinatura.",
        "operationId": "cancelar-assinatura",
        "parameters": [
          {
            "name": "subscription_id",
            "in": "path",
            "description": "Código da Assinatura. <br>Formato: `sub_XXXXXXXXXXXXXXXX`.",
            "schema": {
              "type": "string"
            },
            "required": true
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "cancel_pending_invoices": {
                    "type": "boolean",
                    "description": "Parâmetro que define se as cobranças e faturas pendentes dentro de uma assinatura serão canceladas automaticamente com a execução do cancelamento da assinatura",
                    "default": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": "{\n    \"id\": \"sub_WeEMlp2FXFMjVq3Q\",\n    \"code\": \"8YNU49TD4Z\",\n    \"start_at\": \"2018-04-05T00:00:00Z\",\n    \"interval\": \"month\",\n    \"interval_count\": 1,\n    \"billing_type\": \"postpaid\",\n    \"boleto_due_days\":5,\n    \"current_cycle\": {\n        \"id\": \"cycle_6ow0JqhD5sJmMJPl\",\n        \"start_at\": \"2018-04-05T00:00:00Z\",\n        \"end_at\": \"2018-05-04T23:59:59Z\",\n        \"billing_at\": \"2018-04-05T00:00:00Z\"\n    },\n    \"setup\": {\n        \"id\": \"or_0Wd7bYRMSmSYy8qz\",\n        \"description\": \"Inscrição\",\n        \"amount\": 9990,\n        \"status\": \"paid\"\n    },\n    \"next_billing_at\": \"2018-04-05T00:00:00Z\",\n    \"payment_method\": \"boleto\",\n    \"currency\": \"BRL\",\n    \"statement_descriptor\": \"Spotify\",\n    \"installments\": 1,\n    \"status\": \"canceled\",\n    \"created_at\": \"2018-04-05T03:20:16Z\",\n    \"updated_at\": \"2018-04-05T12:14:06Z\",\n    \"canceled_at\": \"2018-04-05T12:14:06Z\",\n    \"customer\": {\n        \"id\": \"cus_px3yqRSlRsVqawgj\",\n        \"name\": \"Tony Stark\",\n        \"email\": \"ef61ded5-9e60-40c7-89cd-a3b6e70515e8@avengers.com\",\n        \"delinquent\": false,\n        \"created_at\": \"2018-04-05T03:20:15Z\",\n        \"updated_at\": \"2018-04-05T03:20:15Z\",\n        \"phones\": {}\n    },\n    \"plan\": {\n        \"id\": \"plan_dxVldzsgzu9rpe8v\",\n        \"name\": \"Premium\",\n        \"description\": \"Vá de Premium. E seja feliz!\",\n        \"url\": \"/plans/plan_dxVldzsgzu9rpe8v/vodafone-teste/premium\",\n        \"statement_descriptor\": \"Spotify\",\n        \"interval\": \"month\",\n        \"interval_count\": 1,\n        \"billing_type\": \"postpaid\",\n        \"payment_methods\": [\n            \"boleto\",\n            \"credit_card\"\n        ],\n        \"installments\": [\n            1\n        ],\n        \"status\": \"active\",\n        \"currency\": \"BRL\",\n        \"created_at\": \"2018-04-04T22:17:16Z\",\n        \"updated_at\": \"2018-04-04T22:17:16Z\"\n    },\n    \"items\": [\n        {\n            \"id\": \"si_5LPVYR1c7WuJd06l\",\n            \"name\": \"Name - Premium\",\n            \"description\": \"Test - Description\",\n            \"quantity\": 1,\n            \"status\": \"active\",\n            \"created_at\": \"2018-04-05T03:20:16Z\",\n            \"updated_at\": \"2018-04-05T03:20:16Z\",\n            \"pricing_scheme\": {\n                \"price\": 1490,\n                \"scheme_type\": \"unit\"\n            }\n        }\n    ]\n}"
                  }
                },
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "example": "sub_WeEMlp2FXFMjVq3Q"
                    },
                    "code": {
                      "type": "string",
                      "example": "8YNU49TD4Z"
                    },
                    "start_at": {
                      "type": "string",
                      "example": "2018-04-05T00:00:00Z"
                    },
                    "interval": {
                      "type": "string",
                      "example": "month"
                    },
                    "interval_count": {
                      "type": "integer",
                      "example": 1,
                      "default": 0
                    },
                    "billing_type": {
                      "type": "string",
                      "example": "postpaid"
                    },
                    "boleto_due_days": {
                      "type": "integer",
                      "example": 5,
                      "default": 0
                    },
                    "current_cycle": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "example": "cycle_6ow0JqhD5sJmMJPl"
                        },
                        "start_at": {
                          "type": "string",
                          "example": "2018-04-05T00:00:00Z"
                        },
                        "end_at": {
                          "type": "string",
                          "example": "2018-05-04T23:59:59Z"
                        },
                        "billing_at": {
                          "type": "string",
                          "example": "2018-04-05T00:00:00Z"
                        }
                      }
                    },
                    "setup": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "example": "or_0Wd7bYRMSmSYy8qz"
                        },
                        "description": {
                          "type": "string",
                          "example": "Inscrição"
                        },
                        "amount": {
                          "type": "integer",
                          "example": 9990,
                          "default": 0
                        },
                        "status": {
                          "type": "string",
                          "example": "paid"
                        }
                      }
                    },
                    "next_billing_at": {
                      "type": "string",
                      "example": "2018-04-05T00:00:00Z"
                    },
                    "payment_method": {
                      "type": "string",
                      "example": "boleto"
                    },
                    "currency": {
                      "type": "string",
                      "example": "BRL"
                    },
                    "statement_descriptor": {
                      "type": "string",
                      "example": "Spotify"
                    },
                    "installments": {
                      "type": "integer",
                      "example": 1,
                      "default": 0
                    },
                    "status": {
                      "type": "string",
                      "example": "canceled"
                    },
                    "created_at": {
                      "type": "string",
                      "example": "2018-04-05T03:20:16Z"
                    },
                    "updated_at": {
                      "type": "string",
                      "example": "2018-04-05T12:14:06Z"
                    },
                    "canceled_at": {
                      "type": "string",
                      "example": "2018-04-05T12:14:06Z"
                    },
                    "customer": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "example": "cus_px3yqRSlRsVqawgj"
                        },
                        "name": {
                          "type": "string",
                          "example": "Tony Stark"
                        },
                        "email": {
                          "type": "string",
                          "example": "ef61ded5-9e60-40c7-89cd-a3b6e70515e8@avengers.com"
                        },
                        "delinquent": {
                          "type": "boolean",
                          "example": false,
                          "default": true
                        },
                        "created_at": {
                          "type": "string",
                          "example": "2018-04-05T03:20:15Z"
                        },
                        "updated_at": {
                          "type": "string",
                          "example": "2018-04-05T03:20:15Z"
                        },
                        "phones": {
                          "type": "object",
                          "properties": {}
                        }
                      }
                    },
                    "plan": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "example": "plan_dxVldzsgzu9rpe8v"
                        },
                        "name": {
                          "type": "string",
                          "example": "Premium"
                        },
                        "description": {
                          "type": "string",
                          "example": "Vá de Premium. E seja feliz!"
                        },
                        "url": {
                          "type": "string",
                          "example": "/plans/plan_dxVldzsgzu9rpe8v/vodafone-teste/premium"
                        },
                        "statement_descriptor": {
                          "type": "string",
                          "example": "Spotify"
                        },
                        "interval": {
                          "type": "string",
                          "example": "month"
                        },
                        "interval_count": {
                          "type": "integer",
                          "example": 1,
                          "default": 0
                        },
                        "billing_type": {
                          "type": "string",
                          "example": "postpaid"
                        },
                        "payment_methods": {
                          "type": "array",
                          "items": {
                            "type": "string",
                            "example": "boleto"
                          }
                        },
                        "installments": {
                          "type": "array",
                          "items": {
                            "type": "integer",
                            "example": 1,
                            "default": 0
                          }
                        },
                        "status": {
                          "type": "string",
                          "example": "active"
                        },
                        "currency": {
                          "type": "string",
                          "example": "BRL"
                        },
                        "created_at": {
                          "type": "string",
                          "example": "2018-04-04T22:17:16Z"
                        },
                        "updated_at": {
                          "type": "string",
                          "example": "2018-04-04T22:17:16Z"
                        }
                      }
                    },
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "example": "si_5LPVYR1c7WuJd06l"
                          },
                          "name": {
                            "type": "string",
                            "example": "Name - Premium"
                          },
                          "description": {
                            "type": "string",
                            "example": "Test - Description"
                          },
                          "quantity": {
                            "type": "integer",
                            "example": 1,
                            "default": 0
                          },
                          "status": {
                            "type": "string",
                            "example": "active"
                          },
                          "created_at": {
                            "type": "string",
                            "example": "2018-04-05T03:20:16Z"
                          },
                          "updated_at": {
                            "type": "string",
                            "example": "2018-04-05T03:20:16Z"
                          },
                          "pricing_scheme": {
                            "type": "object",
                            "properties": {
                              "price": {
                                "type": "integer",
                                "example": 1490,
                                "default": 0
                              },
                              "scheme_type": {
                                "type": "string",
                                "example": "unit"
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "404",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": "{\n    \"message\": \"Subscription not found.\"\n}"
                  }
                },
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "example": "Subscription not found."
                    }
                  }
                }
              }
            }
          }
        },
        "deprecated": false,
        "x-readme": {
          "code-samples": [
            {
              "language": "csharp",
              "code": "using MundiAPI.PCL;\nusing MundiAPI.PCL.Models;\nusing System.Web.Mvc;\n\nnamespace MundipaggTest.Controllers {\n\n    public class HomeController : Controller {\n\n    public ActionResult Index() {\n\n    // Secret key fornecida pela Mundipagg\n    string basicAuthUserName = \"SUA_CHAVE_SECRETA\";\n    // Senha em branco. Passando apenas a secret key\n    string basicAuthPassword = \"\";\n\n    var client = new MundiAPIClient(basicAuthUserName, basicAuthPassword);\n\n    string subscrptionId = \"sub_WeEMlp2FXFMjVq3Q\";\n    \n    var request = new CreateCancelSubscriptionRequest {\n        CancelPendingInvoices = true\n    };\n\n    var response = client.Subscriptions.CancelSubscription(subscrptionId, request);\n\n    return View();\n    }\n}\n}",
              "name": "SDK C#"
            },
            {
              "language": "php",
              "code": "//This example was built using MundiAPI-PHP SDK.\n//For more information, please refer to https://github.com/mundipagg/MundiAPI-PHP\n\n$secretKey = 'YOUR_SECRET_KEY'; //the secret key will be provided by MundiPagg.\n$basicAuthPassword = ''; //fill it with an empty string\n\n$apiClient = new \\MundiAPILib\\MundiAPIClient(\n    $secretKey,\n    $basicAuthPassword\n);\n\n$subscriptionsController = $apiClient->getSubscriptions();\n\n$subscriptionId = \"sub_WeEMlp2FXFMjVq3Q\";\n\n$request = new \\MundiAPILib\\Models\\CreateCancelSubscriptionRequest();\n$request->cancelPendingInvoices = true;\n\n$result = $subscriptionsController->cancelSubscription($subscriptionId, $request);\n\necho json_encode($result, JSON_PRETTY_PRINT);",
              "name": "SDK PHP"
            },
            {
              "language": "java",
              "code": "package examples.subscription;\n\nimport com.mundipagg.api.MundiAPIClient;\nimport com.mundipagg.api.controllers.SubscriptionsController;\nimport com.mundipagg.api.http.client.*;\nimport com.mundipagg.api.models.*;\n\npublic class CreateCancelSubscription {\n\t\n\tpublic static void main(String[] args) {\n\n        String basicAuthUserName = \"YOUR_SECRET_KEY\"; // The username to use with basic authentication\n        String basicAuthPassword = \"\"; // The password to use with basic authentication\n\n        MundiAPIClient client = new MundiAPIClient(basicAuthUserName, basicAuthPassword);\n\n        SubscriptionsController subscriptions_controller = new SubscriptionsController();\n\n        String subscriptionId = \"sub_4qK9P5gtaipabMxV\";\n\n        CreateCancelSubscriptionRequest request = new CreateCancelSubscriptionRequest();\n\n        request.setCancelPendingInvoices(true);\n\n        subscriptions_controller.cancelSubscriptionAsync(subscriptionId, request, new APICallBack<GetSubscriptionResponse>() {\n            public void onSuccess(HttpContext context, GetSubscriptionResponse response) {\n\n                System.out.println(\"Status response: \" + context.getResponse().getStatusCode());\n                System.out.println(\"Subscription cancel !\");\n                System.out.println(\"Subscription id: \" + response.getId());\n                System.out.println(\"Subscription status: \" + response.getStatus());\n\n            }\n\n            public void onFailure(HttpContext context, Throwable error) {\n\n                System.out.println(\"Status response: \" + context.getResponse().getStatusCode());\n                System.out.println(error.getMessage());\n                error.printStackTrace();\n\n            }\n        });\n    }\n\n}",
              "name": "SDK JAVA"
            },
            {
              "language": "python",
              "code": "from mundiapi.mundiapi_client import MundiapiClient\nfrom mundiapi.models import *\nfrom mundiapi.controllers import *\nfrom mundiapi.exceptions.error_exception import *\n\nMundiapiClient.config.basic_auth_user_name = \"YOUR_SECRET_KEY:\"\nsubscriptions_controller = subscriptions_controller.SubscriptionsController()\n\nsubscriptionId = \"sub_2EvZ8GdFYZhXkbe4\"\n\nrequest = create_cancel_subscription_request.CreateCancelSubscriptionRequest()\nrequest.cancel_pending_invoices = True\n\ntry:\n    result = subscriptions_controller.cancel_subscription(request)\n    assert result is not None\n    assert result.status == \"canceled\"\n    print(\"Subscription Id: \", result.id)\n    print(\"Subscription status: \", result.status)\nexcept ErrorException as ex:\n    print(ex.message)\n    print(\"Errors: \", ex.errors)\nexcept Exception as ex:\n    raise ex",
              "name": "SDK PYTHON"
            }
          ],
          "samples-languages": [
            "csharp",
            "php",
            "java",
            "python"
          ]
        }
      }
    }
  },
  "x-readme": {
    "headers": [],
    "explorer-enabled": false,
    "proxy-enabled": false
  },
  "x-readme-fauxas": true,
  "_id": "5aba89f6b169810058a71e9a:5aba89f6b169810058a71ec6"
}
```