UNPKG

829 BJavaScriptView Raw
1var RuleEngine = require('../index');
2/* Sample Rule to block a transaction if its below 500 */
3var rule = {
4 "condition": function(R) {
5 R.when(this.transactionTotal < 500);
6 },
7 "consequence": function(R) {
8 this.result = false;
9 this.reason = "The transaction was blocked as it was less than 500";
10 R.stop();
11 }
12};
13/* Creating Rule Engine instance and registering rule */
14var R = new RuleEngine();
15R.register(rule);
16/* Fact with less than 500 as transaction, and this should be blocked */
17var fact = {
18 "name": "user4",
19 "application": "MOB2",
20 "transactionTotal": 400,
21 "cardType": "Credit Card"
22};
23R.execute(fact, function(data) {
24 if (data.result) {
25 console.log("Valid transaction");
26 } else {
27 console.log("Blocked Reason:" + data.reason);
28 }
29});
\No newline at end of file