Applying coupons
You can give customers discounts in your application by applying coupons to their subscriptions. Multiple coupons can be applied to a single subscription and the grantee will be charged the new rate from the following billing cycle onwards.
- Node SDK
- Fetch
- cURL
import { Salable } from '@salable/node-sdk';
const salable = new Salable('YOUR_SALABLE_API_KEY', 'v2');
await salable.subscriptions.addCoupon(
'YOUR_SUBSCRIPTION_UUID',
{ couponUuid: 'YOUR_COUPON_TO_APPLY_UUID' }
);
await fetch(
`https://api.salable.app/subscriptions/YOUR_SUBSCRIPTION_UUID/coupons`,
{
method: "POST",
headers: {
"x-api-key": "YOUR_SALABLE_API_KEY",
version: "v2"
},
body: JSON.stringify({
couponUuid: 'YOUR_COUPON_TO_APPLY_UUID',
}),
}
);
curl -X POST \
https://api.salable.app/subscriptions/YOUR_SUBSCRIPTION_UUID/coupons \
-H "x-api-key: YOUR_SALABLE_API_KEY" \
-H "version: v2" \
-H "Content-Type: application/json" \
-d '{
"couponUuid": "YOUR_COUPON_TO_APPLY_UUID"
}'
You can also programmatically remove coupons from subscriptions. Similarly with adding coupons, the pricing will be updated to reflect the new rate from the following billing cycle.
- Node SDK
- Fetch
- cURL
import { Salable } from '@salable/node-sdk';
const salable = new Salable('YOUR_SALABLE_API_KEY', 'v2');
await salable.subscriptions.removeCoupon('YOUR_SUBSCRIPTION_UUID', { couponUuid: 'YOUR_COUPON_UUID' });
await fetch(
`https://api.salable.app/subscriptions/YOUR_SUBSCRIPTION_UUID/coupons`,
{
method: "PUT",
headers: {
"x-api-key": "YOUR_SALABLE_API_KEY",
version: "v2"
},
body: JSON.stringify({
couponUuid: 'YOUR_COUPON_TO_REMOVE_UUID',
}),
}
);
curl -X PUT \
https://api.salable.app/subscriptions/YOUR_SUBSCRIPTION_UUID/coupons \
-H "x-api-key: YOUR_SALABLE_API_KEY" \
-H "version: v2" \
-H "Content-Type: application/json" \
-d '{
"couponUuid": "YOUR_COUPON_TO_REMOVE_UUID"
}'