PayAgent – Autonomous AI Negotiation with PayPal Settlement
Inspiration
Freelance transactions often involve more than simply agreeing on a price. Buyers and sellers may have different expectations regarding deliverables, deadlines, revisions, and payment conditions.
We wanted to explore how AI agents could make these negotiations more structured, transparent, and efficient while ensuring that both parties remain in control of their decisions.
This inspired us to build PayAgent, an AI-powered platform that connects bilateral negotiations with a structured agreement and PayPal Sandbox settlement workflow.
What It Does
PayAgent is designed to support negotiations between buyers and sellers through intelligent agents operating within predefined boundaries.
Key capabilities include:
- Bounded AI Negotiation: Each party defines private negotiation mandates, including price limits, delivery timelines, and revision constraints.
- Automated Offer Generation: Negotiation agents assist in generating and evaluating offers while respecting predefined constraints.
- Mutual Agreement: Both parties review and accept the same versioned agreement before settlement.
- PayPal Integration: The payment adapter targets PayPal Sandbox Invoicing, Orders, Payments, and webhook verification.
- Evidence Management: Supports secure deliverable evidence uploads and SHA-256 integrity verification.
- Dispute Resolution: Provides a structured workflow for handling disagreements between buyers and sellers.
- Real-Time Updates: Uses WebSocket communication to support deal updates.
How We Built It
We built PayAgent using a modern full-stack architecture:
- Frontend: Next.js 14, React, TypeScript, and Tailwind CSS.
- Backend: Java 21 and Spring Boot 3.3.
- Database: PostgreSQL 16 with Flyway migrations.
- Payment Infrastructure: PayPal Sandbox APIs, including Invoicing v2, Orders v2, Payments v2, and webhook verification.
- Real-Time Communication: Spring WebSocket with STOMP.
- Security: JWT authentication, role-based access control, agreement versioning, and idempotency mechanisms.
Our architecture separates negotiation logic, payment processing, evidence management, and dispute handling into dedicated backend modules.
Financial amounts are represented using integer minor units to avoid floating-point precision issues. Agreements use canonicalized terms and SHA-256 fingerprints to ensure that both parties approve the same terms.
Challenges We Faced
One of our biggest challenges was coordinating the negotiation lifecycle with payment operations while maintaining consistency between both parties.
We also encountered challenges involving authentication, authorization, evidence ownership, agreement revisions, and payment-state synchronization.
Testing revealed several security and integration issues, which helped us improve our validation logic and strengthen the application's security boundaries.
Another challenge was distinguishing between locally verified functionality and integrations that still require live Sandbox or deployment testing.
What We Learned
Throughout this project, we learned how to design a multi-agent negotiation workflow, integrate payment APIs, manage financial state transitions, and build secure backend services.
We also learned the importance of testing real authentication and authorization flows rather than relying only on mocked responses.
Most importantly, we learned that autonomous AI systems handling financial decisions must operate within clear constraints, maintain transparency, and preserve human control.
Accomplishments
- Designed a bilateral AI negotiation architecture.
- Implemented buyer and seller workspaces.
- Developed private mandate and agreement management.
- Built dedicated PayPal Sandbox integration modules.
- Added evidence integrity and dispute management capabilities.
- Established automated backend verification and security regression tests.
The latest local backend verification recorded 392 passing tests, with 13 explicitly skipped tests. Live payment and deployed-application verification remain outstanding.
What's Next
Our next steps are to complete deployment verification, validate the complete PayPal Sandbox payment lifecycle, test the end-to-end buyer and seller experience, and publish a demonstration of the integrated application.
Built With
- ai
- api
- authentication
- boot
- css
- docker
- java
- jwt
- next.js
- payment
- paypal
- postgresql
- processing
- python
- react
- rest
- spring
- tailwind
- typescript
- websockets