Inspiration

Visa has removed its Level 2 incentives, so on business-card payments the way to a lower interchange rate is verified Level 3 data: a commodity code, unit of measure and specific description for every line. Visa rejects placeholder values like "ITEM1", and trade press reports merchants being reclassified after audits found auto-filled data. Small B2B sellers mostly send none of it, because their gateway or invoicing tool only captures the amount, and Braintree and PayPal both need custom work to pass line items. We wanted to see whether the seller's own messy catalog could be turned into that data without an ERP project.

What it does

You load a product catalog with lines like "Nitrile exam glv Med 100/bx pf". The AI does the classification once; PayPal and Braintree carry the result on every order. LineGrade gives each line an 8-digit UNSPSC commodity code, a unit of measure and a specific description. Lines it is unsure about (low confidence, no code, or two close candidates) stop for a person to approve, edit or exclude; fees, bundles and vague lines are excluded rather than coded. An order builder then turns SKUs and quantities into a payload with PO number, tax, shipping, ships-from ZIP and Level 3 line items, validates it (totals to the cent, no placeholder descriptions, field limits), and pays it through the Braintree sandbox or PayPal Orders v2 sandbox. After payment the order is read back from the processor and compared with what was sent. A readiness screen shows the data score before and after and an estimate of the interchange difference.

The deployed demo replays a saved AI run on a synthetic catalog. Live AI runs locally.

How we built it

  • Node 22 and Express 5 for the API; React 19, Vite and AG Grid Community for the UI. One Render free web service serves both.
  • Classification: a typo-tolerant keyword shortlist over the UNSPSC list, then Claude Haiku 5.5 (via OpenRouter, temperature 0) picks a code, runner-up, unit and description. The code must exist in the list; units and descriptions are validated; rows below 0.6 confidence, without a code, or with a close same-class runner-up are flagged.
  • Payments: Braintree transaction.sale with Level 2/3 fields, read back with transaction.find and line items. PayPal Orders v2 with supplementary_data.card.level_2 and level_3, an idempotency key on create and capture, and a read-back that compares the returned Level 2/3 fields. Both rails build from the same enriched line items.
  • Safety around money: a ledger with one entry per order id (a retry cannot charge twice, on either rail), per-browser sessions, per-session and daily payment caps, and clear outcomes for declines and for a processor that cannot be reached.
  • Evaluation: a 30-line holdout written before the run, labels checked by a person, the classifier frozen at a recorded commit and run once. Result on those lines: an accepted 8-digit code for 21 of 24 products, all 24 products in the right product class, and the 6 vague or service lines correctly left uncoded.

Challenges we ran into

  • PayPal unit_of_measure returned 500s. PayPal's sandbox failed on some valid-looking unit values (short codes such as EA and BX, and mixed-case words) while accepting others. We found the working set by testing, reported the 500s publicly to PayPal, and the PayPal rail now only sends allow-listed uppercase values, maps short codes (EA to EACH, BX to BOX, PK to PACK, CS to CASE), and omits a unit, recording why, if it is still not on the list.
  • Keeping the accuracy number honest. We tuned the classifier on a first 60-line set, so we did not quote it. We wrote a fresh holdout, had the labels checked before running, froze the code and ran it once. After the run we found one label we had set wrongly (the classifier's code for plotter paper was the more specific one); we recorded that in the report as a post-hoc review rather than changing the headline.
  • UNSPSC licensing. The code list is UNDP's, so it can't ship in full. We removed the full code list we had committed. The saved demo run keeps the titles the classifier returned for its lines, credited to UNDP in NOTICE, and the hosted demo replays that run instead of classifying live. Live AI works locally with a list you download yourself.
  • Retries and lost replies. A payment that times out may or may not exist. We added a ledger and idempotency keys so a retry cannot double-charge, and tested the failure paths with a chaos flag that simulates an unreachable processor.
  • Sleeping server. The free Render instance sleeps. Our "waking up" screen failed to ever finish in some browsers (it used an API older browsers lack); we fixed it and added a Retry after 60 seconds.

Accomplishments that we're proud of

  • The same $958.05 synthetic order goes through both Braintree and PayPal with Level 2/3 data, and is read back from each processor. In the sandbox, PayPal returns the Level 2 and Level 3 fields, so the read-back check compares them.
  • A frozen, single-run holdout with every miss listed, and a README that states the number the data supports and no more.
  • Failure paths that were shown working: AI provider down, processor down, bad input, caps, expired sessions, and a server that is asleep.

What we learned

  • The hard part is not the code lookup; it is deciding when not to guess. Flagging uncertain rows and refusing to put a fee or a bundle on a card order mattered more than a few more points of accuracy.
  • Level 3 processors disagree on the details (units, field limits, what comes back on read-back), so each rail needs its own validation.
  • Sources on this topic are secondary and conflict, and the sandboxes never show interchange charged. So every fee figure in the product is an estimate from a sourced rate table, labelled as one.

What's next for linegrade

  • Upload your own CSV (not built yet; it needs size limits and a spend cap).
  • A larger holdout, and a measured look at how often near-duplicate codes (for example exam versus surgical gloves) are flagged.
  • Re-check the Visa rate table whenever a new schedule appears; the rates and their sources and dates are in data/rates.json.
  • Processor-side verification of Level 3 data is outside what the sandboxes show; that needs a real merchant account.

Built With

Share this project:

Updates

Submission history