Actions

Pause - Action

Pauses a subscription at specific date for a specific period.

Required for Pause Offer to work.

To implement the Pause action, you need to implement an endpoint and define features

Prerequisites

Subscriptions - Controller

You must implement a Subscriptions controller first.

Required

Cancel - Action

Pause is a part of the cancel flow. You must implement the Cancel action first.

Required

SDK

If you are using the SDK, you can implement the Pause action by following the code example below. You don't need to get into the details of the API endpoints, the SDK will take care of that for you.

import { Integrator } from '@churnkey/sdk'
import { Subscriptions } from '../controllers/Subscriptions'

export const Pause = Integrator.Pause.config({
    Subscriptions: Subscriptions,
    features: {
        // define which start dates are supported, at least one is required
        startDates: { 
            [Integrator.Pause.StartDate.Immediate]: true,
            [Integrator.Pause.StartDate.EndOfPeriod]: true
        },
        // define which durations are supported, at least one is required
        durations: {
            [Integrator.Pause.Duration.Period]: true,
            [Integrator.Pause.Duration.Date]: true
        },
        allowAnnual: true
    },
    async handle(ctx, options) {
        const subscription = await this.subscriptions.retrieve({
            customerId: options.customerId,
            id: options.subscriptionId
        })

        if (!options.allowAnnual) {
            if (subscription.duration.unit === 'year') {
                throw new Integrator.Error(400, 'Annual subscriptions are not allowed to be paused')
            }
        }

        switch (options.startAt) {
            case Integrator.Pause.StartDate.Immediate:
                await ctx.db.pauseSubscription(subscription, {
                    duration: options.duration
                })
                break
            case Integrator.Pause.StartDate.EndOfPeriod:
                await ctx.db.pauseSubscriptionAtThePeriodEnd(subscription, {
                    duration: options.duration
                })
                break
        }
    }
})

Endpoints

Handle Required

POST /churnkey/actions/subscription/pause

This endpoints handles the single subscription pause. You should find the subscription by customerId and subscriptionId and pause it.

Options for pause, provided in the request body.

Handle All optional

POST /churnkey/actions/customer/pause

This endpoint handles pause of all customer's subscriptions. You should find all subscriptions by customerId and pause them.

This endpoint is optional. By default, when we need to pause all subscriptions, we will call the Handle endpoint for each subscription. You can implement this endpoint to reduce the number of API calls and improve performance/end-user UX.

Options for pause, provided in the request body.

Features required

Features define which behavior is supported for the Pause action. Depending on the features you enabled, requests body will have different options.

For example, if you enable only end-of-period start date, the request.body.startAt will be always end-of-period. If you enable both start dates, request.body.startAt can be either immediate or end-of-period.