← Solutions

Intelligent Payment Routing

Choose the payment processor for each card transaction in your Spring Boot service, with a Deep Netts neural network that learns which route keeps the most money for the merchant.

payment-service · processor routing
payment€312.00Paris · VisaDeep Nettsrouting modelProcessor Aapproval 0.71Processor Bapproval 0.94Processor Capproval 0.64
€312.00Paris · VisaDeep Nettsrouting modelProcessor Aapproval 0.71Processor Bapproval 0.94Processor Capproval 0.64
98.3 %
of the possible gain captured (minimal, simulated payments)
5 routes
with eligibility rules and availability (extended)
29 features
from 13 transaction fields (extended)
JDK 25
Spring Boot 4.1 · Deep Netts core 4.0.5

The cheapest processor is not always the best choice

A merchant can send each card payment to one of several processors. They charge different fees and approve different kinds of payments at different rates.

A declined payment is a lost sale. Fees are known in advance, but approval rates have to be learned from past payments – that is what the model learns.

How it works

  1. Describe the payment

    Amount, cross-border or domestic, online or in store, debit or credit card, and the fraud score from the merchant’s risk system.

  2. Encode it

    The amount on a log scale, flags as 0 or 1 – every value between 0 and 1. The extended version derives 29 features, from card brand to hour of day.

  3. Score every route at once

    One multi-class Deep Netts network with one output per processor scores all routes in a single prediction.

  4. Pick and fall back

    The highest-scoring route wins. The extended version first removes ineligible or unavailable routes and returns a ranked list to retry down after a soft decline.

Inside the model

The network from the minimal version, neuron by neuron, in its real size.

Inputs · 5Hidden · 16 · ReLUOutput · 3 · softmaxamountcross_borderonlinedebit_cardrisk_scoreLOCAL_BANKGLOBAL_PROCESSORRISK_SPECIALIST
The minimal network5 → 16 → 3

Point at an input or an output to see what it is and how it is computed.

Decision
  • One score per processor, summing to 1
  • The highest score is the recommended processor
inputs scaled to 0..1Cross-entropyAdamlearning rate 0.001100 epochsseed 42
Extended version29 → 32 → 16 (ReLU) → 5 (softmax)

one output per route

Source: minimal/…/RoutingModel.java, PaymentEncoder.java, Processor.java

Walk through the code

Real files from the minimal version. Pick a step to see the lines that do it.

@RestControllerpublic class RoutingController {     private final RoutingModel model;     public RoutingController(RoutingModel model) {        this.model = model;    }     @PostMapping("/api/routing/recommendation")    public RoutingRecommendation recommend(@Valid @RequestBody Payment payment) {        return model.recommend(payment);    }}

Two versions in one repository

Start with the minimal version to see the whole integration in a few files; move to the extended one for the full lifecycle.

The smallest complete integration of Deep Netts in a Spring Boot application.

  • 3 processors, 5 request fields, 1 endpoint
  • Train, evaluate, save and load
  • Compared with the cheapest processor and a simple rule

REST API

POST/api/routing/recommendationRecommend a processorminimal
POST/api/routing/decisionsRanked routes for one transactionextended
GET/api/routing/routesRoutes with rules, fees and availabilityextended
PUT/api/routing/routes/{route}/availabilityTake a route out of service or backextended
GET/api/routing/modelActive model and metricsextended
POST/api/routing/model/retrainRetrain, kept only if it passes the quality gateextended
Request · minimal
POST /api/routing/recommendationContent-Type: application/json {  "amount": 120,  "crossBorder": true,  "online": true,  "debitCard": false,  "riskScore": 0.05}
Response
{  "processor": "GLOBAL_PROCESSOR",  "modelScores": {    "LOCAL_BANK": 0.0,    "GLOBAL_PROCESSOR": 1.0,    "RISK_SPECIALIST": 0.0  },  "baselineProcessor": "LOCAL_BANK"}

Run it locally

  • JDK 25 (required by Deep Netts 4.x)
  • Maven 3.9 or later
  • No external services – trains on simulated payments
  • Both versions use port 8080, run one at a time
Terminal
git clone https://github.com/deepnetts/spring-boot-transaction-routing.gitcd spring-boot-transaction-routing/minimalmvn spring-boot:run # in a second terminalcurl -X POST localhost:8080/api/routing/recommendation   -H "Content-Type: application/json"   -d '{"amount": 120, "crossBorder": true, "online": true,       "debitCard": false, "riskScore": 0.05}'

Ready for AI coding assistants

The repository ships a SKILL.md with the rules an AI coding assistant must follow (output order, encoder consistency, independent evaluation, honest reporting) and ready-made prompts.

  • explain-the-example.mdGuided walkthrough for a Java developer new to ML, without changing files
  • add-processor-or-feature.mdAdd a processor or a model input, then re-evaluate
  • train-on-own-data.mdReplace the simulator with your historical payments, with a fixed split
  • review-a-model-change.mdReview uncommitted changes against the SKILL.md rules

Good to know

  • Both versions train on synthetic data; the results are not estimates of real-world performance.
  • In the minimal simulation a simple two-line rule already reaches 92.9 % of the possible gain – the example does not show that machine learning beats a tuned rule.
  • Scores are not calibrated probabilities. Route availability is kept in memory on a single instance.

More solutions

See Deep Netts in researchCase studies from Jefferson Lab and the University of Minnesota.Read the case studies