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
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.