# Transaction Rules - Test Payloads

**Base URL**: Your API endpoint for transaction evaluation
**Endpoint**: `POST /api/transaction-rules/evaluate`
**Date**: April 15, 2026

---

## Test Setup Information

### Common Fields
- **merchant_id**: `285414480000000`
- **terminal_id**: `41448413`
- **Currency Code**: `784` (AED - UAE Dirham)
- **BIN**: `416646`
- **Device Model**: `MF919 S10`

### Amount Format
- ISO 8583 format: Last 2 digits are decimals
- Example: `"000000100000"` = 1000.00 AED
- Example: `"000000050000"` = 500.00 AED

---

## 1. MAX_AMOUNT Rule

### Test Case 1.1: PASS - Transaction Below Maximum
**Rule Config**: `{"max_amount": 5000.0}`
**Expected**: ALLOW

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000001",
    "stan": "000001",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T10:00:00Z"
  }
}
```

### Test Case 1.2: FAIL - Transaction Exceeds Maximum
**Rule Config**: `{"max_amount": 500.0}`
**Expected**: DECLINE with message "exceeds maximum"

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000002",
    "stan": "000002",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T10:05:00Z"
  }
}
```

---

## 2. MIN_AMOUNT Rule

### Test Case 2.1: PASS - Transaction Above Minimum
**Rule Config**: `{"min_amount": 50.0}`
**Expected**: ALLOW

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000003",
    "stan": "000003",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T10:10:00Z"
  }
}
```

### Test Case 2.2: FAIL - Transaction Below Minimum
**Rule Config**: `{"min_amount": 2000.0}`
**Expected**: DECLINE with message "below minimum"

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000004",
    "stan": "000004",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T10:15:00Z"
  }
}
```

---

## 3. DAILY_TOTAL Rule

### Test Case 3.1: PASS - Within Daily Limit
**Rule Config**: `{"max_total_amount": 50000.0, "include_declines": false, "currency": null}`
**Expected**: ALLOW (assuming no prior transactions today)

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000005",
    "stan": "000005",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T10:20:00Z"
  }
}
```

### Test Case 3.2: FAIL - Exceeds Daily Limit
**Rule Config**: `{"max_total_amount": 500.0, "include_declines": false}`
**Expected**: DECLINE if daily total already at/near 500.0
**Note**: Requires previous transactions to exist in database

```json
{
  "amount": {
    "currency": "784",
    "value": "000000050000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000006",
    "stan": "000006",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T10:25:00Z"
  }
}
```

---

## 4. WEEKLY_TOTAL Rule

### Test Case 4.1: PASS - Within Weekly Limit
**Rule Config**: `{"max_total_amount": 100000.0, "include_declines": false}`
**Expected**: ALLOW

```json
{
  "amount": {
    "currency": "784",
    "value": "000000200000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000007",
    "stan": "000007",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T10:30:00Z"
  }
}
```

### Test Case 4.2: FAIL - Exceeds Weekly Limit
**Rule Config**: `{"max_total_amount": 1000.0, "include_declines": false}`
**Expected**: DECLINE if weekly total exceeds limit
**Note**: Week starts on Monday (ISO 8601)

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000008",
    "stan": "000008",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T10:35:00Z"
  }
}
```

---

## 5. MONTHLY_TOTAL Rule

### Test Case 5.1: PASS - Within Monthly Limit
**Rule Config**: `{"max_total_amount": 500000.0, "include_declines": false}`
**Expected**: ALLOW

```json
{
  "amount": {
    "currency": "784",
    "value": "000000300000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000009",
    "stan": "000009",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T10:40:00Z"
  }
}
```

### Test Case 5.2: FAIL - Exceeds Monthly Limit
**Rule Config**: `{"max_total_amount": 5000.0, "include_declines": false}`
**Expected**: DECLINE if monthly total exceeds limit

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000010",
    "stan": "000010",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T10:45:00Z"
  }
}
```

---

## 6. COUNT_LIMIT Rule

### Test Case 6.1: PASS - Within Count Limit
**Rule Config**: `{"max_count": 100, "period": "24h"}`
**Expected**: ALLOW (assuming few prior transactions)

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000011",
    "stan": "000011",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T10:50:00Z"
  }
}
```

### Test Case 6.2: FAIL - Exceeds Count Limit
**Rule Config**: `{"max_count": 3, "period": "1h"}`
**Expected**: DECLINE if more than 3 transactions in last hour
**Note**: Send multiple transactions to trigger

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000012",
    "stan": "000012",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T10:55:00Z"
  }
}
```

---

## 7. VELOCITY_COUNT Rule

### Test Case 7.1: PASS - Within Velocity Limit
**Rule Config**: `{"count": 10, "window_seconds": 300, "scope": "terminal"}`
**Expected**: ALLOW

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000013",
    "stan": "000013",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T11:00:00Z"
  }
}
```

### Test Case 7.2: FAIL - Exceeds Velocity Count
**Rule Config**: `{"count": 2, "window_seconds": 60, "scope": "terminal"}`
**Expected**: DECLINE if more than 2 transactions in 60 seconds
**Note**: Send rapid transactions to test

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000014",
    "stan": "000014",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T11:00:45Z"
  }
}
```

---

## 8. VELOCITY_AMOUNT Rule

### Test Case 8.1: PASS - Within Velocity Amount Limit
**Rule Config**: `{"max_amount": 50000.0, "time_window_minutes": 10}`
**Expected**: ALLOW

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000015",
    "stan": "000015",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T11:05:00Z"
  }
}
```

### Test Case 8.2: FAIL - Exceeds Velocity Amount
**Rule Config**: `{"max_amount": 500.0, "time_window_minutes": 5}`
**Expected**: DECLINE if total amount in 5 minutes exceeds 500

```json
{
  "amount": {
    "currency": "784",
    "value": "000000060000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000016",
    "stan": "000016",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T11:06:00Z"
  }
}
```

---

## 9. REFUND_POLICY Rule

### Test Case 9.1: PASS - Refund Allowed and Within Limit
**Rule Config**: `{"refunds_allowed": true, "max_refund_amount": 5000.0, "refund_window_days": 30}`
**Expected**: ALLOW

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "200000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000017",
    "stan": "000017",
    "type": "REFUND",
    "timestamp": "2026-04-15T11:10:00Z"
  }
}
```

### Test Case 9.2: FAIL - Refunds Not Allowed
**Rule Config**: `{"refunds_allowed": false}`
**Expected**: DECLINE with message "not allowed"

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "200000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000018",
    "stan": "000018",
    "type": "REFUND",
    "timestamp": "2026-04-15T11:15:00Z"
  }
}
```

### Test Case 9.3: FAIL - Refund Exceeds Maximum
**Rule Config**: `{"refunds_allowed": true, "max_refund_amount": 500.0}`
**Expected**: DECLINE with message "exceeds maximum refund limit"

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "200000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000019",
    "stan": "000019",
    "type": "REFUND",
    "timestamp": "2026-04-15T11:20:00Z"
  }
}
```

### Test Case 9.4: PASS - CREDIT Type (Also Treated as Refund)
**Rule Config**: `{"refunds_allowed": true, "max_refund_amount": 5000.0}`
**Expected**: ALLOW

```json
{
  "amount": {
    "currency": "784",
    "value": "000000050000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "200000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000020",
    "stan": "000020",
    "type": "CREDIT",
    "timestamp": "2026-04-15T11:25:00Z"
  }
}
```

---

## 10. REFUND_VELOCITY Rule

### Test Case 10.1: PASS - Within Refund Velocity Limit
**Rule Config**: `{"max_refund_count": 5, "period": "24h"}`
**Expected**: ALLOW

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "200000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000021",
    "stan": "000021",
    "type": "REFUND",
    "timestamp": "2026-04-15T11:30:00Z"
  }
}
```

### Test Case 10.2: FAIL - Exceeds Refund Velocity
**Rule Config**: `{"max_refund_count": 2, "period": "1h"}`
**Expected**: DECLINE if more than 2 refunds in last hour

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "200000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000022",
    "stan": "000022",
    "type": "REFUND",
    "timestamp": "2026-04-15T11:35:00Z"
  }
}
```

---

## 11. DUPLICATE_DETECTION Rule

### Test Case 11.1: PASS - Unique Transaction
**Rule Config**: `{"keys": ["stan", "amount"], "dedupe_window_seconds": 60}`
**Expected**: ALLOW (first occurrence)

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000023",
    "stan": "000023",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T11:40:00Z"
  }
}
```

### Test Case 11.2: FAIL - Duplicate Transaction
**Rule Config**: `{"keys": ["stan"], "dedupe_window_seconds": 300}`
**Expected**: DECLINE if same STAN sent within 5 minutes
**Note**: Send same payload twice to test

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000024",
    "stan": "999999",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T11:41:00Z"
  }
}
```

---

## 12. TIME_WINDOW Rule

### Test Case 12.1: PASS - Within Allowed Time Window (Whitelist Mode)
**Rule Config**: `{"default_action": "allow", "allowed_periods": [{"start": "00:00", "end": "23:59", "tz": "UTC"}]}`
**Expected**: ALLOW

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000025",
    "stan": "000025",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T10:00:00Z"
  }
}
```

### Test Case 12.2: FAIL - Outside Allowed Time Window
**Rule Config**: `{"default_action": "allow", "allowed_periods": [{"start": "20:00", "end": "21:00", "tz": "UTC"}]}`
**Expected**: DECLINE if timestamp is outside 20:00-21:00 UTC

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000026",
    "stan": "000026",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T10:30:00Z"
  }
}
```

### Test Case 12.3: PASS - Blacklist Mode (Outside Blocked Period)
**Rule Config**: `{"default_action": "decline", "allowed_periods": [{"start": "02:00", "end": "04:00", "tz": "UTC"}]}`
**Expected**: ALLOW (outside the blocked 2am-4am window)

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000027",
    "stan": "000027",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T10:00:00Z"
  }
}
```

---

## 13. BIN_LIMITS Rule

### Test Case 13.1: PASS - BIN Not in Blocked List
**Rule Config**: `{"blocked_bins": ["411111", "522222"]}`
**Expected**: ALLOW

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000028",
    "stan": "000028",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T12:00:00Z"
  }
}
```

### Test Case 13.2: FAIL - BIN in Blocked List
**Rule Config**: `{"blocked_bins": ["416646"]}`
**Expected**: DECLINE with message about restricted BIN

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000029",
    "stan": "000029",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T12:05:00Z"
  }
}
```

### Test Case 13.3: PASS - BIN in Allowed List
**Rule Config**: `{"allowed_bins": ["416646", "512345"]}`
**Expected**: ALLOW

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000030",
    "stan": "000030",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T12:10:00Z"
  }
}
```

### Test Case 13.4: FAIL - BIN Not in Allowed List
**Rule Config**: `{"allowed_bins": ["512345", "601100"]}`
**Expected**: DECLINE

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000031",
    "stan": "000031",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T12:15:00Z"
  }
}
```

### Test Case 13.5: PASS - BIN Prefix Velocity (Within Limit)
**Rule Config**: `{"bin_prefix": "4166", "max_amount": 10000.0, "max_count": 5, "period": "24h"}`
**Expected**: ALLOW

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "card_number": "4166460000001234",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000032",
    "stan": "000032",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T12:20:00Z"
  }
}
```

### Test Case 13.6: FAIL - BIN Prefix Exceeds Amount Limit
**Rule Config**: `{"bin_prefix": "4166", "max_amount": 500.0, "period": "24h"}`
**Expected**: DECLINE if BIN total in period exceeds limit

```json
{
  "amount": {
    "currency": "784",
    "value": "000000060000"
  },
  "bin": "416646",
  "card_number": "4166460000001234",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000033",
    "stan": "000033",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T12:25:00Z"
  }
}
```

---

## 14. TXN_TYPE_CONTROL Rule

### Test Case 14.1: PASS - Transaction Type Allowed
**Rule Config**: `{"allowed_types": ["PURCHASE", "REFUND"]}`
**Expected**: ALLOW

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000034",
    "stan": "000034",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T12:30:00Z"
  }
}
```

### Test Case 14.2: FAIL - Transaction Type Not Allowed
**Rule Config**: `{"allowed_types": ["PURCHASE", "REFUND"]}`
**Expected**: DECLINE

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "020000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000035",
    "stan": "000035",
    "type": "VOID",
    "timestamp": "2026-04-15T12:35:00Z"
  }
}
```

### Test Case 14.3: FAIL - Transaction Type in Blocked List
**Rule Config**: `{"blocked_types": ["VOID", "REVERSAL"]}`
**Expected**: DECLINE

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "020000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000036",
    "stan": "000036",
    "type": "VOID",
    "timestamp": "2026-04-15T12:40:00Z"
  }
}
```

---

## 15. MCC_RESTRICTION Rule

### Test Case 15.1: PASS - MCC Not Blocked
**Rule Config**: `{"blocked_mccs": ["5411", "7995"]}`
**Expected**: ALLOW

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mcc": "5812",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000037",
    "stan": "000037",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T12:45:00Z"
  }
}
```

### Test Case 15.2: FAIL - MCC in Blocked List
**Rule Config**: `{"blocked_mccs": ["5411", "5812"]}`
**Expected**: DECLINE

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mcc": "5411",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000038",
    "stan": "000038",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T12:50:00Z"
  }
}
```

### Test Case 15.3: PASS - MCC in Allowed List
**Rule Config**: `{"allowed_mccs": ["5812", "7011"]}`
**Expected**: ALLOW

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mcc": "5812",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000039",
    "stan": "000039",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T12:55:00Z"
  }
}
```

### Test Case 15.4: FAIL - MCC Not in Allowed List
**Rule Config**: `{"allowed_mccs": ["5812", "7011"]}`
**Expected**: DECLINE

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mcc": "5411",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000040",
    "stan": "000040",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T13:00:00Z"
  }
}
```

---

## 16. BLACKLIST Rule

### Test Case 16.1: PASS - Not in Blacklist
**Rule Config**: `{"type": "blacklist", "action": "block", "values": ["5200000000001234"]}`
**Expected**: ALLOW

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "card_number": "4166460000001234",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000041",
    "stan": "000041",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T13:05:00Z"
  }
}
```

### Test Case 16.2: FAIL - Card in Blacklist
**Rule Config**: `{"type": "blacklist", "action": "block", "values": ["4166460000001234"]}`
**Expected**: DECLINE

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "card_number": "4166460000001234",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000042",
    "stan": "000042",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T13:10:00Z"
  }
}
```

### Test Case 16.3: FLAG - Card in Blacklist with Flag Action
**Rule Config**: `{"type": "blacklist", "action": "flag", "values": ["4166460000001234"]}`
**Expected**: FLAG (transaction proceeds but flagged for review)

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "card_number": "4166460000001234",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000043",
    "stan": "000043",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T13:15:00Z"
  }
}
```

### Test Case 16.4: FAIL - Allowlist Mode (Card Not in List)
**Rule Config**: `{"type": "allowlist", "action": "block", "values": ["5200000000001234"]}`
**Expected**: DECLINE (not in allowlist)

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "card_number": "4166460000001234",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000044",
    "stan": "000044",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T13:20:00Z"
  }
}
```

---

## 17. CUSTOM_SCRIPT Rule

### Test Case 17.1: PASS - Custom Condition Met
**Rule Config**: `{"conditions": [{"field": "amount", "operator": "<=", "value": "5000"}]}`
**Expected**: ALLOW

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000045",
    "stan": "000045",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T13:25:00Z"
  }
}
```

### Test Case 17.2: FAIL - Custom Condition Not Met
**Rule Config**: `{"conditions": [{"field": "amount", "operator": ">", "value": "2000"}]}`
**Expected**: DECLINE (amount 1000 is not > 2000)

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000046",
    "stan": "000046",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T13:30:00Z"
  }
}
```

---

## Additional Test Scenarios

### Test Case 18: Multiple Rules - All Pass
**Description**: Transaction passes all configured rules
**Expected**: ALLOW

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000047",
    "stan": "000047",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T14:00:00Z"
  }
}
```

### Test Case 19: Missing merchant_id
**Expected**: DECLINE with "INVALID_REQUEST"

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "mti": "0200",
  "processing_code": "000000",
  "terminal_id": "41448413",
  "transaction": {
    "rrn": "610406000048",
    "stan": "000048",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T14:05:00Z"
  }
}
```

### Test Case 20: Missing terminal_id
**Expected**: DECLINE with "INVALID_REQUEST"

```json
{
  "amount": {
    "currency": "784",
    "value": "000000100000"
  },
  "bin": "416646",
  "device_model": "MF919 S10",
  "merchant_id": "285414480000000",
  "mti": "0200",
  "processing_code": "000000",
  "transaction": {
    "rrn": "610406000049",
    "stan": "000049",
    "type": "PURCHASE",
    "timestamp": "2026-04-15T14:10:00Z"
  }
}
```

---

## Testing Notes

### Important Considerations:

1. **Database State**: Many rules (DAILY_TOTAL, WEEKLY_TOTAL, COUNT_LIMIT, VELOCITY_*, etc.) depend on historical transaction data in the database. Ensure the database has appropriate test data or is empty when testing.

2. **Timestamps**: Use current UTC timestamps for real-time testing. Adjust timestamps in payloads to test time-based rules.

3. **Unique Identifiers**: Always use unique STAN and RRN values for each test to avoid conflicts.

4. **Rule Configuration**: Before testing, ensure the transaction_rules table has the appropriate rules configured for your merchant_id and terminal_id.

5. **Amount Format**: Remember that ISO 8583 format uses the last 2 digits as decimals:
   - `000000100000` = 1000.00 AED
   - `000000050000` = 500.00 AED
   - `000000001000` = 10.00 AED

6. **Processing Codes**:
   - `000000` = PURCHASE/SALE
   - `200000` = REFUND
   - `020000` = VOID

7. **Response Codes**: Expected response codes from rules engine:
   - `00` = Approved
   - `05` = Do not honor (default decline)
   - `FLAG` = Flagged for review

8. **Priority Testing**: If multiple rules are configured, remember they are evaluated in priority order (lower number = higher priority).

---

## Quick Reference: Transaction Types

| Type | Description | Processing Code |
|------|-------------|-----------------|
| PURCHASE | Standard purchase transaction | 000000 |
| SALE | Same as PURCHASE | 000000 |
| REFUND | Refund transaction | 200000 |
| CREDIT | Credit transaction (treated as refund) | 200000 |
| VOID | Void/reversal transaction | 020000 |
| REVERSAL | Transaction reversal | 020000 |

---

## Quick Reference: Currency Codes

| Code | Currency |
|------|----------|
| 784 | AED (UAE Dirham) |
| 356 | INR (Indian Rupee) |
| 840 | USD (US Dollar) |
| 978 | EUR (Euro) |

---

**End of Test Payloads Document**
