Munim Technologies

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.

FeatureWhat happens
Coupons and codesPercent 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 offersA free trial or a lower price for the first payments, for customers new to the product. Once each.
GiftsSomeone pays for your product for someone else, who gets an email with a code to redeem in your app.
Unlock linksAfter a web purchase, a one-time link that opens your app and unlocks the purchase for the signed-in account.
License keysA 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 }'
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 hasA code
A sale, your own checkout offer, or an intro priceReplaces it only if it makes the price lower. Removing the code brings the earlier offer back.
A compare-at priceApplies. The compare-at price is the price itself.
A free trialApplies only if it lasts for every payment, since the trial would use up a shorter discount.
A win-back offer, or it's a giftCan't be used.
While a subscription pays a discounted price, the cancel flow offers no discount and plan switches wait until the discount ends, so a card subscription never carries two coupons.

Intro offers

Code
// $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

Code
// 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' })
  1. One payment

    A gift is paid once, at the regular price: a recurring price times periods. Nothing renews.
  2. 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.
  3. 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.

  1. Set your app link

    Code
    await munim.offerSettings.update({ unlock_url: 'myapp://unlock?token={token}' })
  2. Munim emails it

    Each web purchase made without an app_user_id emails the buyer a link that works once, for 24 hours. Or make one yourself with POST /v1/unlock_links, for example on your success page.
  3. 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) })
    })
  4. 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.

Code
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)
StatusWhen
activeGood to use.
inactiveIts subscription ended.
expiredA gift's time ran out.
revokedRefunded 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

EventWhen
gift.createdA gift was paid for and emailed.
gift.redeemedThe recipient redeemed it.
unlock_link.redeemedA link was used in your app.
license_key.createdA purchase made a key.
license_key.activatedA device was activated.
license_key.deactivatedA device was freed.
license_key.revokedA refund, a chargeback or you revoked it.