← All examples

Transaction Fraud Flag

Finance

Flag a transaction when the amount is unusually high and the location does not match the account.

Policy rule

A **transaction** is flagged
  if the __amount__ of the **transaction** is greater than 5000
  and the __location_country__ of the **transaction** is not equal to the __home_country__ of the **account**
  and the __transactions_last_hour__ of the **account** is greater than 3.

Input schema

{
"properties": {
"transaction": {
"properties": {
"amount": {
"type": "number"
},
"location_country": {
"type": "string"
}
},
"required": [
"amount",
"location_country"
],
"type": "object"
},
"account": {
"properties": {
"home_country": {
"type": "string"
},
"transactions_last_hour": {
"type": "number"
}
},
"required": [
"home_country",
"transactions_last_hour"
],
"type": "object"
}
},
"required": [
"transaction",
"account"
],
"title": "Transaction Model",
"type": "object"
}

Test cases

Suspicious foreign transaction

Expect pass
{
"transaction": {
"amount": 8000,
"location_country": "NG"
},
"account": {
"home_country": "GB",
"transactions_last_hour": 5
}
}

Normal domestic purchase

Expect fail
{
"transaction": {
"amount": 120,
"location_country": "GB"
},
"account": {
"home_country": "GB",
"transactions_last_hour": 1
}
}

Integration

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: {
		"transaction": {
			"amount": 8000,
			"location_country": "NG"
		},
		"account": {
			"home_country": "GB",
			"transactions_last_hour": 5
		}
	},
});

if (result.result) {
	console.log("policy matched");
} else {
	console.log("policy did not match");
}

Ready to try this policy?

Open in editor