venmo/business-rules

Ability to pass parameters into the Rule variables

Opened this issue · 1 comments

Hi, I have been trying to evaluate business rules for a project that I am working on, and I can't figure out how to parametrize a rule:

For example, I want to trigger the rule if it matches a specific configuration. A product has category, and the category is books, and frequency is 1.

     { "name": "attribute_frequency",
        "operator": "less_than_or_equal_to",
        "value": {"key": "category", "value": "books", "max_frequency": 1},
      },

It is not possible to pass a more complex objects into the rule variables? Or pass parameters?

How do you address that?

Thank you!

You can instead create multiple conditions such that one condition is for the category and other is for its frequency. The "all" clause will ensure that the condition rule is satisfied iff both of these are true.

Edit: Addendum: A pseudo example below.

rule = {
    "conditions": {
        "all": [
            {"name": "category", "operator": "equal_to", "value": "book"},
            {"name": "attribute_frequency", "operator": "equal_to", "value": 1},
        ]
    },
    "actions": [{"name": "give_basket_discount", "params": {"amount": 2},}],
}

Also note that you should separate out the category into a different variable. Think of variables as smallest divisible units of potential business logic.