Actions

Apply Coupon

Apply a coupon to a subscription.

Required for Apply Discount Offer to work.

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

Prerequisites

Subscriptions - Controller

You must implement a Subscriptions controller first.

Required

Coupons - Controller

You must implement a Coupons controller first.

Required

Cancel - Action

Coupon application 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 Apply Coupon 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'
import { Coupons } from '../controllers/Coupons'

export const ApplyCoupon = Integrator.ApplyCoupon.config({
    Subscriptions: Subscriptions,
    Coupons: Coupons,
    features: {
        enabled: true
    },
    async handle(ctx, options) {
        const subscription = await this.subscriptions.retrieve({
            customerId: options.customerId,
            id: options.subscriptionId
        })

        const coupon = await this.coupons.retrieve({
            id: options.coupon
        })

        await ctx.db.applyCoupon({ subscription, coupon })
    }
})

Endpoints

Handle Required

POST /churnkey/actions/subscription/apply-coupon

This endpoint applies coupon to a subscription. You should find the subscription by customerId and subscriptionId and apply coupon to it.

Options for this action, provided in the request body.

Features required

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