Cancel Page Object

A Cancel Page instance is used to control and integrate cancel pages during subscription cancellation flows.

Create a cancelPage object using the chargebee object to use the functions listed below.

Tutorials

For step-by-step integration, see the Cancel Pages tutorials.

Attach the cancellation handler

attachCancelHandler()

Attaches a click handler to the cb‑cancel element to initialize the cancel page flow.

How it works

1. Request the cancel page URL

Sends options to Chargebee and stores the returned cancel page URL.

2. Attach the click handler

  1. Finds the DOM element with the id cb‑cancel.
  2. Registers a click listener that:
    • Redirects to the cancel page URL, if one was obtained and stored in the previous step.
    • Otherwise, as a fallback, redirects to the element’s href value, if present.

Example

cancelPage.attachCancelHandler({
  account: {
    firstPurchaseDate: "2024-06-26"
  },
  subscription: {
    id: "16CRibUdE6pV6HoU"
  },
  externalUserId: "jane_doe",
  firstName: "Jane",
  lastName: "Doe",
  locale: "fr-FR",
  saveReturnUrl: "https://app.yourcompany.com/save?id=jane_doe",
  cancelConfirmationUrl: "https://app.yourcompany.com/cancel_confirm?id=jane_doe",
  custom: {
    emailCount: 4208
  }
});

Parameters

account
Object
subscription
required, Object
firstName
String
lastName
String
fullName
String
email
String
externalUserId
String
saveReturnUrl
String
cancelConfirmationUrl
String
locale
String
custom
Object

Returns

None.

Get a cancel page

getPage()

Requests a cancel page URL from Chargebee.

This function sends options to Chargebee and the returned promise resolves with the URL of the cancel page.

Example

function bindLink(id, url) {
    document.getElementById(id).addEventListener('click', () => {
        window.location.assign(url);
    });
}

cancelPage.getPage({
  account: {
    firstPurchaseDate: "2024-06-26"
  },
  subscription: {
    id: "16CRibUdE6pV6HoU"
  },
  externalUserId: "jane_doe",
  firstName: "Jane",
  lastName: "Doe",
  locale: "fr-FR",
  saveReturnUrl: "https://app.yourcompany.com/save?id=jane_doe",
  cancelConfirmationUrl: "https://app.yourcompany.com/cancel_confirm?id=jane_doe",
  custom: {
    emailCount: 4208
  }
}).then((result) => {
  if (result.valid) {
    //Do any additional processing here.
    bindLink('cancel-btn', result.url);
  } else {
    //Read and process result.errorMessage or redirect to cancellation page: 
    bindLink('cancel-btn', 'https://app.yourcompany.com/cancel?id=jane_doe');
  }
});

Parameters

account
Object
subscription
required, Object
firstName
String
lastName
String
fullName
String
email
String
externalUserId
String
saveReturnUrl
String
cancelConfirmationUrl
String
locale
String
custom
Object

Returns

A promise that resolves to an object with the following properties:

valid
Boolean
url
String
errorMessage
String