# Risk engine

Every OnCharge checkout is screened before the card is submitted. The checkout page collects signals, OnCharge scores the attempt from 0 (low risk) to 100 (high risk), and your store's risk policy decides whether the payment goes ahead, needs an extra step, or is blocked. You do not need to integrate anything for screening to run; this page explains what happens and how to tune it.

## Signals

| Signal | What it looks at |
|---|---|
| Bot check | An invisible browser challenge score on the checkout page. |
| IP intelligence | VPN, Tor, proxy and data-centre (hosting) networks; IP country. |
| Email check | Invalid and disposable email addresses. |
| Phone check | Invalid numbers and VoIP lines. |
| Automation flags | Headless browsers and automation tools. |
| Timing | Checkouts completed faster than a person could. |
| Velocity | Attempts from the same IP or email in the last 5 minutes, hour and day. |
| Network reputation | Payment, refund and chargeback history of the same email or phone across OnCharge merchants (identifiers are stored only as keyed hashes). |

## Decisions

| Decision | What happens |
|---|---|
| `allow` | The payment goes ahead. |
| `step_up` | The shopper completes extra steps first, such as an SMS code, accepting terms, a signature or 3-D Secure. |
| `review` | Treated as a step-up; an SMS code is required if your policy says so. |
| `deny` | The payment is blocked with a generic message. |

With the default thresholds, a score of 30 or less is allowed, 31 to 59 is `review`, 60 to 79 is a step-up with an SMS code (or `review` if `require_otp_on_review` is off), and 80 or more is denied. Some signals decide directly, whatever the score: by default a headless browser is denied, and VPN or Tor traffic, data-centre networks and disposable emails get a step-up.

**Monitor vs. enforce.** In `monitor` mode (the default) every decision is recorded but payments are never blocked by the score; use it to see what the engine would do. Switch to `enforce` when you are happy with the results.

## Shared blocklist

When a shopper is banned (for example after a chargeback), their email and phone are blocked across OnCharge. A session created for a banned shopper fails with `403 global_ban`, and the `message` is safe to show the shopper. Identifiers are stored only as keyed hashes; the shopper is never told which store or reason caused the ban.

## Your store's policy

Read and change the policy with the API ([`GET`](https://oncharge.io/docs/api#getriskpolicy) and [`PUT /api/v1/risk/policies`](https://oncharge.io/docs/api#updateriskpolicy)):

```json title="Default policy"
{
  "mode": "monitor",
  "thresholds": { "score_allow": 30, "score_review": 60, "score_deny": 80 },
  "step_up_rules": {
    "require_otp_on_review": true,
    "require_signature": true,
    "require_terms": true,
    "force_3ds_above": 70
  },
  "blocks": {
    "vpn_tor": "step_up",
    "datacenter_asn": "step_up",
    "disposable_email": "step_up",
    "voip_phone": "allow",
    "high_risk_countries": [],
    "headless_browser": "deny"
  },
  "velocity_limits": { "ip_5m": 5, "ip_1h": 15, "ip_24h": 50, "email_5m": 3, "email_1h": 10, "email_24h": 30 }
}
```

- Each section you send to `PUT` replaces that section; sections you leave out stay as they are.
- Thresholds must satisfy `score_allow < score_review < score_deny`.
- `blocks` values are `allow`, `step_up` or `deny`; `high_risk_countries` takes ISO country codes.

Before changing the policy, replay a past decision under the new policy with [`POST /api/v1/risk/simulate`](https://oncharge.io/docs/api#simulateriskpolicy). Nothing is saved.

## Decisions and feedback

- [`GET /api/v1/risk/decisions`](https://oncharge.io/docs/api#listriskdecisions) lists decisions (filter by `from`, `to`, `decision`; paginate with `limit` and `offset`).
- [`GET /api/v1/risk/decisions/{id}`](https://oncharge.io/docs/api#getriskdecision) returns one decision with its reasons, a short explanation and its outcome label.
- [`POST /api/v1/risk/feedback`](https://oncharge.io/docs/api#sendriskfeedback) tells OnCharge how an order turned out (`fraud_confirmed`, `false_positive`, `legitimate`, `chargeback`), which improves future scoring.

The session's `risk_decision` (`accept`, `review` or `reject`) and `risk_score` are also on [`GET /api/v1/checkout/sessions/{id}`](https://oncharge.io/docs/api#getcheckoutsession).
