Grant a loyalty discount when the customer has enough orders, account age, and tier.
A **customer** gets loyalty_discount
if the __total_orders__ of the **customer** is greater than or equal to 10
and the __account_age_days__ of the **customer** is greater than 180
and the __membership_tier__ of the **customer** is in ["gold", "platinum"].
{
"properties": {
"customer": {
"properties": {
"total_orders": {
"type": "number"
},
"account_age_days": {
"type": "number"
},
"membership_tier": {
"type": "string"
}
},
"required": [
"total_orders",
"account_age_days",
"membership_tier"
],
"type": "object"
}
},
"required": [
"customer"
],
"title": "Customer Model",
"type": "object"
}Gold member qualifies
Expect pass{
"customer": {
"total_orders": 25,
"account_age_days": 400,
"membership_tier": "gold"
}
}New silver member
Expect fail{
"customer": {
"total_orders": 3,
"account_age_days": 30,
"membership_tier": "silver"
}
}Execute this policy from your app using one of the official SDKs.
import { ExecutionClient } from "@policies2/sdk";
const client = new ExecutionClient({
apiKey: process.env.POLICY_API_KEY!,
transport: { kind: "rest", baseUrl: "https://api.policy2.net" },
});
const result = await client.executePolicy({
id: "your-policy-id", // replace with your published policy ID
reference: "base",
data: {
"customer": {
"total_orders": 25,
"account_age_days": 400,
"membership_tier": "gold"
}
},
});
if (result.result) {
console.log("policy matched");
} else {
console.log("policy did not match");
}Ready to try this policy?
Open in editor