Inspiration

I run a small resale business. Every order that ships straight from a supplier means the same chores: find the item at each supplier, check the price still leaves a margin, pay, and copy the tracking number back to the customer. An AI agent could do this in seconds. But an agent with a payment method can also overpay, pay twice, trust a supplier that appeared last week, or keep buying after a supplier quietly raised its price. I wanted the speed of an agent with the caution of a careful owner.

What it does

When a customer pays in the store with PayPal, RestockGuard:

reads three supplier feeds and uses AI to decide which listings are the same product (suppliers name things differently and not all publish a GTIN); computes the landed cost of each offer (cost × qty + shipping); checks rules in code: minimum margin (a loss is always blocked), per-order limit, daily budget, supplier price jumps, new suppliers; pays the chosen supplier with PayPal Payouts, one payout per order; adds the supplier's tracking number to the customer's PayPal order; sends anything risky to the owner's Approvals queue instead of paying.

The owner dashboard (built with AG Grid) shows every offer compared, the result of every rule, the payout status and the profit, and lets the owner change rules in plain words.

How we built it

PayPal JavaScript SDK + Orders v2 for checkout (create and capture). Webhooks (PAYMENT.CAPTURE.COMPLETED, PAYMENT.PAYOUTSBATCH.*), with signature verification, start the agent and update payout status. Payouts pay the supplier. The sender_batch_id is derived from the customer's order id, so PayPal itself refuses a second payout for the same order, on top of the app's own lock. Order tracking (/v2/checkout/orders/{id}/track) puts the supplier's tracking number on the customer's order. AI: Qwen3-235B (open-weight) through the Otari gateway, behind an OpenAI-compatible interface. It matches products and turns plain-language rule changes into a proposal the owner previews before applying. Node 22 with built-in SQLite, Express, AG Grid Community, deployed on Render. End-to-end tests in a PayPal mock mode cover: automatic buy, approval, blocked loss, and a replayed webhook that must not pay twice.

Challenges we ran into

An AI explanation that was wrong with correct numbers. The model rewrote "Supplier C is a new supplier (12 days)" as "12-day marketplace processing". Checking the numbers was not enough, so the text that explains a money decision is now built from the exact rule results, never paraphrased. Payout status lags the API call. A payout is "pending" first; webhooks plus polling keep the dashboard honest. Idempotency. Captures, webhooks and approvals can all arrive more than once. A database lock and PayPal's own batch id make double payment impossible.

Accomplishments that we're proud of

The whole loop runs on the real PayPal sandbox: a customer payment, a supplier payout that reaches the supplier's sandbox account, a tracking number on the customer's order, and webhooks verified by PayPal. And the agent says "no" in the right places: a price rise that would lose money is blocked with nothing paid.

What we learned

Let the model do what it is good at (fuzzy product matching, understanding the owner's words) and keep every money decision in plain code that can be tested.

What's next for RestockGuard

Real supplier APIs and price files, partial shipments, refunds through the same rules, and the same engine for households: reorder daily goods when they run low, within a monthly budget.

Built With

Share this project:

Updates

Submission history