Using Churnkey’s Handler Callback Feature
By default, Churnkey takes care of billing updates for you; this includes subscription pauses, discounts, plan changes, and cancellations. If you’d like to implement custom billing logic, you can use handler callbacks.
What Are Handler Callbacks?
Handler callbacks are intended for when you want to handle changes to a customer's subscription instead of having Churnkey do it on your behalf. If a handler callback for a customer event is defined, Churnkey will not take action on your behalf when this event occurs.
Promise Objects
Most handler type callbacks (with the exception of handleSupportRequest are JavaScript Promise objects. Calling resolve will advance Churnkey's flow to a success state. Optionally, you can pass a message which will be shown to the customer. Calling reject
will advance Churnkey's to an error state. Again, you can optionally pass a message to show the customer.
Using Handler Callbacks
To use handler callbacks, you can pass in any of the following as parameters when initializing Churnkey:
{
handlePause: <Promise>,
handleCancel: <Promise>,
handleDiscount: <Promise>,
handleTrialExtension: <Promise>,
handleSupportRequest: <function>
handlePlanChange: <Promise<(customer, { plan })>
}
In addition to handler callbacks, we also provide listener callbacks. More details on those here →