Offer free shipping when the subtotal exceeds a threshold, or the customer is on a premium tier.
A **order** gets free_shipping
if the __subtotal__ of the **order** is greater than or equal to 50
or the __customer_tier__ of the **order** is equal to "prime".
{
"properties": {
"order": {
"properties": {
"subtotal": {
"type": "number"
},
"customer_tier": {
"type": "string"
}
},
"required": [
"subtotal",
"customer_tier"
],
"type": "object"
}
},
"required": [
"order"
],
"title": "Order Model",
"type": "object"
}Large order qualifies
Expect pass{
"order": {
"subtotal": 75,
"customer_tier": "standard"
}
}Small non-prime order
Expect fail{
"order": {
"subtotal": 20,
"customer_tier": "standard"
}
}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: {
"order": {
"subtotal": 75,
"customer_tier": "standard"
}
},
});
if (result.result) {
console.log("free shipping is allowed");
} else {
console.log("charge shipping");
}Ready to try this policy?
Open in editor