Inspiration

Online shopping makes it too easy to overspend. Traditional payment apps just process transactions - they don't help you make smarter financial decisions. I wanted to create something different: a shopping assistant that understands natural language, compares prices intelligently, and enforces spending limits automatically. The core idea: What if your payment app could guide you toward better decisions instead of just taking your money?

What it does

LeashPay is a conversational AI shopping assistant powered by Google Gemini that helps you shop smarter while staying within budget. Instead of filling out forms or clicking through filters, you simply chat:

  • Natural Shopping: "I want to buy headphones under 10000 rupees" - the AI understands and searches
  • Smart Comparisons: Automatically finds the best deal across multiple merchants
  • Policy Protection: Enforces monthly budgets, per-purchase caps, and approval workflows
  • PayPal Integration: Secure sandbox payments with one-click checkout
  • Transaction Monitoring: AG Grid-powered audit dashboard tracks every purchase
  • Guardian Approval: High-value purchases require approval before processing

The AI proposes purchases, the policy engine decides if they're allowed, and PayPal processes approved transactions safely.

How we built it

Tech Stack:

  • Frontend: Next.js 16 with React, Tailwind CSS for responsive UI
  • AI Agent: Google Gemini 1.5 Pro via Vercel AI SDK with 7 custom tools (search, compare, check policy, purchase, budget status, price history)
  • Payments: PayPal Orders API v2 for checkout, webhooks for confirmation
  • Data: SQLite with better-sqlite3 for purchases, policies, and audit logs
  • Catalog: Channel3 mock API with 13 demo products across categories
  • Dashboard: AG Grid Community Edition for transaction filtering and sorting

Architecture:

  1. Conversational Agent (src/app/api/agent/route.ts) - Handles chat, tool calling, and response generation
  2. Tool System (src/lib/agent/tools.ts) - 7 functions the AI can execute autonomously
  3. Policy Engine (src/lib/policy/engine.ts) - Risk scoring and rule enforcement
  4. PayPal Integration (src/lib/paypal/) - Order creation, capture, webhook handling
  5. Audit System (src/lib/db/) - Logs every action for transparency

Development Process:

  • Built conversational system prompt with examples for consistent AI behavior
  • Integrated PayPal sandbox with OAuth 2.0 authentication and webhook validation
  • Designed policy engine with risk scoring algorithm (0-100 scale)
  • Created AG Grid dashboard with custom styling and status indicators
  • Implemented budget tracking with monthly limits and approval thresholds

Challenges we ran into

1. Google Gemini API Compatibility

  • Problem: Gemini doesn't accept system messages in the messages array like other LLMs
  • Solution: Used separate system parameter instead - required reading Gemini-specific docs

2. Tool Calling Type Errors

  • Problem: TypeScript errors between Zod schemas and AI SDK tool format
  • Solution: Used type assertions (as any) as a temporary fix - works in runtime but needs refactoring

3. Natural Language Understanding

  • Problem: Initial regex-based query parsing failed on variations like "I wanna buy..."
  • Solution: Let Gemini handle all parsing - much more robust than pattern matching

4. PayPal Webhook Security

  • Problem: Needed to validate webhook signatures to prevent fraud
  • Solution: Implemented signature verification using PayPal's transmission ID and cert URL

5. Currency Conversion

  • Problem: PayPal uses USD, but target users need INR (Indian Rupees)
  • Solution: Built conversion layer (1 USD = ₹83) with consistent formatting throughout

6. AG Grid Enterprise Warnings

  • Problem: Community version shows warnings for enterprise features
  • Solution: Disabled unused features in grid config - warnings don't affect functionality

Accomplishments that we're proud of

✅ Real Conversational AI - Not just pattern matching - the agent truly understands intent and asks follow-up questions

✅ Full PayPal Integration - Complete order flow with webhooks, approval URLs, and payment capture

✅ Intelligent Policy Engine - Dynamic risk scoring that considers price, merchant, purchase history, and budget status

✅ Production-Ready Code - Clean architecture, proper error handling, audit logging, and security best practices

✅ Beautiful UI - Custom design system with smooth animations, responsive layout, and accessibility

✅ Tool Calling Mastery - AI autonomously decides which tools to call based on conversation context

✅ Security First - Webhook signature validation, policy enforcement, sandbox-only mode for safety

What we learned

Technical Skills:

  • AI Agent Design: How to write effective system prompts that guide LLM behavior without being restrictive
  • Tool Calling Architecture: Building autonomous agents that can execute functions intelligently
  • PayPal Integration: OAuth flows, order management, webhook handling, and sandbox testing
  • Risk Scoring: Designing algorithms that balance security with user experience
  • Real-time Conversations: Managing message history and context across multi-turn dialogues

Key Insights:

  • AI is better at parsing than regex: Natural language understanding beats pattern matching every time
  • Clear prompts = consistent behavior: Vague instructions lead to unpredictable AI responses
  • Webhooks need verification: Never trust external events without signature validation
  • Budget enforcement needs both tech AND UX: Rules alone aren't enough - users need clear feedback
  • TypeScript strict mode catches bugs early: Even temporary type assertions are better than no types

Personal Growth:

  • Learned to debug LLM behavior by improving prompts, not just code
  • Understood the importance of audit logs for transparency and debugging
  • Discovered that good developer experience (sandbox, docs) makes integration 10x faster

What's next for LeashPay

Short-term Improvements:

  • Real Product API: Replace demo data with Google Shopping or Amazon Product API
  • Price Alerts: Notify users when products drop below their target price
  • Spending Analytics: Charts showing monthly trends, category breakdowns, and savings

Medium-term Features:

  • Multi-user Support: Individual budgets, shared family wallets, role-based permissions
  • Mobile App: React Native app with push notifications for approvals
  • Bank Integration: Connect real bank accounts for automatic budget tracking
  • ML Recommendations: Learn user preferences and suggest products proactively

Long-term Vision:

  • Production PayPal: Move from sandbox to live transactions
  • International Support: Multiple currencies, regional pricing, localized products
  • Smart Contracts: Blockchain-based transparent policy enforcement
  • Financial Coaching: AI-powered insights about spending habits and savings opportunities
  • Marketplace Integration: Direct partnerships with retailers for exclusive deals

The Big Picture: LeashPay isn't just a payment app - it's a financial literacy tool. The vision is to help people make better spending decisions through intelligent automation, not restriction. The future of payments isn't faster checkout - it's smarter decisions.

Built With

  • ag-grid
  • audit-logging
  • better-sqlite3
  • budget-management
  • channel3
  • conversational-ai
  • google-gemini
  • llm
  • next.js
  • node.js
  • oauth2
  • payment-gateway
  • paypal
  • policy-engine
  • react
  • rest-api
  • sandbox
  • sqlite
  • tailwindcss
  • tool-calling
  • typescript
  • vercel-ai-sdk
  • webhooks
  • zod
Share this project:

Updates

Submission history