Actions
Change Price - Action
Changes the price and/or product of a subscription.
Required for Change Price Offer to work.
To implement the Change Price
action, you need to implement an endpoint and define features
Prerequisites
SDK
If you are using the SDK, you can implement the Change Price
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 { Prices } from '../controllers/Prices'
export const ChangePrice = Integrator.ChangePrice.config({
Subscriptions: Subscriptions,
Prices: Prices,
features: {
enabled: true,
schedules: {
[Integrator.ChangePrice.Schedule.Immediate]: true,
[Integrator.ChangePrice.Schedule.EndOfPeriod]: true
},
prorate: true
},
async handle(ctx, options) {
const subscription = await this.subscriptions.retrieve({
customerId: options.customerId,
id: options.subscriptionId
})
const price = await this.prices.retrieve({
id: options.price
})
await ctx.db.changePrice({ subscription, price, at: options.scheduledAt, prorate: options.prorate })
}
})
Endpoints
Handle Required
POST /churnkey/actions/subscription/apply-coupon
This endpoint changes a price of subscription. You should find the subscription by customerId
and subscriptionId
and set a new price to it.
Options for this action provided in the request body.
Features required
Features define which behavior is supported for the Change Price
action. Depending on the features you enabled, requests body will have different options.