Cancel a Subscription

Cancels a subscription based on its UUID.

Examples
curl -X PATCH "https://api.chartmogul.com/v1/import/subscriptions/sub_e6bc5407-e258-4de0-bb43-61faaf062035" \
     -u YOUR_API_KEY: \
     -H "Content-Type: application/json" \
     -d '{ 
          "cancelled_at": "2022-01-15 00:00:00"
        }'
        
curl -X PATCH "https://api.chartmogul.com/v1/import/subscriptions/sub_e6bc5407-e258-4de0-bb43-61faaf062035" \
     -u YOUR_API_KEY: \
     -H "Content-Type: application/json" \
     -d '{ 
          "cancellation_dates": ["2022-01-01T10:00:00.000Z", "2023-01-01T10:00:00.000Z"]
        }'
customer = ChartMogul::Customer.retrieve('cus_f466e33d-ff2b-4a11-8f85-417eb02157a7')
subscription = customer.subscriptions.find{|e| e.uuid == 'sub_e6bc5407-e258-4de0-bb43-61faaf062035'}
subscription.cancel(Time.utc(2022, 1, 15))
ChartMogul.Subscription.cancel(config,
   "sub_e6bc5407-e258-4de0-bb43-61faaf062035", 
   { "cancelled_at": "2022-01-15 00:00:00" });

ChartMogul.Subscription.cancel(config,
   "sub_e6bc5407-e258-4de0-bb43-61faaf062035", 
   { "cancellation_dates": ["2022-01-01T10:00:00.000Z", "2023-01-01T10:00:00.000Z"] });
<?php

$canceldate = "2022-01-15 00:00:00";
$subscription = new ChartMogul\Subscription([
    "uuid" => "sub_e6bc5407-e258-4de0-bb43-61faaf062035"
]);
$subscription->cancel($canceldate);

// Or set cancellation dates
$cancellationDates = ["2022-01-01T10:00:00.000Z", "2023-01-01T10:00:00.000Z"];
$subscription->setCancellationDates($cancellationDates);
?>
api.CancelSubscription(
  "sub_e6bc5407-e258-4de0-bb43-61faaf062035",
  &cm.CancelSubscriptionParams{CancelledAt: "2022-01-15T00:00:00Z"})

api.CancelSubscription(
  "sub_e6bc5407-e258-4de0-bb43-61faaf062035",
  &cm.CancelSubscriptionParams{
    CancellationDates: []string{
      "2022-01-01T10:00:00.000Z", "2023-01-01T10:00:00.000Z"}})
chartmogul.Subscription.cancel(
    config,
    uuid="sub_e6bc5407-e258-4de0-bb43-61faaf062035",
    data={"cancelled_at": "2022-01-15 00:00:00"}
)
  
chartmogul.Subscription.cancel(
    config,
    uuid="sub_e6bc5407-e258-4de0-bb43-61faaf062035",
    data={"cancellation_dates":
          ["2022-01-01T10:00:00.000Z", "2023-01-01T10:00:00.000Z"] }
)
Result Format
{
  "uuid": "sub_e6bc5407-e258-4de0-bb43-61faaf062035",
  "external_id": "sub_0001",
  "customer_uuid": "cus_f466e33d-ff2b-4a11-8f85-417eb02157a7",
  "plan_uuid": "pl_eed05d54-75b4-431b-adb2-eb6b9e543206",
  "cancellation_dates": ["2022-01-15T00:00:00.000Z"],
  "data_source_uuid": "ds_fef05d54-47b4-431b-aed2-eb6b9e545430"
}

{
  "uuid": "sub_e6bc5407-e258-4de0-bb43-61faaf062035",
  "external_id": "sub_0001",
  "customer_uuid": "cus_f466e33d-ff2b-4a11-8f85-417eb02157a7",
  "plan_uuid": "pl_eed05d54-75b4-431b-adb2-eb6b9e543206",
  "cancellation_dates": ["2022-01-01T10:00:00.000Z", "2023-01-01T10:00:00.000Z"],
  "data_source_uuid": "ds_fef05d54-47b4-431b-aed2-eb6b9e545430"
}
#<ChartMogul::Subscription:0x007fb4991dae98 
@uuid="sub_e6bc5407-e258-4de0-bb43-61faaf062035", 
@external_id="sub_0001", 
@plan_uuid="pl_eed05d54-75b4-431b-adb2-eb6b9e543206",
@cancellation_dates=[2022-01-15 00:00:00 UTC],
@data_source_uuid="ds_fef05d54-47b4-431b-aed2-eb6b9e545430"
>
  
#<ChartMogul::Subscription:0x007fb4991dae98 
@uuid="sub_e6bc5407-e258-4de0-bb43-61faaf062035", 
@external_id="sub_0001", 
@plan_uuid="pl_eed05d54-75b4-431b-adb2-eb6b9e543206",
@cancellation_dates=[2022-01-01 00:00:00 UTC, 2023-01-01 00:00:00 UTC],
@data_source_uuid="ds_fef05d54-47b4-431b-aed2-eb6b9e545430"
>
{
  "uuid": "sub_e6bc5407-e258-4de0-bb43-61faaf062035",
  "external_id": "sub_0001",
  "customer_uuid": "cus_f466e33d-ff2b-4a11-8f85-417eb02157a7",
  "plan_uuid": "pl_eed05d54-75b4-431b-adb2-eb6b9e543206",
  "cancellation_dates": ["2022-01-15T00:00:00.000Z"],
  "data_source_uuid": "ds_fef05d54-47b4-431b-aed2-eb6b9e545430"
}

{
  "uuid": "sub_e6bc5407-e258-4de0-bb43-61faaf062035",
  "external_id": "sub_0001",
  "customer_uuid": "cus_f466e33d-ff2b-4a11-8f85-417eb02157a7",
  "plan_uuid": "pl_eed05d54-75b4-431b-adb2-eb6b9e543206",
  "cancellation_dates": ["2022-01-01T10:00:00.000Z", "2023-01-01T10:00:00.000Z"],
  "data_source_uuid": "ds_fef05d54-47b4-431b-aed2-eb6b9e545430"
}
<?php

ChartMogul\Subscription::__set_state(array(
   "uuid" => "sub_e6bc5407-e258-4de0-bb43-61faaf062035",
   "external_id" => "sub_0001",
   "cancellation_dates" => 
  array (
    0 => "2022-01-15T00:00:00.000Z",
  ),
   "plan_uuid" => "pl_eed05d54-75b4-431b-adb2-eb6b9e543206",
   "data_source_uuid" => "ds_fef05d54-47b4-431b-aed2-eb6b9e545430",
));

ChartMogul\Subscription::__set_state(array(
   "uuid" => "sub_e6bc5407-e258-4de0-bb43-61faaf062035",
   "external_id" => "sub_0001",
   "cancellation_dates" => 
  array (
    0 => "2022-01-01T00:00:00.000Z",
    1 => "2023-01-01T00:00:00.000Z",
  ),
   "plan_uuid" => "pl_eed05d54-75b4-431b-adb2-eb6b9e543206",
   "data_source_uuid" => "ds_fef05d54-47b4-431b-aed2-eb6b9e545430",
));
?>
(*chartmogul.Subscription)(0xc042004bd0)({
 UUID: (string) (len=40) "sub_e6bc5407-e258-4de0-bb43-61faaf062035",
 ExternalID: (string) (len=8) "sub_0001",
 PlanUUID: (string) (len=39) "pl_eed05d54-75b4-431b-adb2-eb6b9e543206",
 CustomerUUID: (string) (len=40) "cus_f466e33d-ff2b-4a11-8f85-417eb02157a7",
 DataSourceUUID: (string) (len=39) "ds_fef05d54-47b4-431b-aed2-eb6b9e545430",
 CancellationDates: ([]string) (len=1) {
  (string) (len=24) "2022-01-15T00:00:00.000Z"
 }
})

(*chartmogul.Subscription)(0xc042004bd0)({
 UUID: (string) (len=40) "sub_e6bc5407-e258-4de0-bb43-61faaf062035",
 ExternalID: (string) (len=8) "sub_0001",
 PlanUUID: (string) (len=39) "pl_eed05d54-75b4-431b-adb2-eb6b9e543206",
 CustomerUUID: (string) (len=40) "cus_f466e33d-ff2b-4a11-8f85-417eb02157a7",
 DataSourceUUID: (string) (len=39) "ds_fef05d54-47b4-431b-aed2-eb6b9e545430",
 CancellationDates: ([]string) (len=2) {
  (string) (len=24) "2022-01-01T00:00:00.000Z",
  (string) (len=24) "2023-01-01T00:00:00.000Z"
 }
})
<Subscription{
    cancellation_dates=[datetime.datetime(2022, 1, 15, 0, 0)], 
    customer_uuid='cus_f466e33d-ff2b-4a11-8f85-417eb02157a7', 
    data_source_uuid='ds_fef05d54-47b4-431b-aed2-eb6b9e545430', 
    external_id='sub_0001', 
    plan_uuid='pl_eed05d54-75b4-431b-adb2-eb6b9e543206', 
    uuid='sub_e6bc5407-e258-4de0-bb43-61faaf062035'}>

<Subscription{
    cancellation_dates=[
    	datetime.datetime(2022, 1, 1, 0, 0), datetime.datetime(2023, 1, 1, 0, 0)], 
    customer_uuid='cus_f466e33d-ff2b-4a11-8f85-417eb02157a7', 
    data_source_uuid='ds_fef05d54-47b4-431b-aed2-eb6b9e545430', 
    external_id='sub_0001', 
    plan_uuid='pl_eed05d54-75b4-431b-adb2-eb6b9e543206', 
    uuid='sub_e6bc5407-e258-4de0-bb43-61faaf062035'}>

In the response, the JSON object contains the following data:

  • uuid - The UUID of the subscription object generated by ChartMogul.
  • external_id - The unique external identifier for this subscription, as specified by you.
  • customer_uuid - the UUID of the customer whose subscription this is.
  • plan_uuid - The UUID of the plan object generated by ChartMogul.
  • cancellation_dates - An array of cancelled_at attributes specified by you. This is an array because a subscription may be re-activated and cancelled several times.
  • data_source_uuid - The UUID of the data source that this subscription plan belongs to.
Language
Credentials
Basic
base64
: