Approve a withdrawal only when the account has the funds, is within its daily limit, and is in good standing.
A **withdrawal** is approved
if §withdrawal.funds is valid
and §withdrawal.limit is valid
and §withdrawal.account is valid.
withdrawal.funds. A **withdrawal** passes funds_check
if the __amount__ of the **withdrawal** is less than the __available_balance__ of the **account**.
withdrawal.limit. A **withdrawal** passes limit_check
if the __withdrawn_today__ of the **account** + the __amount__ of the **withdrawal** is less than or equal to the __daily_limit__ of the **account**.
withdrawal.account. A **withdrawal** passes account_check
if the __status__ of the **account** is equal to "active"
and the __frozen__ of the **account** is equal to false.
Change the policy or the input and evaluate it here — no account needed.
Policy
Input
{
"properties": {
"withdrawal": {
"properties": {
"amount": {
"type": "number"
}
},
"required": [
"amount"
],
"type": "object"
},
"account": {
"properties": {
"available_balance": {
"type": "number"
},
"daily_limit": {
"type": "number"
},
"withdrawn_today": {
"type": "number"
},
"status": {
"type": "string"
},
"frozen": {
"type": "boolean"
}
},
"required": [
"available_balance",
"daily_limit",
"withdrawn_today",
"status",
"frozen"
],
"type": "object"
}
},
"required": [
"withdrawal",
"account"
],
"title": "Withdrawal Model",
"type": "object"
}Funded, within limit
Expect pass{
"withdrawal": {
"amount": 200
},
"account": {
"available_balance": 1450,
"daily_limit": 500,
"withdrawn_today": 100,
"status": "active",
"frozen": false
}
}Breaches daily limit
Expect fail{
"withdrawal": {
"amount": 450
},
"account": {
"available_balance": 1450,
"daily_limit": 500,
"withdrawn_today": 100,
"status": "active",
"frozen": false
}
}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: {
"withdrawal": {
"amount": 200
},
"account": {
"available_balance": 1450,
"daily_limit": 500,
"withdrawn_today": 100,
"status": "active",
"frozen": false
}
},
});
if (result.result) {
console.log("policy matched");
} else {
console.log("policy did not match");
}Ready to version this policy and wire it into a flow?
Open in editor