Offers and license keys
Discount codes, intro offers, gifts, unlock links from web to app, and license keys.
What it does
Offers help you sell: discount codes, a better first price for new customers, gifts, and getting web buyers into your app. Set them up in the dashboard under Sell → Offers and License keys, or with the API.
| Feature | What happens |
|---|---|
| Coupons and codes | Percent or amount off, for one payment, a few, or every payment. Customers type the code on the checkout, or you put it on a link. |
| Intro offers | A free trial or a lower price for the first payments, for customers new to the product. Once each. |
| Gifts | Someone pays for your product for someone else, who gets an email with a code to redeem in your app. |
| Unlock links | After a web purchase, a one-time link that opens your app and unlocks the purchase for the signed-in account. |
| License keys | A key for each purchase. Your desktop app activates and checks it with Munim, with no secret key. |
Coupons and codes
curl https://billing-sandbox-api.munimtech.com/v1/coupons \
-H "Authorization: Bearer $MUNIM_BILLING_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{ "percent_off": 20, "duration": "once", "code": "SUMMER20", "max_redemptions": 500 }'const coupon = await munim.coupons.create({
percent_off: 20,
duration: 'once', // or 'repeating' with duration_in_periods, or 'forever'
code: 'SUMMER20',
max_redemptions: 500,
})
// A checkout link with the code already applied
const checkout = await munim.checkouts.create({ price_id: 'pri_…', promotion_code: 'SUMMER20' })percent_off / amount_offnumber / integer- Percent off (more than 0, less than 100), or cents off each item's price.
durationstring- Subscriptions: once (the first payment, the default), repeating (the first duration_in_periods payments; monthly or yearly prices) or forever. One-time prices get it once.
applies_toobject- { product_ids, price_ids } to limit it. Default: everything.
first_purchase_onlyboolean- Only for customers who never paid you before.
max_redemptions / redeem_byinteger / time- Total uses, and the last moment it works.
codestring- A promotion code for it. Add more with POST /v1/promotion_codes, each with its own limits.
The code field shows on your checkout while you have an active code. A customer types it and the page shows the new price, the discount and what renews at what price. To hide the field on one checkout, pass allow_promotion_codes: false. Codes aren’t case-sensitive.
A code works like a sale: card subscriptions get a one-use coupon, PayPal a plan for those terms, and each payment records coupon_id and discount_amount. Munim’s fee is on what the customer paid.
One discount at a time
Discounts never stack. A checkout has at most one:
| The checkout already has | A code |
|---|---|
| A sale, your own checkout offer, or an intro price | Replaces it only if it makes the price lower. Removing the code brings the earlier offer back. |
| A compare-at price | Applies. The compare-at price is the price itself. |
| A free trial | Applies only if it lasts for every payment, since the trial would use up a shorter discount. |
| A win-back offer, or it's a gift | Can't be used. |
Intro offers
// $1.99 for the first 3 months, then the regular price (new customers only)
await munim.prices.update('pri_monthly', {
intro_offer: { type: 'intro_price', unit_amount: 199, periods: 3 },
})
// Or a free trial only new customers get
await munim.prices.update('pri_yearly', { intro_offer: { type: 'free_trial', trial_days: 14 } })A recurring price can have one intro offer. Customers who already subscribed to the product don’t get it. Munim checks when the checkout is made and again when the customer types their email; if it comes off, the page says so. An intro price wins over the price’s own sale when it’s lower or the same. Pass intro_offer: false on a checkout to sell without it.
A price with trial_days gives everyone a trial, so it can’t have an intro offer as well.
Gifts
// On your server: sell 3 months of Pro as a gift
const checkout = await munim.checkouts.create({
price_id: 'pri_monthly',
gift: { recipient_email: '[email protected]', sender_name: 'Alex', message: 'Enjoy!', periods: 3 },
})
// Later, when Sam enters the code in your app (your server, with Sam signed in)
const { subscriber } = await munim.gifts.redeem({ code: 'GIFT-ABCD-EFGH-JKMN', app_user_id: 'user_sam' })One payment
A gift is paid once, at the regular price: a recurring price timesperiods. Nothing renews.The recipient gets an email
With a code and a page that opens your app (your app link, below) or shows the code to type.Your server redeems it
For the signed-in user. They get the product for the gift’s periods from then, or for good for a one-time product.
The buyer doesn’t get the product. A full refund cancels the gift; if it was already redeemed, the recipient’s access ends too. POST /v1/gifts/:id/resend sends a new code.
Unlock links
Someone buys on your website, then opens your app. An unlock link attaches the purchase to the account they sign in with, with no matching of emails.
Set your app link
Codeawait munim.offerSettings.update({ unlock_url: 'myapp://unlock?token={token}' })Munim emails it
Each web purchase made without anapp_user_idemails the buyer a link that works once, for 24 hours. Or make one yourself withPOST /v1/unlock_links, for example on your success page.Your app reads it
Code// In the app (React Native): read the link it was opened with import { Linking } from 'react-native' import { parseUnlockUrl } from 'munim-billing/react-native' Linking.addEventListener('url', async ({ url }) => { const found = parseUnlockUrl(url) // { kind: 'unlock', token } or { kind: 'gift', code } if (found) await fetch('https://api.example.com/unlock', { method: 'POST', body: JSON.stringify(found) }) })Your server redeems it
Code// On your server, for the signed-in user const { subscriber } = await munim.unlockLinks.redeem({ token, app_user_id: user.id }) // subscriber.entitlements.pro.active === true
Tokens are stored hashed and can’t be shown again. A second use is refused. The purchase then counts in that user’s entitlements and follows it: a subscription’s status, a refund. A project can have its own app link (unlock_url on the project).
License keys
Turn keys on for a product (license_keys: { activation_limit: 2 }, or in the dashboard). Each purchase gets a key like 7KQ2M-8D3XR-A9VNT-4HB6P-W2JCE, emailed to the buyer.
import { licenses } from 'munim-billing'
// First run: activate this computer (no secret key in the app)
const { instance } = await licenses.activate({ license_key, instance_name: os.hostname() })
saveLocally(instance.id)
// Each launch
const check = await licenses.validate({ license_key, instance_id: instance.id })
if (!check.valid) showLicenseScreen(check.message)| Status | When |
|---|---|
active | Good to use. |
inactive | Its subscription ended. |
expired | A gift's time ran out. |
revoked | Refunded in full, charged back, or revoked by you. |
Activating past the limit returns 409. Free a device with licenses.deactivate in the app, or from the key’s details in the dashboard.
Events
| Event | When |
|---|---|
gift.created | A gift was paid for and emailed. |
gift.redeemed | The recipient redeemed it. |
unlock_link.redeemed | A link was used in your app. |
license_key.created | A purchase made a key. |
license_key.activated | A device was activated. |
license_key.deactivated | A device was freed. |
license_key.revoked | A refund, a chargeback or you revoked it. |