DEV Community

Cover image for Fraud Scoring in Laravel: How TalkAm Chooses Between a PIN and a Face Check
Abdulahmed Abdulhakeem
Abdulahmed Abdulhakeem

Posted on Originally published at abdulahmed.hashnode.dev

Fraud Scoring in Laravel: How TalkAm Chooses Between a PIN and a Face Check

TalkAm is a voice-banking app I built on WhatsApp. A user sends a voice note, something like "send 20,000 to my sister", TalkAm reads the transfer back, and the money moves once the user clears one verification step: a four-digit PIN or a face check.

Which of the two is the risk gate's call, made before any verification is offered. This article walks through how it decides, and the handful of decisions in the code that keep each decision explainable to the person on the other end.

Why a score, not a list of triggers

The obvious design is a list. New device: face check. Large amount: face check. It reads well and tests easily. It is also wrong, because most single risk signals are weak.

A transfer at 2am is not suspicious; plenty of people work nights. A transfer at 2am, from a phone this account has never used, for more than this person has ever sent, is.

A design where any one rule escalates on its own has to set every rule's bar high enough to stand alone, so each rule ends up missing the case it was written for. Scoring lets each rule be as sensitive as it honestly should be and puts the judgement in the combination.

So TalkAm's gate runs nine transaction-monitoring rules, the kind a bank's monitoring engine runs, and adds up their points. At or above 50, the transaction needs a face check. Below it, a PIN.

The weights live in one config file, not in nine classes, so tuning one is an edit rather than a code change:

// config/talkam.php (trimmed)
'face_score_threshold' => (int) env('TALKAM_FACE_SCORE_THRESHOLD', 50),

'rules' => [
    'odd_hour'           => ['weight' => 15, 'from_hour' => 0, 'until_hour' => 5],
    'tier_check'         => ['weight' => 0],   // refuses instead of scoring
    'round_tripping'     => ['weight' => 35, 'window_minutes' => 60],
    'customer_history'   => ['weight' => 25, 'minimum_account_age_days' => 7],
    'high_amount'        => ['weight' => 25, 'both_weight' => 40],
    'velocity_check'     => ['weight' => 30, 'window_minutes' => 30],
    'geo_anomaly'        => ['weight' => 25],
    'device_fingerprint' => ['weight' => 25],
    'ml_score'           => ['weight' => 40, 'floor' => 0.50],
],
Enter fullscreen mode Exit fullscreen mode

The same file carries worked examples next to the numbers, so anyone changing a weight can see what it does to real cases:

  • familiar device, normal amount, daytime, established account: 0, PIN

  • new device at 2am, small amount: 15 + 25 = 40, PIN

  • new device, and more than this user has ever sent: 25 + 25 = 50, face

  • brand-new account, and a large amount for them: 25 + 25 = 50, face

  • received money an hour ago and sending it straight on: 35, a face check only with another signal beside it

A few of the rules carry their own judgement. "Odd hour" is asked in the user's own timezone, so a trader in Kano sending money at 8pm doesn't look strange to a server set to another timezone. "High amount" fires on either of two bars: above an absolute ₦100,000, or above the user's own range, which is their largest settled transfer in the last 90 days times 1.5. The tolerance matters. Without it, someone who always sends ₦5,000 gets a face check for sending ₦5,001, and people learn the face check is noise. Clearing both bars scores 40 instead of 25, because large and out of character together is a stronger signal than either.

What is deliberately not a rule: paying someone who isn't a saved payee. It is the most ordinary transfer there is, a trader paying a new supplier or a parent paying a school account read off a letter. Making it elevated by definition would put a face check in front of the commonest transfer in banking.

Refusals come before scoring

Some answers are not risk judgements. An account on hold. A transfer above the hard limits of ₦500,000 per transaction or ₦1,000,000 a day. An amount over the account's KYC tier cap. No verification raises any of those, so offering a face check would have the user pass it and then be refused anyway. It would also tell an attacker exactly where the limits sit.

So refusals run first, and the tier check is the first rule in the list:

private function decide(RiskContext $context): RiskDecision
{
    $refusal = $this->refuseOutright($context); // hold, hard limits

    if ($refusal !== null) {
        return $refusal;
    }

    $signals = [];
    $score = 0;

    foreach ($this->rules as $rule) {
        $signal = $rule->evaluate($context);
        $signals[] = $signal;

        if ($signal->isRefusal) { // only TIER_CHECK
            return RiskDecision::refuse((string) $signal->refusalReason, $signal->evidence, $signals);
        }

        $score += $signal->points;
    }

    return RiskDecision::scored($score, (int) config('talkam.risk.face_score_threshold'), $signals);
}
Enter fullscreen mode Exit fullscreen mode

There is one more refusal, after scoring. TalkAm also answers on an IVR line, so feature phones can do PIN-level work. A feature phone has no camera. When the score demands a face on that channel, the gate refuses and tells the user to come back on WhatsApp. It never quietly drops to a PIN, because then "call from a feature phone" becomes the cheapest way past a face check.

Four outcomes, not two

Each rule answers with a RuleSignal, and there are four kinds:

RuleSignal::fired($rule, $evidence, $points); // saw what it looks for
RuleSignal::quiet($rule, $evidence);          // looked, saw nothing
RuleSignal::refuse($rule, $reason);           // ends the request
RuleSignal::noSignal($rule, $why);            // could not look
Enter fullscreen mode Exit fullscreen mode

The difference between the last and the second is the one that matters most. Nothing in TalkAm captures a user's location today, so the location rule cannot run. If it returned quiet, every transaction in the system would carry "nothing unusual about this location", a reassurance nobody measured and one that looks exactly like a real one.

So it returns noSignal, with the reason written into the audit row. The gap stays visible where someone can do something about it. The rule's weight of 25 is already in config for the day a location source exists, either one the user consents to or a feed from the bank side.

The model is one input, never the decision

The ninth rule is a model's opinion, and three properties keep it in its place:

public function evaluate(RiskContext $context): RuleSignal
{
    try {
        $score = $this->scorer->score($context);
    } catch (Throwable $exception) {
        report($exception);

        return RuleSignal::noSignal($this->rule(), "scorer_failed: {$this->scorer->name()}");
    }

    if ($score === null) {
        return RuleSignal::noSignal($this->rule(), "no_score_available: {$this->scorer->name()}");
    }

    $score = max(0.0, min(1.0, $score));

    if ($score < (float) config('talkam.risk.rules.ml_score.floor')) {
        return RuleSignal::quiet($this->rule(), ['score' => $score]);
    }

    return RuleSignal::fired($this->rule(), ['score' => $score], (int) round($this->rule()->weight() * $score));
}
Enter fullscreen mode Exit fullscreen mode

It is capped. A score of 1.0 contributes 40 points and no more, and 40 is below the threshold of 50. The model can push a transfer over the line, but there is always a deterministic rule in any escalation that someone can explain to the user.

It has a floor. Scores below 0.50 add nothing rather than a trickle. A model that is mildly suspicious of everything would otherwise raise the baseline for every transaction, and the other rules' weights would quietly stop meaning what they say.

It fails to no signal. A scorer that throws or returns nothing reports that it could not look, never that it looked and was reassured.

That last point is live today, because there is no trained model yet. The scorer bound in the container is a placeholder that returns null. Returning 0.0 would be a model asserting that every transaction is definitively safe, the most flattering lie a score can tell. The interface is deliberately narrow, score(RiskContext $context): ?float, with no tier and no recommendation, so a real model can be swapped in without touching the gate.

Every decision is logged, including the routine ones

The gate writes to risk_events on every evaluation: one row per rule that fired, so an escalation is itemised and queryable by rule name, plus one summary row with the score, the threshold, the outcome and the rules that stayed quiet or couldn't run. The summary row is what lets you audit the gate for what it let through, which after an incident is the question that matters.

Refusals are logged as a warning, not as critical. Critical means "this may not be the account owner", and it is what raises a hold on the account. Being over a limit is an ordinary answer to an ordinary request: the user should hear no and be free to try a smaller amount straight away. An earlier version logged refusals as critical, and one over-limit request turned into a lockout that renewed itself on every retry.

What I'd still change

  • The weights are hand-set. The worked examples keep them sane, but real transaction data is what should tune them, and that doesn't exist yet.

  • Round-tripping under-reports. The ledger only sees money that came in from other TalkAm users, which is why that rule sits at 35, strong but never enough alone.

  • On WhatsApp, the "device" is the sender's phone number. It identifies the account more than the handset, so it carries a moderate 25.

  • Two of the nine rules, location and the model, are wired but silent today. That is honest, and it also means the gate is working with seven rules until they're fed.

None of this is exotic. It is a weighted sum, a threshold and an audit table. The value is in the rules about the rules: refuse before you score, never let "couldn't look" pass for "all clear", and never let a model be the whole reason someone is asked for their face.

How does your system explain a risk decision to the person it challenged?

Top comments (1)

Collapse
 
nexusverify profile image
Nexus Verify •

The design choice I'd pressure-test is the one you named yourself: paying someone who isn't a saved payee is deliberately not a rule, and on WhatsApp the "device" is the phone number. So run this case through the gate: the victim's own phone, a normal hour, a normal amount, an established account, but a payee the user has never paid before. Every rule stays quiet and the score is 0, so it's a PIN — and a PIN is exactly what an attacker holding the phone already has. The check that matters is replaying labeled cases: take your last few weeks of real transfers plus the fraud patterns you most fear, run them through decide() offline, and look at two numbers — how many legitimate transfers land at 45–55 and get face-checked, and how many fraud-shaped ones score under 50. If the second number isn't zero, the threshold isn't the protection; the missing payee rule is. The noSignal discipline is the strongest part — keep it, and don't let the future model fill that gap silently.