Affihub
DocsConceptsCommission Flows

Commission Flows

Overview

Commission flows are rules that determine how much commission a partner earns for each referral. They let you go beyond a flat percentage and create conditional logic — like higher rates for large transactions or special rates for specific partners.

How commission is calculated

Affihub evaluates commissions in this priority order:

  1. Flow rules — Evaluated first, highest priority to lowest. The first matching flow wins.
  2. Partner override — If no flow matches and the partner has a custom commission_pct, use that.
  3. Program default — Fall back to the program's default_commission_pct (default: 20%).

Flow structure

Each flow has:

Field Description
name Human-readable name (e.g., "VIP Partner Bonus")
event The trigger event (default: transaction_completed)
action_type percentage or flat
action_value The commission rate (percentage) or amount (cents)
conditions Array of conditions that must ALL be true
priority Higher number = evaluated first
active Whether the flow is enabled

Action types

Percentage

Commission is calculated as a percentage of the transaction amount:

commission = floor(txn_amount_cents × rate / 100)

Example: 25% of a $100 transaction = $25.00 commission.

Flat

Commission is a fixed amount regardless of transaction size:

commission = action_value (in cents)

Example: $15.00 flat fee per transaction (action_value = 1500).

Conditions

Conditions are evaluated using AND logic — all conditions must be true for the flow to match.

Condition operators

Operator Description Example
eq Equals partner_slug eq "john"
neq Not equals provider neq "paddle"
gt Greater than txn_amount_cents gt 10000
lt Less than txn_amount_cents lt 5000
contains Contains substring customer_email contains "@enterprise.com"

Available fields

Field Type Description
txn_amount_cents number Transaction amount in cents
customer_email string Customer's email address
partner_slug string The referring partner's slug
provider string Payment provider (stripe or paddle)

Examples

Higher rate for large transactions

Give partners 30% commission on transactions over $500:

{
  "name": "Large Transaction Bonus",
  "action_type": "percentage",
  "action_value": 30,
  "priority": 100,
  "conditions": [
    {
      "field": "txn_amount_cents",
      "op": "gt",
      "value": 50000
    }
  ]
}

Flat fee for a specific partner

Give partner "agency-pro" a flat $50 per sale:

{
  "name": "Agency Pro Flat Fee",
  "action_type": "flat",
  "action_value": 5000,
  "priority": 200,
  "conditions": [
    {
      "field": "partner_slug",
      "op": "eq",
      "value": "agency-pro"
    }
  ]
}

Enterprise customer bonus

35% commission when the customer email contains @enterprise.com:

{
  "name": "Enterprise Referral",
  "action_type": "percentage",
  "action_value": 35,
  "priority": 150,
  "conditions": [
    {
      "field": "txn_amount_cents",
      "op": "gt",
      "value": 100000
    },
    {
      "field": "customer_email",
      "op": "contains",
      "value": "@enterprise.com"
    }
  ]
}

Both conditions must be true: the transaction must be over $1,000 AND the customer email must contain @enterprise.com.

Priority ordering

Flows are evaluated from highest to lowest priority. The first flow whose conditions all match is used. If two flows could match, the one with the higher priority wins.

Priority 200: Agency Pro Flat Fee     → checked first
Priority 150: Enterprise Referral     → checked second
Priority 100: Large Transaction Bonus → checked third
(no match): Partner override or program default
💡

Use priority spacing (e.g., 100, 200, 300) to leave room for inserting new rules later.

Managing flows via API

Create a flow

curl -X POST "https://api.affihub.com/api/v1/flows" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Large Transaction Bonus",
    "action_type": "percentage",
    "action_value": 30,
    "priority": 100,
    "conditions": [
      {"field": "txn_amount_cents", "op": "gt", "value": 50000}
    ]
  }'

List all flows

curl "https://api.affihub.com/api/v1/flows" \
  -H "Authorization: Bearer YOUR_API_KEY"

Update a flow

curl -X PATCH "https://api.affihub.com/api/v1/flows/flw_abc123" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"action_value": 35, "active": true}'

Delete a flow

curl -X DELETE "https://api.affihub.com/api/v1/flows/flw_abc123" \
  -H "Authorization: Bearer YOUR_API_KEY"

Integer math

Commission calculations use integer arithmetic to avoid floating-point precision issues:

commission = floor(txn_cents × round(pct × 100) / 10000)

For example, 20% of $99.00 (9900 cents):

floor(9900 × 2000 / 10000) = floor(1980) = 1980 cents = $19.80