Overview

This is why Unprice is really adaptive. Instead of thinking about plans inside your code, with Unprice you think about features. You map your application to validate specific features, this gives you the flexibility to change the packaging without affecting other customers.

Think about it as a feature flag with super powers.

What is an entitlement?

Entitlements are the features a customer has access to. They can be billed or not, for instance if a customer is subscribe to a plan PRO with fetures “tokens” with a limit of 10K tokens per month, that is an entitlement that is billed.

// without Unprice
if (customer.plan === "PRO") { // <-- mapping to PRO plan means when the plan changes you have to change this
  // let custor use tokens
} else {
  return "don't have access"
}

// ----------------------------------------------------

// with Unprice
// Verify if the customer has access to the feature
const { result, error } = await unprice.customers.can({
  customerId: customer.unpriceCustomerId,
  featureSlug: "tokens", // map your feature code
  metadata: {
    action: "create",
    country: "US"
  }
});

if (error) {
  // handle potential network or bad request error
  // a link to our docs will be in the `error.docs` field
  console.error(error.message);
  return;
}

if (result.access) {
  // let custor use tokens
  // because now the feature is tied to the customer itself and not the plan
  // you can change the features of your customer without touching your code
  continue
} else {
  return {
    message: "don't have access",
    deniedReason: result.deniedReason
  }
}

console.log(result);

How to use entitlement - Tutorial

Next Steps

You should get to know our API reference or the Typescript SDK to start integrate with your product.

You can also check out the Features section for more information on how to use Unkey.